WordPress.org

Make WordPress Core

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

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

Just realized I don't have to keep submitting -v2, -v3, sorry. Small modification that only sets the cookie if someone is logged in.

  • 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..d394937 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} elseif(
     242
     243        // If our cookie is set.
     244        isset( $_COOKIE['_wp_dont_load_plugins'] )
     245
     246        // And our login details match (just to make this cookie hard to duplicate).
     247        && $_COOKIE['_wp_dont_load_plugins'] == md5( $_COOKIE[LOGGED_IN_COOKIE] )
     248
     249        // Only for the dashboardDashboard.
     250        && is_admin()
     251
     252        // And we're not trying to turn this off.
     253        && ! isset( $_GET['_wp_load_plugins'] )
     254) {
     255
     256        // Throw a message if the cookie is active.
     257        add_action( 'admin_notices', 'wp_plugins_not_loaded_notice' );
     258
     259} elseif(
     260
     261        // We want to start loading plugins again.
     262        isset( $_GET['_wp_load_plugins'] )
     263
     264        // Activated through the Dashboard.
     265        && is_admin()
     266
     267) {
     268
     269        // Remove the cookie.
     270        setcookie(
     271                '_wp_dont_load_plugins',
     272
     273                // No value
     274                false,
     275
     276                // Expire
     277                time() - 3600
     278        );
     279
     280} else {
     281
     282        // Load active plugins.
     283        foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
     284                wp_register_plugin_realpath( $plugin );
     285                include_once( $plugin );
     286        }
     287
    216288}
    217 unset( $plugin );
    218289
    219290// Load pluggable functions.
    220291require( ABSPATH . WPINC . '/pluggable.php' );