admin管理员组

文章数量:1297182

a very specific question about upgrader_process_complete filter (but also upgrader_post_install). I must call some functions whenever specific themes/plugins are updated.

The code works perfectly when plugins/themes are updated through the WP update-core.php admin page, while they are not if plugins/themes are updated respectively from plugins/themes list page, through ajax.

Do you have any hint of the reason why? Or how can I hook into the ajax updater process? thanks

a very specific question about upgrader_process_complete filter (but also upgrader_post_install). I must call some functions whenever specific themes/plugins are updated.

The code works perfectly when plugins/themes are updated through the WP update-core.php admin page, while they are not if plugins/themes are updated respectively from plugins/themes list page, through ajax.

Do you have any hint of the reason why? Or how can I hook into the ajax updater process? thanks

Share Improve this question edited Aug 5, 2022 at 12:48 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Aug 5, 2022 at 9:21 a-codera-coder 4001 gold badge3 silver badges10 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

There's two thing that relates to this concern.

  1. The upgrader_process_complete action doesn't fire when the updater is running in bulk mode, aka multiple plugin updates. ref: https://core.trac.wordpress.org/browser/tags/6.0/src/wp-admin/includes/class-wp-upgrader.php#L826
// @see https://core.trac.wordpress.org/browser/tags/6.0/src/wp-admin/includes/class-wp-upgrader.php#L826
// @line 826 - 841.

if ( ! $options['is_multi'] ) {
   do_action( 'upgrader_process_complete', $this, $options['hook_extra'] );
}
  1. The wp_ajax_update_plugin function, which is responsible for handing the ajax request performs the each plugin upgrade in bulk mode. ref: https://core.trac.wordpress.org/browser/tags/6.0/src/wp-admin/includes/ajax-actions.php#L4547
// @see https://core.trac.wordpress.org/browser/tags/6.0/src/wp-admin/includes/ajax-actions.php#L4547
// Line 4545 - 4547.

$skin     = new WP_Ajax_Upgrader_Skin();
$upgrader = new Plugin_Upgrader( $skin );
$result   = $upgrader->bulk_upgrade( array( $plugin ) );

Having explored the whole WP codex, I was missing a major point above all the rest: hooks priorities!

upgrader_process_complete, upgrader_post_install, (etc) hooks must be registered through an hook called also through WP ajax operations (eg. admin_init).

I was mistakenly registering those filters on "admin_menu". Everything solved then!

本文标签: hooksupgraderprocesscomplete filter not fired using ajax updates