1

I am building a 'control panel', for my server and would like to use my Wordpress userbase to control the login functionality, as well as be able to show some posts.

I have set some defines and included wp-load:

define( 'COOKIE_DOMAIN', false );
define( 'DISABLE_WP_CRON', true );
define( 'WP_USE_THEMES', false );
define( 'WP_CACHE', false );
// define( 'SHORTINIT', true );
include( '/home/getyou/www/wp-load.php' );

With shortinit defined, I am able to utilize some of the functionality, however the user functionality fails, without it, I notice my w3 Total Cache is caching everything.

Is there a way I can continue to use all of the wordpress functionality, but possibly unload or disable w3 total cache for this external site?

EDIT

Added a mu-plugin with the following code to disable all plugins based on defining MEDINIT

if ( defined( 'MEDINIT ') && MEDINIT ) {
    add_filter( 'option_active_plugins', function ( $plugins ) {
        $plug_arr = get_plugins();
        foreach( $plug_arr as $k => $v){
            unset( $plugins[$k] );
        }
        return $plugins;
    } );
}

However, when I call var_dump( get_option('active_plugins') ); it still loads all plugins.

1
  • Something strange. When I implement the var_dump in my external file, the W3 Total Cache comment at the bottom of the source code dissappears, but when I get rid of the var_dump it reappears...
    – Kevin
    Commented Oct 18, 2017 at 14:51

1 Answer 1

2

You would need to put something like this in a .php file of any name in your must-use plugins folder (/wp-content/mu-plugins/) so that it loads before all plugins so you can use it to filter the plugin loading...

<?php 
if (defined('SHORTINIT') && SHORTINIT) {
    add_filter('option_active_plugins', 'shortinit_plugins_filter');
    function shortinit_plugins_filter($plugins) {
        $noloadplugins = array('w3-total-cache');
        foreach ($plugins as $i => $plugin) {
             if (in_array($plugin, $noloadplugins)) {unset($plugins[$i]);}
        }
        return $plugins;
    }
}

Alternatively manually include whatever function files you need to make things work as they should.

UPDATE for Multisite

You would need to use a different filter on multisite, something like this should work, eg. for blog ID 2...

<?php 
if (defined('SHORTINIT') && SHORTINIT) {
    add_filter('site_option_active_plugins', 'shortinit_site_plugins_filter', 10, 3);
    function shortinit_site_plugins_filter($plugins, $option, $network_id) {
        if ($network_id == 2) {
            $noloadplugins = array('w3-total-cache');
            foreach ($plugins as $i => $plugin) {
                 if (in_array($plugin, $noloadplugins)) {unset($plugins[$i]);}
            }
        }
        return $plugins;
    }
}

Note if wanted to change sitewide activated plugins you would need to do further filtering of the network wide active plugins, something like:

<?php 
if (defined('SHORTINIT') && SHORTINIT) {
    add_filter('option_active_sitewide_plugins', 'shortinit_network_plugins_filter');
    function shortinit_network_plugins_filter($plugins) {
        if (get_current_blog() == 2) {
            $noloadplugins = array('w3-total-cache');
            foreach ($plugins as $i => $plugin) {
                 if (in_array($plugin, $noloadplugins)) {unset($plugins[$i]);}
            }
        }
        return $plugins;
    }
}
9
  • This also is not working inside a multisite install. I am attempting to utilize it for the second site in it via if get_current_blog_id() == 2, and it still loads and caches everything...
    – Kevin
    Commented Oct 19, 2017 at 20:08
  • 1
    maybe worth including that in your question... I've added some code for multisite, hopefully does the trick.
    – majick
    Commented Oct 20, 2017 at 9:08
  • still showing the w3tc comment at the bottom of the pages, and can confirm that it is indeed still caching
    – Kevin
    Commented Oct 20, 2017 at 15:24
  • just to check is w3 total cache network activated or just active for that site
    – majick
    Commented Oct 21, 2017 at 9:26
  • 1
    ...so it actually looks like there are other filters for get_site_option (then is now get_network_option) so you would need to look at /wp-includes/option.php to see whether you need to use the pre_site_option_{option} or default_site_option_{option} or just site_option_{option} filter for your case
    – majick
    Commented Oct 30, 2017 at 4:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.