最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

themes - Disable plugins on cron and ajax page

programmeradmin7浏览0评论

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!

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!

Share Improve this question asked May 8, 2016 at 0:11 HumptyHumpty 511 bronze badge 1
  • 1 Filter name is active_plugins not option_active_plugins – Sumit Commented May 8, 2016 at 7:29
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论