WordPress.org

Make WordPress Core

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

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

Re-worked so it doesn't loop through foreach. Also message is Admin-wide so it refers to 'Plugins' not 'Plugins below'.

  • wp-includes/plugin.php

    diff --git a/wp-includes/plugin.php b/wp-includes/plugin.php
    index d616a2a..b80e2e8 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                                'Plugins are not being loaded 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..d47fbd4 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 );
     212
     213// Load active plugins if we aren't trying to stop them from loading.
     214if(
     215
     216        // Only load plugins if we don't pass plugins.php?dontloadplugins.
     217        ! isset( $_GET['dontloadplugins'] )
     218
     219        // And our 2 minute cookie isn't set.
     220        && ! isset( $_COOKIE['wp_dont_load_plugins'] )
     221
     222        // Or, if we're disabling the cookie, go ahead and load the plugin
     223        // and remove the cookie.
     224        || isset( $_GET['loadtheplugins'] )
     225) {
     226
     227        // Make sure our cookie is removed.
     228        if( isset( $_COOKIE['wp_dont_load_plugins'] ) ) {
     229                setcookie( 'wp_dont_load_plugins', '', time() - 3600 );
     230        }
     231
     232        // Load active plugins.
     233        foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
     234                wp_register_plugin_realpath( $plugin );
     235                include_once( $plugin );
     236        }
     237        unset( $plugin );
     238
     239} else {
     240
     241        // Our cookie lasts 10 minutes and re-activates the plugins.
     242        $cookie_to_expire = time() + 600;
     243
     244        // Set a cookie for the user so they have time to de-activate the plugin.
     245        setcookie(
     246                'wp_dont_load_plugins',
     247
     248                // Store the time it will expire so we can use that.
     249                $cookie_to_expire,
     250
     251                // Expire time.
     252                $cookie_to_expire
     253        );
     254
     255        // Throw a message if we don't load plugins.
     256        add_action( 'admin_notices', 'wp_plugins_not_loaded_notice' );
    216257}
    217 unset( $plugin );
    218258
    219259// Load pluggable functions.
    220260require( ABSPATH . WPINC . '/pluggable.php' );