Changeset 13335 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-blueprint.php
- Timestamp:
- 03/14/2024 05:40:44 AM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-blueprint.php
r13189 r13335 40 40 $this->reviewer_blueprint( $request, $plugin ); 41 41 } 42 if ( $request->get_param('url_hash') ) { 43 $this->developer_blueprint( $request, $plugin ); 44 } 42 45 43 46 $blueprints = get_post_meta( $plugin->ID, 'assets_blueprints', true ); … … 76 79 if ( $request->get_param('zip_hash') ) { 77 80 foreach ( get_attached_media( 'application/zip', $plugin ) as $zip_file ) { 78 if ( hash_equals( Template::preview_link_hash( $zip_file->ID, 0 ), $request->get_param('zip_hash') ) || 79 hash_equals( Template::preview_link_hash( $zip_file->ID, -1 ), $request->get_param('zip_hash') ) ) { 81 $zip_file_path = get_attached_file( $zip_file->ID ); 82 if ( hash_equals( Template::preview_link_hash( $zip_file_path, 0 ), $request->get_param('zip_hash') ) || 83 hash_equals( Template::preview_link_hash( $zip_file_path, -1 ), $request->get_param('zip_hash') ) ) { 80 84 $zip_url = wp_get_attachment_url( $zip_file->ID ); 81 85 if ( $zip_url ) { 82 83 $landing_page = '/wp-admin/plugins.php'; 84 $activate_plugin = true; 85 $dependencies = $plugin->requires_plugins ?: []; 86 87 if ( stripos( $plugin->post_title, 'woocommerce' ) ) { 88 $dependencies[] = 'woocommerce'; 89 } 90 if ( stripos( $plugin->post_title, 'buddypress' ) ) { 91 $dependencies[] = 'buddypress'; 92 } 93 94 $dependencies = array_diff( $dependencies, [ $plugin->post_name ] ); 95 96 // Plugin deactivated, and land on the Plugin Check page 97 if ( 'pcp' === $request->get_param('type') ) { 98 $landing_page = '/wp-admin/admin.php?page=plugin-check&plugin=' . sanitize_title( $request['plugin_slug'] ); 99 $activate_plugin = false; 100 $dependencies = []; 101 } 102 103 $zip_blueprint = (object)[ 104 'landingPage' => $landing_page, 105 'preferredVersions' => (object)[ 106 'php' => '8.0', 107 'wp' => 'latest', 108 ], 109 'phpExtensionBundles' => [ 110 'kitchen-sink' 111 ], 112 'features' => (object)[ 113 'networking' => true 114 ], 115 'steps' => [ 116 (object)[ 117 'step' => 'installPlugin', 118 'pluginZipFile' => (object)[ 119 'resource' => 'wordpress.org/plugins', 120 'slug' => 'plugin-check', 121 ] 122 ], 123 (object)[ 124 'step' => 'installPlugin', 125 'pluginZipFile' => (object)[ 126 'resource' => 'url', 127 'url' => $zip_url, 128 ], 129 'options' => (object)[ 130 'activate' => (bool)$activate_plugin 131 ] 132 ], 133 (object)[ 134 'step' => 'login', 135 'username' => 'admin', 136 'password' => 'password', 137 ] 138 ] 139 ]; 140 141 if ( $dependencies ) { 142 $dep_step = []; 143 foreach ( $dependencies as $slug ) { 144 $dep_step[] = (object)[ 145 'step' => 'installPlugin', 146 'pluginZipFile' => [ 147 'resource' => 'wordpress.org/plugins', 148 'slug' => sanitize_title( $slug ), 149 ], 150 'options' => (object)[ 151 'activate' => true 152 ] 153 ]; 154 } 155 // Insert dependencies aftter PCP 156 array_splice( $zip_blueprint->steps, 1, 0, $dep_step ); 157 } 158 159 // Include the helper plugin too 160 $helper_zip = self::get_zip_url_by_slug( 'playground-review-helper' ); 161 if ( $helper_zip && 'pcp' !== $request->get_param('type') ) { 162 $helper_step = [ 163 (object)[ 164 'step' => 'installPlugin', 165 'pluginZipFile' => [ 166 'resource' => 'url', 167 'url' => $helper_zip, 168 ], 169 'options' => (object)[ 170 'activate' => (bool)$activate_plugin 171 ] 172 ] 173 ]; 174 array_splice( $zip_blueprint->steps, 1, 0, $helper_step ); 175 } 176 177 $output = json_encode( $zip_blueprint ); 86 $is_pcp = 'pcp' === $request->get_param('type'); 87 $output = $this->generate_blueprint( $request, $plugin, $zip_url, $is_pcp, true ); 178 88 179 89 if ( $output ) { … … 187 97 188 98 return new \WP_Error( 'invalid_blueprint', 'Invalid file', array( 'status' => 500 ) ); 189 99 } 100 101 function developer_blueprint( $request, $plugin ) { 102 // Generated blueprint for developers who haven't yet created a custom blueprint 103 if ( $request->get_param('url_hash') ) { 104 $download_link = Template::download_link( $plugin ); 105 if ( $download_link ) { 106 if ( hash_equals( Template::preview_link_hash( $download_link, 0 ), $request->get_param('url_hash') ) || 107 hash_equals( Template::preview_link_hash( $download_link, -1 ), $request->get_param('url_hash') ) ) { 108 $output = $this->generate_blueprint( $request, $plugin, $download_link, false, false ); 109 110 if ( $output ) { 111 header( 'Access-Control-Allow-Origin: https://playground.wordpress.net' ); 112 die( $output ); 113 } 114 } 115 } 116 } 117 } 118 119 public function generate_blueprint( $request, $plugin, $zip_url, $install_pcp = true, $install_prh = true ) { 120 $landing_page = '/wp-admin/plugins.php'; 121 $activate_plugin = true; 122 $dependencies = $plugin->requires_plugins ?: []; 123 124 if ( stripos( $plugin->post_title, 'woocommerce' ) ) { 125 $dependencies[] = 'woocommerce'; 126 } 127 if ( stripos( $plugin->post_title, 'buddypress' ) ) { 128 $dependencies[] = 'buddypress'; 129 } 130 131 $dependencies = array_diff( $dependencies, [ $plugin->post_name ] ); 132 133 // Plugin deactivated, and land on the Plugin Check page 134 if ( $install_pcp ) { 135 $landing_page = '/wp-admin/admin.php?page=plugin-check&plugin=' . sanitize_title( $request['plugin_slug'] ); 136 $activate_plugin = false; 137 $dependencies = []; 138 } 139 140 $zip_blueprint = (object)[ 141 'landingPage' => $landing_page, 142 'preferredVersions' => (object)[ 143 'php' => '8.0', 144 'wp' => 'latest', 145 ], 146 'phpExtensionBundles' => [ 147 'kitchen-sink' 148 ], 149 'features' => (object)[ 150 'networking' => true 151 ], 152 ]; 153 154 $steps = []; 155 156 // PCP first, if needed. 157 if ( $install_pcp ) { 158 $steps[] = (object)[ 159 'step' => 'installPlugin', 160 'pluginZipFile' => (object)[ 161 'resource' => 'wordpress.org/plugins', 162 'slug' => 'plugin-check', 163 ] 164 ]; 165 } 166 167 // Include the helper plugin too 168 $helper_zip = self::get_zip_url_by_slug( 'playground-review-helper' ); 169 if ( $helper_zip && $install_prh ) { 170 $steps[] = (object)[ 171 'step' => 'installPlugin', 172 'pluginZipFile' => [ 173 'resource' => 'url', 174 'url' => $helper_zip, 175 ], 176 'options' => (object)[ 177 'activate' => (bool)$activate_plugin 178 ] 179 ]; 180 } 181 182 // Dependencies next 183 if ( $dependencies ) { 184 foreach ( $dependencies as $slug ) { 185 $steps[] = (object)[ 186 'step' => 'installPlugin', 187 'pluginZipFile' => [ 188 'resource' => 'wordpress.org/plugins', 189 'slug' => sanitize_title( $slug ), 190 ], 191 'options' => (object)[ 192 'activate' => true 193 ] 194 ]; 195 } 196 } 197 198 // Now the plugin itself 199 $steps[] = (object)[ 200 'step' => 'installPlugin', 201 'pluginZipFile' => (object)[ 202 'resource' => 'url', 203 'url' => $zip_url, 204 ], 205 'options' => (object)[ 206 'activate' => (bool)$activate_plugin 207 ] 208 ]; 209 210 // Finally log in 211 $steps[] = (object)[ 212 'step' => 'login', 213 'username' => 'admin', 214 'password' => 'password', 215 ]; 216 217 $zip_blueprint->steps = $steps; 218 219 $output = json_encode( $zip_blueprint, JSON_PRETTY_PRINT ); 220 221 return $output; 190 222 } 191 223
Note: See TracChangeset
for help on using the changeset viewer.