Make WordPress Core

Changeset 50787


Ignore:
Timestamp:
04/24/2021 06:02:39 PM (4 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/plugin.php

    r50522 r50787  
    662662        ob_start();
    663663
    664         if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
    665             define( 'WP_SANDBOX_SCRAPING', true );
    666         }
    667 
    668         wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
    669         $_wp_plugin_file = $plugin;
    670         include_once WP_PLUGIN_DIR . '/' . $plugin;
    671         $plugin = $_wp_plugin_file; // Avoid stomping of the $plugin variable in a plugin.
     664        // Load the plugin to test whether it throws any errors.
     665        plugin_sandbox_scrape( $plugin );
    672666
    673667        if ( ! $silent ) {
     
    733727            return new WP_Error( 'unexpected_output', __( 'The plugin generated unexpected output.' ), $output );
    734728        }
     729
    735730        ob_end_clean();
    736731    }
Note: See TracChangeset for help on using the changeset viewer.