Make WordPress Core

Changeset 57592


Ignore:
Timestamp:
02/12/2024 12:31:29 PM (7 months ago)
Author:
costdev
Message:

Upgrade/Install: Avoid update_option() calls during bootstrap.

[57545] introduced the Plugin Dependencies feature, which contains a new plugin_data option.

Previously, the plugin_data option was being updated during bootstrap and in get_plugins(), causing an error when using the install script as the options database table does not yet exist, and also risked an "out of sync" issue between the database and the cache on websites with heavy traffic.

This removes the calls to update_option() during Core's bootstrap, and guards the call in get_plugins() to ensure that it doesn't run when WordPress is installing.

Follow-up to [57545].

Props desrosj, swisspidy, huzaifaalmesbah, afragen, dd32, azaozz, costdev.
Fixes #60461. See #60457, #60491.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/plugin.php

    r57545 r57592  
    361361    $cache_plugins[ $plugin_folder ] = $wp_plugins;
    362362    wp_cache_set( 'plugins', $cache_plugins, 'plugins' );
    363     update_option( 'plugin_data', $new_plugin_data );
     363
     364    if ( ! wp_installing() ) {
     365        update_option( 'plugin_data', $new_plugin_data );
     366    }
    364367
    365368    return $wp_plugins;
  • trunk/src/wp-includes/load.php

    r57545 r57592  
    987987    $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
    988988
    989     $invalid_plugins = array();
    990989    foreach ( $active_plugins as $plugin ) {
    991990        if ( ! validate_file( $plugin )                     // $plugin must validate as file.
     
    996995        ) {
    997996            $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
    998         } else {
    999             $invalid_plugins[] = $plugin;
    1000         }
    1001     }
    1002 
    1003     if ( ! empty( $invalid_plugins ) ) {
    1004         $all_plugin_data = get_option( 'plugin_data', array() );
    1005 
    1006         if ( ! empty( $all_plugin_data ) ) {
    1007             foreach ( $invalid_plugins as $invalid_plugin ) {
    1008                 unset( $all_plugin_data[ $invalid_plugin ] );
    1009             }
    1010 
    1011             update_option( 'plugin_data', $all_plugin_data );
    1012997        }
    1013998    }
  • trunk/src/wp-settings.php

    r57563 r57592  
    500500
    501501// Load active plugins.
    502 $all_plugin_data    = get_option( 'plugin_data', array() );
    503 $failed_plugins     = array();
    504 $update_plugin_data = false;
     502$all_plugin_data = get_option( 'plugin_data', array() );
     503$failed_plugins  = array();
    505504foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
    506     $plugin_file = str_replace( trailingslashit( WP_PLUGIN_DIR ), '', $plugin );
    507     if ( ! isset( $all_plugin_data[ $plugin_file ] ) ) {
    508         require_once ABSPATH . 'wp-admin/includes/plugin.php';
    509         $all_plugin_data[ $plugin_file ] = get_plugin_data( WP_PLUGIN_DIR . "/$plugin_file" );
    510 
    511         $update_plugin_data = true;
    512     }
    513 
    514     $plugin_headers   = $all_plugin_data[ $plugin_file ];
    515     $errors           = array();
    516     $requirements     = array(
    517         'requires'         => ! empty( $plugin_headers['RequiresWP'] ) ? $plugin_headers['RequiresWP'] : '',
    518         'requires_php'     => ! empty( $plugin_headers['RequiresPHP'] ) ? $plugin_headers['RequiresPHP'] : '',
    519         'requires_plugins' => ! empty( $plugin_headers['RequiresPlugins'] ) ? $plugin_headers['RequiresPlugins'] : '',
     505    $plugin_file    = str_replace( trailingslashit( WP_PLUGIN_DIR ), '', $plugin );
     506    $plugin_headers = $all_plugin_data[ $plugin_file ];
     507    $errors         = array();
     508    $requirements   = array(
     509        'requires'     => ! empty( $plugin_headers['RequiresWP'] ) ? $plugin_headers['RequiresWP'] : '',
     510        'requires_php' => ! empty( $plugin_headers['RequiresPHP'] ) ? $plugin_headers['RequiresPHP'] : '',
    520511    );
    521     $compatible_wp    = is_wp_version_compatible( $requirements['requires'] );
    522     $compatible_php   = is_php_version_compatible( $requirements['requires_php'] );
    523     $dependencies_met = ! WP_Plugin_Dependencies::has_unmet_dependencies( $plugin_file );
     512    $compatible_wp  = is_wp_version_compatible( $requirements['requires'] );
     513    $compatible_php = is_php_version_compatible( $requirements['requires_php'] );
    524514
    525515    $php_update_message = '</p><p>' . sprintf(
     
    533523    if ( $annotation ) {
    534524        $php_update_message .= '</p><p><em>' . $annotation . '</em>';
    535     }
    536 
    537     if ( ! $dependencies_met ) {
    538         $errors[] = sprintf(
    539             /* translators: %s: The plugin's name. */
    540             _x( '%s has unmet dependencies.', 'plugin' ),
    541             $plugin_headers['Name']
    542         );
    543525    }
    544526
     
    602584unset( $plugin, $_wp_plugin_file );
    603585
    604 if ( $update_plugin_data ) {
    605     update_option( 'plugin_data', $all_plugin_data );
    606 }
    607 
    608586if ( ! empty( $failed_plugins ) ) {
    609587    add_action(
Note: See TracChangeset for help on using the changeset viewer.