我试图触发一些内部更新类时,WP是自动的。对于手动更新(单击update时),我找到了一种方法,它被很好地记录下来,我使用钩子
add_action( 'uprader_process_complete', 'my_update_function', 10, 2)
但是,当使用
add_action( 'automatic_updates_complete', 'my_update_function', 10, 1)没有被执行。
有没有人在wordpress插件中使用更新功能?文件是相当稀少的。
发布于 2022-11-17 19:43:45
我找到了一个解决办法:
function my_function_to_run_on_autoupdate(array $results ): void {
// Iterate through the plugins being updated and check if ours is there.
foreach ( $results['plugin'] as $plugin ) {
if (
isset( $plugin->item->slug )
&& strlen( $plugin->item->slug ) > 0
// 'your-plugin-slug' is usually the folder name of your plugin
&& $plugin->item->slug === 'your-plugin-slug'
) {
// Run whatever you want to run
}
}
}这将在每次插件自动更新时执行.如果它找到您的插件," If“中的代码将被执行。
https://wordpress.stackexchange.com/questions/411313
复制相似问题