Making WordPress.org


Ignore:
Timestamp:
01/12/2024 05:29:18 AM (3 years ago)
Author:
tellyworth
Message:

Plugin Directory: Load plugin dependencies in mod preview

When plugin moderators are previewing a plugin in Playground, this will attempt to load a plugin's depenedencies, for easier testing.

It also loads a small helper plugin.

See #7380.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-blueprint.php

    r13088 r13105  
    5858        }
    5959
     60        protected function get_zip_url_by_slug( $slug ) {
     61                $plugin = Plugin_Directory::get_plugin_post( $slug );
     62                if ( !$plugin ) {
     63                        return false;
     64                }
     65
     66                $zips = get_attached_media( 'application/zip', $plugin );
     67                // Return the first (is this correct?)
     68                if ( $zips & count( $zips ) ) {
     69                        return wp_get_attachment_url( reset($zips)->ID );
     70                }
     71                return false;
     72        }
     73
    6074        function reviewer_blueprint( $request, $plugin ) {
    6175                // Direct zip preview for plugin reviewers
     
    6983                                                $landing_page = '/wp-admin/plugins.php';
    7084                                                $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 ] );
    7195
    7296                                                // Plugin deactivated, and land on the Plugin Check page
    7397                                                if ( 'pcp' === $request->get_param('type') ) {
    74                                                         $landing_page = '/wp-admin/admin.php?page=plugin-check';
     98                                                        $landing_page = '/wp-admin/admin.php?page=plugin-check&plugin=' . sanitize_title( $request['plugin_slug'] );
    7599                                                        $activate_plugin = false;
     100                                                        $dependencies = [];
    76101                                                }
    77102
     
    91116                                                                (object)[
    92117                                                                        'step' => 'installPlugin',
    93                                                                         'pluginZipFile' => [
     118                                                                        'pluginZipFile' => (object)[
    94119                                                                                'resource' => 'wordpress.org/plugins',
    95120                                                                                'slug'     => 'plugin-check',
     
    114139                                                ];
    115140
     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
    116177                                                $output = json_encode( $zip_blueprint );
    117178
Note: See TracChangeset for help on using the changeset viewer.