Make WordPress Core

Changeset 56787


Ignore:
Timestamp:
10/05/2023 03:08:59 PM (12 months ago)
Author:
audrasjb
Message:

Upgrade/Install: Check plugin compatibility during bulk upgrades.

Previously, bulk upgrades did not verify that a plugin package was compatible with the site's WordPress version or the server's PHP version. This could lead to
incompatible updates being installed, causing various compatibility issues and errors.

This change implements the following checks:

  • If available, the API response's requires and requires_php values are checked for compatibility. This saves time, diskspace, memory and file operations by

failing the upgrade before the package is downloaded and unpacked.

  • If the API check passes, the downloaded and unpacked package is verified using Plugin_Upgrader::check_package() to ensure a plugin file is present, and the

plugin's "RequiresWP" and "RequiresPHP" headers are compatible, if present. This ensures that a mismatch between the API response and the plugin file's headers does
not cause an incompatible plugin to be installed.

Props salcode, afragen, mukesh27, iammehedi1, zunaid321, johnbillion, SergeyBiryukov, costdev, nicolefurlan, audrasjb, nicolefurlan.
Merges [56525] to the 6.3 branch.
Fixes #59198.

--

_M 6.3
M 6.3/src/wp-admin/includes/class-plugin-upgrader.php

Location:
branches/6.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.3

  • branches/6.3/src/wp-admin/includes/class-plugin-upgrader.php

    r56174 r56787  
    275275     * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
    276276     *
     277     * @global string $wp_version The WordPress version string.
     278     *
    277279     * @param string[] $plugins Array of paths to plugin files relative to the plugins directory.
    278280     * @param array    $args {
     
    284286     */
    285287    public function bulk_upgrade( $plugins, $args = array() ) {
     288        global $wp_version;
     289
    286290        $defaults    = array(
    287291            'clear_update_cache' => true,
     
    344348            $this->skin->plugin_active = is_plugin_active( $plugin );
    345349
    346             $result = $this->run(
    347                 array(
    348                     'package'           => $r->package,
    349                     'destination'       => WP_PLUGIN_DIR,
    350                     'clear_destination' => true,
    351                     'clear_working'     => true,
    352                     'is_multi'          => true,
    353                     'hook_extra'        => array(
    354                         'plugin'      => $plugin,
    355                         'temp_backup' => array(
    356                             'slug' => dirname( $plugin ),
    357                             'src'  => WP_PLUGIN_DIR,
    358                             'dir'  => 'plugins',
     350            if ( isset( $r->requires ) && ! is_wp_version_compatible( $r->requires ) ) {
     351                $result = new WP_Error(
     352                    'incompatible_wp_required_version',
     353                    sprintf(
     354                        /* translators: 1: Current WordPress version, 2: WordPress version required by the new plugin version. */
     355                        __( 'Your WordPress version is %1$s, however the new plugin version requires %2$s.' ),
     356                        $wp_version,
     357                        $r->requires
     358                    )
     359                );
     360
     361                $this->skin->before( $result );
     362                $this->skin->error( $result );
     363                $this->skin->after();
     364            } elseif ( isset( $r->requires_php ) && ! is_php_version_compatible( $r->requires_php ) ) {
     365                $result = new WP_Error(
     366                    'incompatible_php_required_version',
     367                    sprintf(
     368                        /* translators: 1: Current PHP version, 2: PHP version required by the new plugin version. */
     369                        __( 'The PHP version on your server is %1$s, however the new plugin version requires %2$s.' ),
     370                        PHP_VERSION,
     371                        $r->requires_php
     372                    )
     373                );
     374
     375                $this->skin->before( $result );
     376                $this->skin->error( $result );
     377                $this->skin->after();
     378            } else {
     379                add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
     380                $result = $this->run(
     381                    array(
     382                        'package'           => $r->package,
     383                        'destination'       => WP_PLUGIN_DIR,
     384                        'clear_destination' => true,
     385                        'clear_working'     => true,
     386                        'is_multi'          => true,
     387                        'hook_extra'        => array(
     388                            'plugin'      => $plugin,
     389                            'temp_backup' => array(
     390                                'slug' => dirname( $plugin ),
     391                                'src'  => WP_PLUGIN_DIR,
     392                                'dir'  => 'plugins',
     393                            ),
    359394                        ),
    360                     ),
    361                 )
    362             );
     395                    )
     396                );
     397                remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
     398            }
    363399
    364400            $results[ $plugin ] = $result;
Note: See TracChangeset for help on using the changeset viewer.