WordPress.org

Make WordPress Core

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

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

Rework to be more straight forward and check for the right user executed the command.

  • 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..a9db958 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
     221        // Our cookie lasts 10 minutes so if somehow it was set it gets de-activated.
     222        $cookie_to_expire = time() + 600;
     223
     224        // Set a cookie for the user so they have time to de-activate the plugin.
     225        setcookie(
     226                '_wp_dont_load_plugins',
     227
     228                // Store something that makes this unique so it can't be done by somebody else.
     229                md5( $_COOKIE[LOGGED_IN_COOKIE] ),
     230
     231                // Expire time.
     232                $cookie_to_expire
     233        );
     234
     235        // Throw a message if we set this and the cookie was set (first time).
     236        add_action( 'admin_notices', 'wp_plugins_not_loaded_notice' );
     237
     238} elseif(
     239
     240        // If our cookie is set.
     241        isset( $_COOKIE['_wp_dont_load_plugins'] )
     242
     243        // And our login details match (just to make this cookie hard to duplicate).
     244        && $_COOKIE['_wp_dont_load_plugins'] == md5( $_COOKIE[LOGGED_IN_COOKIE] )
     245
     246        // Only for the dashboardDashboard.
     247        && is_admin()
     248
     249        // And we're not trying to turn this off.
     250        && ! isset( $_GET['_wp_load_plugins'] )
     251) {
     252
     253        // Throw a message if the cookie is active.
     254        add_action( 'admin_notices', 'wp_plugins_not_loaded_notice' );
     255
     256} elseif(
     257
     258        // We want to start loading plugins again.
     259        isset( $_GET['_wp_load_plugins'] )
     260
     261        // Activated through the Dashboard.
     262        && is_admin()
     263
     264) {
     265
     266        // Remove the cookie.
     267        setcookie(
     268                '_wp_dont_load_plugins',
     269
     270                // No value
     271                false,
     272
     273                // Expire
     274                time() - 3600
     275        );
     276
     277} else {
     278
     279        // Load active plugins.
     280        foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
     281                wp_register_plugin_realpath( $plugin );
     282                include_once( $plugin );
     283        }
     284
    216285}
    217 unset( $plugin );
    218286
    219287// Load pluggable functions.
    220288require( ABSPATH . WPINC . '/pluggable.php' );