Filter Hook on plugin update

时间:2017-06-15 作者:fightstarr20

是否有一个WordPress钩子可以在任何插件更新时运行函数?

每次更新内容时,我都会尝试使用登录用户IP写入日志文件,以便跟踪活动。

1 个回复
SO网友:hwl

大概upgrader_process_complete() 行动挂钩。

批量升级程序进程完成时激发。

On line 761 of wp-admin/includes/class-wp-upgrader.php

来源:

/**
 * Fires when the upgrader process is complete.
 *
 * See also {@see \'upgrader_package_options\'}.
 *
 * @since 3.6.0
 * @since 3.7.0 Added to WP_Upgrader::run().
 * @since 4.6.0 `$translations` was added as a possible argument to `$hook_extra`.
 *
 * @param WP_Upgrader $this WP_Upgrader instance. In other contexts, $this, might be a
 *                          Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader instance.
 * @param array       $hook_extra {
 *     Array of bulk item update data.
 *
 *     @type string $action       Type of action. Default \'update\'.
 *     @type string $type         Type of update process. Accepts \'plugin\', \'theme\', \'translation\', or \'core\'.
 *     @type bool   $bulk         Whether the update process is a bulk update. Default true.
 *     @type array  $plugins      Array of the basename paths of the plugins\' main files.
 *     @type array  $themes       The theme slugs.
 *     @type array  $translations {
 *         Array of translations update data.
 *
 *         @type string $language The locale the translation is for.
 *         @type string $type     Type of translation. Accepts \'plugin\', \'theme\', or \'core\'.
 *         @type string $slug     Text domain the translation is for. The slug of a theme/plugin or
 *                                \'default\' for core translations.
 *         @type string $version  The version of a theme, plugin, or core.
 *     }
 * }
 */
do_action( \'upgrader_process_complete\', $this, $options[\'hook_extra\'] );
以下仅为codex的示例(注为untested 顺便说一句),我对其进行了编辑,以显示所有插件更新的可能实例:

add_action( \'upgrader_process_complete\', \'my_upgrate_function\',10, 2);

function my_upgrate_function( $upgrader_object, $options ) {


    if ($options[\'action\'] == \'update\' && $options[\'type\'] == \'plugin\' ) {

       foreach($options[\'packages\'] as $each_plugin) {

             // do stuff

       }//end foreach
    }//end if
}//end my_upgrade_function() 

结束

相关推荐

Single必须使用Plugins目录进行本地开发

我有多个本地安装的WordPress,并希望有一个单一的必须使用插件目录为我的所有本地网站。有什么我可以添加到wp配置,例如,让我有一个文件夹,可以用于我的所有网站?或者另一种方法?例如:/根/站点/站点1//根/站点/站点2//根/站点/站点3/。。。所有用途:/根/mu插件/谢谢