@@ -49,6 +49,8 @@ static function make_zip_download( $filename, $origin_dir, $tmp_dir, $data, $con
4949 ZipArchive::CREATE && ZipArchive::OVERWRITE
5050 );
5151
52+
53+
5254 // check we have filesystem write access
5355 if ( $ creation_success ) {
5456 // write json containing configuration data
@@ -59,6 +61,39 @@ static function make_zip_download( $filename, $origin_dir, $tmp_dir, $data, $con
5961 if ( 'gpl ' === $ data ['plugin_license ' ] ) {
6062 $ zip ->addFromString ( 'LICENSE ' , file_get_contents ( dirname ( __FILE__ ) . '/../boilerplates/GPL.txt ' ) );
6163 }
64+ $ abstract_plugin_file_dest = '/lib/wordpress-phoenix/abstract-plugin-base/src/abstract-plugin.php ' ;
65+ if ( defined ( 'WP_DEV_KIT_AIRPLANE_MODE ' ) && WP_DEV_KIT_AIRPLANE_MODE ) {
66+ $ plugin_base = file_get_contents ( $ tmp_dir . '/../lib/wordpress-phoenix/abstract-plugin-base/src/abstract-plugin.php ' );
67+ $ abstract_plugin_namespace = self ::get_abstract_plugin_base_namespace ( $ plugin_base );
68+ $ data ['abstractPluginNamespace ' ] = $ abstract_plugin_namespace ;
69+ $ zip ->addFromString (
70+ $ abstract_plugin_file_dest ,
71+ $ plugin_base
72+ );
73+ } else {
74+ $ github_api_call = wp_remote_get (
75+ 'https://api.github.com/repos/WordPress-Phoenix/abstract-plugin-base/contents/src/abstract-plugin.php?ref=master ' ,
76+ [
77+ 'timeout ' => 10 ,
78+ ]
79+ );
80+ $ github_response = wp_remote_retrieve_body ( $ github_api_call );
81+ $ github_response = json_decode ( $ github_response , true );
82+ if ( isset ( $ github_response ['content ' ] ) ) {
83+ $ content = base64_decode ( $ github_response ['content ' ] );
84+ $ namespace = self ::get_abstract_plugin_base_namespace ( $ content );
85+ $ data ['abstractPluginNamespace ' ] = $ namespace ;
86+ $ zip ->addFromString ( $ abstract_plugin_file_dest , $ content );
87+ } else {
88+ $ plugin_base = file_get_contents ( $ tmp_dir . '/../lib/wordpress-phoenix/abstract-plugin-base/src/abstract-plugin.php ' );
89+ $ abstract_plugin_namespace = self ::get_abstract_plugin_base_namespace ( $ plugin_base );
90+ $ data ['abstractPluginNamespace ' ] = $ abstract_plugin_namespace ;
91+ $ zip ->addFromString (
92+ $ abstract_plugin_file_dest ,
93+ $ plugin_base
94+ );
95+ }
96+ }
6297 // find every file within origin directory including nested files
6398 $ iterator = new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ origin_dir ) );
6499 foreach ( $ iterator as $ current_file ) {
@@ -82,6 +117,8 @@ static function make_zip_download( $filename, $origin_dir, $tmp_dir, $data, $con
82117 }
83118 }
84119
120+
121+
85122 // only run these operations for standard plugins
86123 // add empties to key directories
87124 $ blank_file = '<?php ' . PHP_EOL . '// *gentle wave* not the code you \'re looking for.. ' . PHP_EOL ;
@@ -152,9 +189,12 @@ static function process_file_contents( $file ) {
152189 'main.php ' ,
153190 'README.md ' ,
154191 'composer.json ' ,
192+ 'app/class-plugin.php '
155193 ) );
156194
157195 if ( in_array ( $ filename , $ important_files ) ) {
196+ $ contents = str_ireplace ( '<%= ABSTRACT_PLUGIN_NAMESPACE %> ' , $ d ['abstractPluginNamespace ' ], $ contents );
197+ $ contents = str_ireplace ( '<%= ABSTRACT_PLUGIN_NAMESPACE_CHECK %> ' , addslashes ($ d ['abstractPluginNamespace ' ] ), $ contents );
158198 $ contents = str_ireplace ( '<%= AUTHORS %> ' , $ d ['plugin_authors ' ], $ contents );
159199 $ contents = str_ireplace ( '<%= TEAM_NAME %> ' , ! empty ( $ d ['plugin_teamorg ' ] ) ? $ d ['plugin_teamorg ' ] : '' , $ contents );
160200 $ contents = str_ireplace ( '<%= TEAM %> ' , ! empty ( $ d ['plugin_teamorg ' ] ) ? ' - ' . $ d ['plugin_teamorg ' ] : '' , $ contents );
@@ -218,4 +258,13 @@ static function process_filename( $file ) {
218258
219259 return $ file ['filename ' ];
220260 }
261+
262+ static function get_abstract_plugin_base_namespace ( $ file_contents ) {
263+ $ m = array ();
264+ if ( preg_match ('#^namespace\s+(.+?);$#sm ' , $ file_contents , $ m ) ) {
265+ return $ m [1 ];
266+ }
267+
268+ return null ;
269+ }
221270}
0 commit comments