WordPress.org

Make WordPress Core

Ticket #29772: 29772-dontloadplugins-cookie.diff

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

Uses plugins.php?dontloadplugins with a cookie to temporarily skip loading plugins so they can be de-activated.

  • wp-includes/plugin.php

    diff --git a/wp-includes/plugin.php b/wp-includes/plugin.php
    index d616a2a..64cf9a7 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?dontloadplugins 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                                'The below plugins are not being loaded for you so you can maintain them.
     929                                &mdash; <a href="?loadtheplugins">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..3bf41f9 100644
    a b register_theme_directory( get_theme_root() ); 
    212212// Load active plugins.
    213213foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
    214214        wp_register_plugin_realpath( $plugin );
    215         include_once( $plugin );
     215
     216        if(
     217
     218                // Only load plugins if we don't pass plugins.php?dontloadplugins.
     219                ! isset( $_GET['dontloadplugins'] )
     220
     221                // And our 2 minute cookie isn't set.
     222                && ! isset( $_COOKIE['wp_dont_load_plugins'] )
     223
     224                // Or, if we're disabling the cookie, go ahead and load the plugin
     225                // and remove the cookie.
     226                || isset( $_GET['loadtheplugins'] )
     227        ) {
     228
     229                // Make sure our cookie is removed.
     230                if( isset( $_COOKIE['wp_dont_load_plugins'] ) ) {
     231                        setcookie( 'wp_dont_load_plugins', '', time() - 3600 );
     232                }
     233
     234                // Load the plugins.
     235                include_once( $plugin );
     236        } else {
     237
     238                $cookie_to_expire = time() + 120;
     239
     240                // Set a cookie for the user so they have time to de-activate the plugin.
     241                setcookie(
     242                        'wp_dont_load_plugins',
     243
     244                        // Store the time it will expire so we can use that.
     245                        $cookie_to_expire,
     246
     247                        // 2 minutes to de-activate plugins.
     248                        $cookie_to_expire
     249                );
     250
     251                // Throw a message if we don't load plugins.
     252                add_action( 'admin_notices', 'wp_plugins_not_loaded_notice' );
     253        }
    216254}
    217255unset( $plugin );
    218256