Making WordPress.org

Changeset 14078


Ignore:
Timestamp:
09/25/2024 04:48:38 AM (4 months ago)
Author:
dd32
Message:

Plugin Directory: Plugin check on upload: When running plugin check against an uploaded ZIP file, attempt to force the plugin to be installed into the expected folder path.

This resolves issues of plugin check suggesting that the textdomain should be 2024_09_25-uploaded-file-SLUG rather than SLUG.

This is intended on being temporary until the upstream issue is resolved.

See #7405.
See https://github.com/WordPress/wordpress-playground/issues/1802.

File:
1 edited

Legend:

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

    r14075 r14078  
    195195        if ( $helper_zip && $install_prh ) {
    196196            $steps[] = (object)[
    197                     'step' => 'installPlugin',
    198                     'pluginZipFile' => [
    199                         'resource' => 'url',
    200                         'url'      => $helper_zip,
    201                     ],
    202                     'options' => (object)[
    203                         'activate' => (bool)$activate_plugin
    204                     ]
    205                 ];
     197                'step' => 'installPlugin',
     198                'pluginZipFile' => [
     199                    'resource' => 'url',
     200                    'url'      => $helper_zip,
     201                ],
     202                'options' => (object)[
     203                    'activate' => (bool)$activate_plugin
     204                ]
     205            ];
    206206        }
    207207
     
    224224        // Now the plugin itself
    225225        $steps[] = (object)[
    226                     'step' => 'installPlugin',
    227                     'pluginZipFile' => (object)[
    228                         'resource' => 'url',
    229                         'url'      => $zip_url,
    230                     ],
    231                     'options' => (object)[
    232                         'activate' => (bool)$activate_plugin
    233                     ]
    234                 ];
     226            'step' => 'installPlugin',
     227            'pluginZipFile' => (object)[
     228                'resource' => 'url',
     229                'url'      => $zip_url,
     230            ],
     231            'options' => (object)[
     232                'activate' => (bool)$activate_plugin
     233            ]
     234        ];
     235
     236        /*
     237         * Maybe rename the plugin to exist in the expected folder.
     238         *
     239         * Temporary workaround for https://github.com/WordPress/wordpress-playground/issues/1802
     240         */
     241        if ( ! str_starts_with( 'https://downloads.wordpress.org/', $zip_url ) ) {
     242            $steps[] = (object)[
     243                'step' => 'runPHP',
     244                'code' => '<?php
     245                    include "/wordpress/wp-load.php";
     246                    $expected_slug = ' . var_export( $plugin->post_name, true ) . ';
     247                    $expected_plugins = ' . var_export( array_merge( [ 'plugin-check', 'playground-review-helper' ], $dependencies ), true ) . ';
     248                    $installed_plugins = array_diff(
     249                        array_map( "basename", glob( WP_PLUGIN_DIR . "/*", GLOB_ONLYDIR ) ),
     250                        $expected_plugins
     251                    );
     252                    if ( 1 === count( $installed_plugins) ) {
     253                        $plugin_dir = reset( $installed_plugins );
     254                        if ( $plugin_dir !== $expected_slug ) {
     255                            if ( rename( WP_PLUGIN_DIR . "/" . $plugin_dir, WP_PLUGIN_DIR . "/" . $expected_slug ) ) {
     256                                $active_plugins = get_option( "active_plugins" );
     257                                foreach ( $active_plugins as &$active_plugin ) {
     258                                    if ( 0 === strpos( $active_plugin, $plugin_dir ) ) {
     259                                        $active_plugin = $expected_slug . substr( $active_plugin, strlen( $plugin_dir ) );
     260                                    }
     261                                }
     262                                update_option( "active_plugins", $active_plugins );
     263                            }
     264                        }
     265                    }
     266                '
     267            ];
     268        }
    235269
    236270        // Finally log in
    237271        $steps[] = (object)[
    238                     'step' => 'login',
    239                     'username' => 'admin',
    240                     'password' => 'password',
    241                 ];
     272            'step' => 'login',
     273            'username' => 'admin',
     274            'password' => 'password',
     275        ];
    242276
    243277        $zip_blueprint->steps = $steps;
Note: See TracChangeset for help on using the changeset viewer.