WordPress.org

Make WordPress Core

Ticket #29772: 29772-dontloadplugins-cookie-v3.3.diff

File 29772-dontloadplugins-cookie-v3.3.diff, 3.1 KB (added by aubreypwd, 5 years ago)

Re-added unset($plugin)

  • wp-includes/plugin.php

    diff --git a/wp-includes/plugin.php b/wp-includes/plugin.php
    index d616a2a..48592d7 100644
    a b function _wp_filter_build_unique_id($tag, $function, $priority) { 
    918918                return $function[0] . '::' . $function[1];
    919919        }
    920920}
     921
     922// If we use plugins.php?_wp_dont_load_plugins when loading plugins.php,
     923// let them know plugins haven't been loaded and help them load them up again.
     924function wp_plugins_not_loaded_notice() {
     925        ?>
     926                <div class="error">
     927                        <p><?php _e(
     928                                'Plugins are not being loaded so you can maintain them.
     929                                &mdash; <a href="?_wp_load_plugins">I\'m done, load the plugins.</a>'
     930                        ); ?></p>
     931                </div>
     932        <?php
     933}
  • wp-settings.php

    diff --git a/wp-settings.php b/wp-settings.php
    index 9795971..f7159b0 100644
    a b create_initial_post_types(); 
    209209// Register the default theme directory root
    210210register_theme_directory( get_theme_root() );
    211211
    212 // Load active plugins.
    213 foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
    214         wp_register_plugin_realpath( $plugin );
    215         include_once( $plugin );
     212if(
     213
     214        // If we're deliberatly trying to bypass loading plugins
     215        isset( $_GET['_wp_dont_load_plugins'] )
     216
     217        // Through the Dashboard
     218        && is_admin()
     219
     220        // And a user is logged in (no use setting if a user isn't logged in)
     221        && isset( $_COOKIE[LOGGED_IN_COOKIE] )
     222) {
     223
     224        // Our cookie lasts 10 minutes so if somehow it was set it gets de-activated.
     225        $cookie_to_expire = time() + 600;
     226
     227        // Set a cookie for the user so they have time to de-activate the plugin.
     228        setcookie(
     229                '_wp_dont_load_plugins',
     230
     231                // Store something that makes this unique so it can't be done by somebody else.
     232                md5( $_COOKIE[LOGGED_IN_COOKIE] ),
     233
     234                // Expire time.
     235                $cookie_to_expire
     236        );
     237
     238        // Throw a message if we set this and the cookie was set (first time).
     239        add_action( 'admin_notices', 'wp_plugins_not_loaded_notice' );
     240
     241        // Don't load plugins...
     242
     243} elseif(
     244
     245        // If our cookie is set.
     246        isset( $_COOKIE['_wp_dont_load_plugins'] )
     247
     248        // And our login details match (just to make this cookie hard to duplicate).
     249        && $_COOKIE['_wp_dont_load_plugins'] == md5( $_COOKIE[LOGGED_IN_COOKIE] )
     250
     251        // Only for the Dashboards.
     252        && is_admin()
     253
     254        // And we're not trying to turn this off.
     255        && ! isset( $_GET['_wp_load_plugins'] )
     256) {
     257
     258        // Throw a message if the cookie is active.
     259        add_action( 'admin_notices', 'wp_plugins_not_loaded_notice' );
     260
     261        // Don't load plugins...
     262
     263} elseif(
     264
     265        // We want to start loading plugins again.
     266        isset( $_GET['_wp_load_plugins'] )
     267
     268        // Activated through the Dashboard.
     269        && is_admin()
     270
     271) {
     272
     273        // Remove the cookie.
     274        setcookie(
     275                '_wp_dont_load_plugins',
     276
     277                // No value
     278                false,
     279
     280                // Expire
     281                time() - 3600
     282        );
     283
     284        // Don't load plugins...
     285
     286} else {
     287
     288        // Load active plugins.
     289        foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
     290                wp_register_plugin_realpath( $plugin );
     291                include_once( $plugin );
     292        }
     293
     294        unset( $plugin );
     295
    216296}
    217 unset( $plugin );
    218297
    219298// Load pluggable functions.
    220299require( ABSPATH . WPINC . '/pluggable.php' );