Make WordPress Core


Ignore:
Timestamp:
02/20/2024 07:25:38 AM (14 months ago)
Author:
costdev
Message:

Plugin Dependencies: Remove auto-deactivation and bootstrapping logic.

Automatic deactivation of dependents with unmet dependencies requires a write operation to the database. This was performed during Core's bootstrap, which risked the database and cache becoming out-of-sync on sites with heavy traffic.

No longer loading plugins that have unmet requirements has not had a final approach decided core-wide, and is still in discussion in #60491 to be handled in a future release.

The plugin_data option, used to persistently store plugin data for detecting unmet dependencies during Core's bootstrap, is no longer needed.

Follow-up to [57545], [57592], [57606], [57617].

Props dd32, azaozz, swissspidy, desrosj, afragen, pbiron, zunaid321, costdev.
Fixes #60457. See #60491, #60510, #60518.

File:
1 edited

Legend:

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

    r57628 r57658  
    389389require ABSPATH . WPINC . '/interactivity-api/class-wp-interactivity-api-directives-processor.php';
    390390require ABSPATH . WPINC . '/interactivity-api/interactivity-api.php';
     391require ABSPATH . WPINC . '/class-wp-plugin-dependencies.php';
    391392
    392393wp_script_modules()->add_hooks();
     
    419420
    420421$GLOBALS['wp_plugin_paths'] = array();
    421 
    422 // Load and initialize WP_Plugin_Dependencies.
    423 require_once ABSPATH . WPINC . '/class-wp-plugin-dependencies.php';
    424 if ( ! defined( 'WP_RUN_CORE_TESTS' ) ) {
    425     WP_Plugin_Dependencies::initialize();
    426 }
    427422
    428423// Load must-use plugins.
     
    500495
    501496// Load active plugins.
    502 $all_plugin_data    = get_option( 'plugin_data', array() );
    503 $failed_plugins     = array();
    504 $plugins_dir_strlen = strlen( trailingslashit( WP_PLUGIN_DIR ) );
    505497foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
    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'] : '',
    522         );
    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']
    563             );
    564         }
    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         }
    579     }
    580 
    581498    wp_register_plugin_realpath( $plugin );
    582499
     
    596513unset( $plugin, $_wp_plugin_file );
    597514
    598 if ( ! empty( $failed_plugins ) ) {
    599     add_action(
    600         'admin_notices',
    601         function () use ( $failed_plugins ) {
    602             global $pagenow;
    603 
    604             if ( 'index.php' === $pagenow || 'plugins.php' === $pagenow ) {
    605                 echo implode( '', $failed_plugins );
    606             }
    607         }
    608     );
    609 }
    610 unset( $failed_plugins );
    611 
    612515// Load pluggable functions.
    613516require ABSPATH . WPINC . '/pluggable.php';
Note: See TracChangeset for help on using the changeset viewer.