Make WordPress Core


Ignore:
Timestamp:
02/12/2024 12:31:29 PM (11 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.