5

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!

1
  • 1
    Filter name is active_plugins not option_active_plugins
    – Sumit
    May 8, 2016 at 7:29

1 Answer 1

0

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.

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.