TransWikia.com

Disable plugins on cron and ajax page

WordPress Development Asked by Humpty on December 19, 2021

I want to disable few wordpress plugins on my cron and an ajax page. I have already tried option_active_plugins filter but it’s not working. I have checked and found most of the people say that option_active_plugins should work but it doesn’t.

Here is my code:

add_filter('option_active_plugins', 'test');

function test($plugins) {
    file_put_contents(__DIR__ . '/test.txt', var_export($plugins, true));
    return $plugins;
}

Above code should create a file in my theme directory but this filter is not firing.

Please help!

One Answer

I experienced a similar problem with an Ajax request. There are a couple of important things to note.

Allow me to first state the obvious:

Make sure that your code using the option_active_plugins filter is inside your mu-plugins folder. It will not work for if your plugin is a regular plugin. Not even if you name it aaaa-first-plugin.

Now for the problem I faced:

I had written my function like this:

add_filter( 'option_active_plugins', function ( $wp_enabled_plugins ) {

    // Quit immediately if in admin area.
    if ( is_admin() ) {
      return $wp_enabled_plugins;
    }

    // do other stuff

});

The problem is that when doing an AJAX call, is_admin() returns true. So I changed it to:

if ( is_admin() && !DOING_AJAX ) { ... }

Everything works fine for me now. Hope it helps someone.

Answered by Jules on December 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP