Make WordPress Core

Changeset 57622


Ignore:
Timestamp:
02/13/2024 01:28:06 PM (8 months ago)
Author:
costdev
Message:

Upgrade/Install: Only check plugins whose data is already stored.

In [57592], some update_option() calls were removed from bootstrapping. However, this also removed a check to ensure an array key existed, and populated it if not.

Scaffolding tests by WP-CLI revealed that a plugin in the active_plugins option may not have data already stored within the plugin_data option, causing a PHP warning for an undefined array key. This data will be added the next time get_plugins() is called.

This adds a condition to ensure the requirements checks are only performed on plugins whose data is already stored in the plugin_data option.

Follow-up to [57592].

Props swissspidy, hellofromTonya, costdev.
Fixes #60461.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-settings.php

    r57606 r57622  
    504504$plugins_dir_strlen = strlen( trailingslashit( WP_PLUGIN_DIR ) );
    505505foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
    506     $plugin_file    = substr( $plugin, $plugins_dir_strlen );
    507     $plugin_headers = $all_plugin_data[ $plugin_file ];
    508     $errors         = array();
    509     $requirements   = array(
    510         'requires'     => ! empty( $plugin_headers['RequiresWP'] ) ? $plugin_headers['RequiresWP'] : '',
    511         'requires_php' => ! empty( $plugin_headers['RequiresPHP'] ) ? $plugin_headers['RequiresPHP'] : '',
    512     );
    513     $compatible_wp  = is_wp_version_compatible( $requirements['requires'] );
    514     $compatible_php = is_php_version_compatible( $requirements['requires_php'] );
    515 
    516     $php_update_message = '</p><p>' . sprintf(
    517         /* translators: %s: URL to Update PHP page. */
    518         __( '<a href="%s">Learn more about updating PHP</a>.' ),
    519         esc_url( wp_get_update_php_url() )
    520     );
    521 
    522     $annotation = wp_get_update_php_annotation();
    523 
    524     if ( $annotation ) {
    525         $php_update_message .= '</p><p><em>' . $annotation . '</em>';
    526     }
    527 
    528     if ( ! $compatible_wp && ! $compatible_php ) {
    529         $errors[] = sprintf(
    530             /* translators: 1: Current WordPress version, 2: Current PHP version, 3: Plugin name, 4: Required WordPress version, 5: Required PHP version. */
    531             _x( '<strong>Error:</strong> Current versions of WordPress (%1$s) and PHP (%2$s) do not meet minimum requirements for %3$s. The plugin requires WordPress %4$s and PHP %5$s.', 'plugin' ),
    532             get_bloginfo( 'version' ),
    533             PHP_VERSION,
    534             $plugin_headers['Name'],
    535             $requirements['requires'],
    536             $requirements['requires_php']
    537         ) . $php_update_message;
    538     } elseif ( ! $compatible_php ) {
    539         $errors[] = sprintf(
    540             /* translators: 1: Current PHP version, 2: Plugin name, 3: Required PHP version. */
    541             _x( '<strong>Error:</strong> Current PHP version (%1$s) does not meet minimum requirements for %2$s. The plugin requires PHP %3$s.', 'plugin' ),
    542             PHP_VERSION,
    543             $plugin_headers['Name'],
    544             $requirements['requires_php']
    545         ) . $php_update_message;
    546     } elseif ( ! $compatible_wp ) {
    547         $errors[] = sprintf(
    548             /* translators: 1: Current WordPress version, 2: Plugin name, 3: Required WordPress version. */
    549             _x( '<strong>Error:</strong> Current WordPress version (%1$s) does not meet minimum requirements for %2$s. The plugin requires WordPress %3$s.', 'plugin' ),
    550             get_bloginfo( 'version' ),
    551             $plugin_headers['Name'],
    552             $requirements['requires']
     506    $plugin_file = substr( $plugin, $plugins_dir_strlen );
     507
     508    /*
     509     * Skip any plugins that have not been added to the 'plugin_data' option yet.
     510     *
     511     * Some plugin files may be added locally and activated, but will not yet be
     512     * added to the 'plugin_data' option. This causes the 'active_plugins' option
     513     * and the 'plugin_data' option to be temporarily out of sync until the next
     514     * call to `get_plugins()`.
     515     */
     516    if ( isset( $all_plugin_data[ $plugin_file ] ) ) {
     517        $plugin_headers = $all_plugin_data[ $plugin_file ];
     518        $errors         = array();
     519        $requirements   = array(
     520            'requires'     => ! empty( $plugin_headers['RequiresWP'] ) ? $plugin_headers['RequiresWP'] : '',
     521            'requires_php' => ! empty( $plugin_headers['RequiresPHP'] ) ? $plugin_headers['RequiresPHP'] : '',
    553522        );
    554     }
    555 
    556     if ( ! empty( $errors ) ) {
    557         $failed_plugins[ $plugin_file ] = '';
    558         foreach ( $errors as $error ) {
    559             $failed_plugins[ $plugin_file ] .= wp_get_admin_notice(
    560                 $error,
    561                 array(
    562                     'type'        => 'error',
    563                     'dismissible' => true,
    564                 )
     523        $compatible_wp  = is_wp_version_compatible( $requirements['requires'] );
     524        $compatible_php = is_php_version_compatible( $requirements['requires_php'] );
     525
     526        $php_update_message = '</p><p>' . sprintf(
     527            /* translators: %s: URL to Update PHP page. */
     528            __( '<a href="%s">Learn more about updating PHP</a>.' ),
     529            esc_url( wp_get_update_php_url() )
     530        );
     531
     532        $annotation = wp_get_update_php_annotation();
     533
     534        if ( $annotation ) {
     535            $php_update_message .= '</p><p><em>' . $annotation . '</em>';
     536        }
     537
     538        if ( ! $compatible_wp && ! $compatible_php ) {
     539            $errors[] = sprintf(
     540                /* translators: 1: Current WordPress version, 2: Current PHP version, 3: Plugin name, 4: Required WordPress version, 5: Required PHP version. */
     541                _x( '<strong>Error:</strong> Current versions of WordPress (%1$s) and PHP (%2$s) do not meet minimum requirements for %3$s. The plugin requires WordPress %4$s and PHP %5$s.', 'plugin' ),
     542                get_bloginfo( 'version' ),
     543                PHP_VERSION,
     544                $plugin_headers['Name'],
     545                $requirements['requires'],
     546                $requirements['requires_php']
     547            ) . $php_update_message;
     548        } elseif ( ! $compatible_php ) {
     549            $errors[] = sprintf(
     550                /* translators: 1: Current PHP version, 2: Plugin name, 3: Required PHP version. */
     551                _x( '<strong>Error:</strong> Current PHP version (%1$s) does not meet minimum requirements for %2$s. The plugin requires PHP %3$s.', 'plugin' ),
     552                PHP_VERSION,
     553                $plugin_headers['Name'],
     554                $requirements['requires_php']
     555            ) . $php_update_message;
     556        } elseif ( ! $compatible_wp ) {
     557            $errors[] = sprintf(
     558                /* translators: 1: Current WordPress version, 2: Plugin name, 3: Required WordPress version. */
     559                _x( '<strong>Error:</strong> Current WordPress version (%1$s) does not meet minimum requirements for %2$s. The plugin requires WordPress %3$s.', 'plugin' ),
     560                get_bloginfo( 'version' ),
     561                $plugin_headers['Name'],
     562                $requirements['requires']
    565563            );
    566564        }
    567         continue;
     565
     566        if ( ! empty( $errors ) ) {
     567            $failed_plugins[ $plugin_file ] = '';
     568            foreach ( $errors as $error ) {
     569                $failed_plugins[ $plugin_file ] .= wp_get_admin_notice(
     570                    $error,
     571                    array(
     572                        'type'        => 'error',
     573                        'dismissible' => true,
     574                    )
     575                );
     576            }
     577            continue;
     578        }
    568579    }
    569580
Note: See TracChangeset for help on using the changeset viewer.