我正在编写一个Wordpress插件,用于为各个插件设置自动更新。我无法验证“auto\\u update\\u plugin”筛选器是否正常工作。我在回调函数中输入的任何内容都不会返回任何结果。就像从未调用过函数一样。
过滤器:
add_filter( \'auto_update_plugin\', array( $this, \'l7wau_auto_update_specific_plugins\' ), 10, 2 );
回调函数:
/**
* Update specific plugins. Got this from Wordpress codex.
*/
function l7wau_auto_update_specific_plugins( $update, $item ) {
// Array for adding the path to file. Use for 3.8.1 and below.
$new_plugin_array = array();
$this->plugin_slug = \'changed\'; //Test to see if it is working. Nothing here.
/**
* Get the array of names/slugs to set to auto-update
* Added the folder/file.php because the actual slug is not
* the file name. It is the plugin folder and file with header use for 3.8.1 and below.
*/
$plugins = $this->l7wau_get_array_plugins_to_update();
if ( in_array( $item->slug, $plugins ) ) {
return true; // Always update plugins in this array
} else {
return $update; // Else, use the normal API response to decide whether to update or not
}
}
最合适的回答,由SO网友:Jeff Mattson 整理而成
事实证明,上述方法确实有效。自动更新周期只需12小时。我所做的改变是10到20的重要性数字。
add_filter( \'auto_update_plugin\', array( $this, \'l7wau_auto_update_specific_plugins\' ), 20, 2 );