0

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.

  • 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 Oct 18 '17 at 14:51
1

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;
    }
}
  • 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 Oct 19 '17 at 20:08
  • 1
    maybe worth including that in your question... I've added some code for multisite, hopefully does the trick. – majick Oct 20 '17 at 9:08
  • still showing the w3tc comment at the bottom of the pages, and can confirm that it is indeed still caching – Kevin Oct 20 '17 at 15:24
  • just to check is w3 total cache network activated or just active for that site – majick Oct 21 '17 at 9:26
  • hey @majick unfortunately W3 Total Cache is Network Activate only. Screenshot: prntscr.com/h0jugq Was going to go with Super Cache, but too many errors with the plugin in multi-site and activating on single site alone. – Kevin Oct 22 '17 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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