Make WordPress Core

Changeset 53004


Ignore:
Timestamp:
03/28/2022 01:57:08 PM (5 months ago)
Author:
audrasjb
Message:

Plugins: Avoid stomping of some variables in wp-settings.php.

This changeset decreases the chance of accidentally overwriting some variables located in wp-settings.php, as the chance of overriding a variable called $_wp_plugin_file would be lower than for $plugin, $mu_plugin or $network_plugin.

Props stevegrunwell, joyously, peterwilsoncc, ocean90, SergeyBiryukov, jrf, azouamauriac.
Fixes #55432.

File:
1 edited

Legend:

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

    r52286 r53004  
    347347// Load must-use plugins.
    348348foreach ( wp_get_mu_plugins() as $mu_plugin ) {
     349    $_wp_plugin_file = $mu_plugin;
    349350    include_once $mu_plugin;
     351    $mu_plugin = $_wp_plugin_file; // Avoid stomping of the $mu_plugin variable in a plugin.
    350352
    351353    /**
     
    358360    do_action( 'mu_plugin_loaded', $mu_plugin );
    359361}
    360 unset( $mu_plugin );
     362unset( $mu_plugin, $_wp_plugin_file );
    361363
    362364// Load network activated plugins.
     
    364366    foreach ( wp_get_active_network_plugins() as $network_plugin ) {
    365367        wp_register_plugin_realpath( $network_plugin );
     368
     369        $_wp_plugin_file = $network_plugin;
    366370        include_once $network_plugin;
     371        $network_plugin = $_wp_plugin_file; // Avoid stomping of the $network_plugin variable in a plugin.
    367372
    368373        /**
     
    375380        do_action( 'network_plugin_loaded', $network_plugin );
    376381    }
    377     unset( $network_plugin );
     382    unset( $network_plugin, $_wp_plugin_file );
    378383}
    379384
     
    416421foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
    417422    wp_register_plugin_realpath( $plugin );
     423
     424    $_wp_plugin_file = $plugin;
    418425    include_once $plugin;
     426    $plugin = $_wp_plugin_file; // Avoid stomping of the $plugin variable in a plugin.
    419427
    420428    /**
     
    427435    do_action( 'plugin_loaded', $plugin );
    428436}
    429 unset( $plugin );
     437unset( $plugin, $_wp_plugin_file );
    430438
    431439// Load pluggable functions.
Note: See TracChangeset for help on using the changeset viewer.