From fe549286d57e7b62c3fa1aac4b1e2f80ada540a3 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 24 Apr 2021 18:04:04 +0000 Subject: [PATCH] Plugins: When loading a plugin in a "sandbox" on activation, do it in a separate function. This avoids accidentally overriding some variables in the scope of `activate_plugin()`, e.g. `$silent` or `$network_wide`. Plugins expecting to have access to `$network_wide` directly on inclusion should receive it as an argument of the activation hook callback instead, on any of these actions: * `activate_plugin` * `activate_{$plugin}` * `activated_plugin` Follow-up to [28644]. Props Mike_Cowobo, dd32, DrewAPicture, mensmaximus, SergeyBiryukov. Fixes #31104. Built from https://develop.svn.wordpress.org/trunk@50787 git-svn-id: http://core.svn.wordpress.org/trunk@50396 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/plugin.php | 11 +++-------- wp-includes/version.php | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 9079a5df66..487df7f4f6 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -661,14 +661,8 @@ function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silen ob_start(); - if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) { - define( 'WP_SANDBOX_SCRAPING', true ); - } - - wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin ); - $_wp_plugin_file = $plugin; - include_once WP_PLUGIN_DIR . '/' . $plugin; - $plugin = $_wp_plugin_file; // Avoid stomping of the $plugin variable in a plugin. + // Load the plugin to test whether it throws any errors. + plugin_sandbox_scrape( $plugin ); if ( ! $silent ) { /** @@ -732,6 +726,7 @@ function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silen $output = ob_get_clean(); return new WP_Error( 'unexpected_output', __( 'The plugin generated unexpected output.' ), $output ); } + ob_end_clean(); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 4ddd58ec76..d6a6466b9d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-alpha-50786'; +$wp_version = '5.8-alpha-50787'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.