From 93290c44f6d7f8cb931be9374e753b8ff688dd99 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 24 Apr 2021 18:02:39 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@50787 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/plugin.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/wp-admin/includes/plugin.php b/src/wp-admin/includes/plugin.php index 9079a5df66..487df7f4f6 100644 --- a/src/wp-admin/includes/plugin.php +++ b/src/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(); }