2017-01-09 203 views

回答

0

我遇到了同样的问题,并深入代码揭示了原因。

Automatic_Upgrader使用Plugin_Upgrader来更新插件。插件升级程序有一个方法,deactivate_plugin_before_upgrade(),用于在升级之前停用插件,但仅限于特定情况。它包含以下行:

// When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it 
    if (wp_doing_cron()) 
     return $return; 

因此,当更新由cron作业运行时,插件不会停用。自动更新通常是通过cron运行的,所以代码已经假设他们总是会这样做。如果自动更新在cron之外被触发(例如手动调用wp_maybe_auto_update(),则插件将被禁用,但它们不会自动重新激活)

一种解决方案是欺骗升级器,使其认为cron在拨打电话wp_maybe_auto_update()之前,通过挂接'wp_doing_cron'筛选器运行:

add_filter('wp_doing_cron', '__return_true'); 
wp_maybe_auto_update(); 
remove_filter('wp_doing_cron', '__return_true'); 
相关问题