From 1c07680a7a2f7c54e9f8c72f19ea278644a3cec0 Mon Sep 17 00:00:00 2001 From: audrasjb Date: Mon, 28 Mar 2022 13:59:02 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@53004 git-svn-id: http://core.svn.wordpress.org/trunk@52593 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/version.php | 2 +- wp-settings.php | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/wp-includes/version.php b/wp-includes/version.php index 81eccc33e262..4cec7d8ce3b3 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-53003'; +$wp_version = '6.0-alpha-53004'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-settings.php b/wp-settings.php index 85b2f2146a68..355cb689bbeb 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -346,7 +346,9 @@ // Load must-use plugins. foreach ( wp_get_mu_plugins() as $mu_plugin ) { + $_wp_plugin_file = $mu_plugin; include_once $mu_plugin; + $mu_plugin = $_wp_plugin_file; // Avoid stomping of the $mu_plugin variable in a plugin. /** * Fires once a single must-use plugin has loaded. @@ -357,13 +359,16 @@ */ do_action( 'mu_plugin_loaded', $mu_plugin ); } -unset( $mu_plugin ); +unset( $mu_plugin, $_wp_plugin_file ); // Load network activated plugins. if ( is_multisite() ) { foreach ( wp_get_active_network_plugins() as $network_plugin ) { wp_register_plugin_realpath( $network_plugin ); + + $_wp_plugin_file = $network_plugin; include_once $network_plugin; + $network_plugin = $_wp_plugin_file; // Avoid stomping of the $network_plugin variable in a plugin. /** * Fires once a single network-activated plugin has loaded. @@ -374,7 +379,7 @@ */ do_action( 'network_plugin_loaded', $network_plugin ); } - unset( $network_plugin ); + unset( $network_plugin, $_wp_plugin_file ); } /** @@ -415,7 +420,10 @@ // Load active plugins. foreach ( wp_get_active_and_valid_plugins() as $plugin ) { wp_register_plugin_realpath( $plugin ); + + $_wp_plugin_file = $plugin; include_once $plugin; + $plugin = $_wp_plugin_file; // Avoid stomping of the $plugin variable in a plugin. /** * Fires once a single activated plugin has loaded. @@ -426,7 +434,7 @@ */ do_action( 'plugin_loaded', $plugin ); } -unset( $plugin ); +unset( $plugin, $_wp_plugin_file ); // Load pluggable functions. require ABSPATH . WPINC . '/pluggable.php';