0

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

2 Answers 2

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 ) );
1
  • Thanks for the reply! I was missing the wp_ajax_update_plugin() function. However it wasn't the real culprit. I'm gonna close the question with a self-answer. Thanks again anyway!
    – a-coder
    Aug 5 at 10:26
0

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.