Action Since 3.7.0 Added to WP_Upgrader::run(). uncanny-automator-pro

upgrader_process_complete

Fire when the upgrader process is complete. See also {@see 'upgrader_package_options'}. Fires after any WordPress upgrade process has successfully completed, providing details about the update.

add_action( 'upgrader_process_complete', $callback, 10, 2 );

Description

Fires after any WordPress upgrade process (plugin, theme, core, translation) concludes. Developers can use this to perform post-upgrade actions, access upgrade details via `$hook_extra`, or conditionally execute logic based on the upgrade type and success.


Usage

add_action( 'upgrader_process_complete', 'your_function_name', 10, 2 );

Parameters

$this (WP_Upgrader)
WP_Upgrader instance. In other contexts, $this, might be a Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader instance.
$hook_extra (array)
{ Array of bulk item update data. Array of translations update data. 'default' for core translations.

Examples

<?php
/**
 * Example callback function for the 'upgrader_process_complete' action hook.
 *
 * This function logs information about completed update processes,
 * specifically focusing on plugin updates, and potentially triggers
 * other actions based on the update type.
 *
 * @param WP_Upgrader $upgrader The WP_Upgrader instance.
 * @param array       $hook_extra Array of extra data about the update process.
 */
function my_plugin_handle_upgrade_complete( $upgrader, $hook_extra ) {
	// Check if the update was for a plugin.
	if ( isset( $hook_extra['type'] ) && 'plugin' === $hook_extra['type'] ) {

		// Log the completion of a plugin update.
		// In a real scenario, you might want to use a more robust logging mechanism.
		error_log( 'Plugin update process completed.' );

		// If it was a bulk plugin update, iterate through the updated plugins.
		if ( isset( $hook_extra['bulk'] ) && $hook_extra['bulk'] && isset( $hook_extra['plugins'] ) && is_array( $hook_extra['plugins'] ) ) {
			foreach ( $hook_extra['plugins'] as $plugin_file ) {
				// Example: Log each updated plugin's file path.
				error_log( sprintf( 'Updated plugin: %s', $plugin_file ) );

				// Example: Trigger another action for each successful plugin update.
				// You could use this to invalidate caches, clear transient data, etc.
				do_action( 'my_plugin_specific_plugin_updated', $plugin_file, $hook_extra );
			}
		} elseif ( isset( $hook_extra['plugins'] ) && is_array( $hook_extra['plugins'] ) && count( $hook_extra['plugins'] ) === 1 ) {
			// Handle single plugin update if needed.
			$plugin_file = $hook_extra['plugins'][0];
			error_log( sprintf( 'Single plugin updated: %s', $plugin_file ) );
			do_action( 'my_plugin_specific_plugin_updated', $plugin_file, $hook_extra );
		}
	}

	// You could also add logic here to handle theme updates, core updates, or translations.
	if ( isset( $hook_extra['type'] ) && 'theme' === $hook_extra['type'] ) {
		error_log( 'Theme update process completed.' );
		if ( isset( $hook_extra['themes'] ) && is_array( $hook_extra['themes'] ) ) {
			foreach ( $hook_extra['themes'] as $theme_slug ) {
				error_log( sprintf( 'Updated theme: %s', $theme_slug ) );
				do_action( 'my_plugin_specific_theme_updated', $theme_slug, $hook_extra );
			}
		}
	}

	// Handle translation updates if they are included.
	if ( isset( $hook_extra['type'] ) && 'translation' === $hook_extra['type'] ) {
		error_log( 'Translation update process completed.' );
		if ( isset( $hook_extra['translations'] ) && is_array( $hook_extra['translations'] ) ) {
			foreach ( $hook_extra['translations'] as $translation ) {
				if ( is_array( $translation ) ) {
					error_log( sprintf( 'Updated translation for %s (%s) version %s', $translation['slug'], $translation['language'], $translation['version'] ) );
					do_action( 'my_plugin_specific_translation_updated', $translation, $hook_extra );
				}
			}
		}
	}
}

// Hook into the 'upgrader_process_complete' action.
// We specify 10 as the priority (default) and 2 as the number of accepted arguments.
add_action( 'upgrader_process_complete', 'my_plugin_handle_upgrade_complete', 10, 2 );
?>

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

uncanny-automator-pro/src/core/admin/installer/includes/class-upgrader.php:239

*     }
			 * }
			 * @since 4.6.0 `$translations` was added as a possible argument to `$hook_extra`.
			 *
			 * @since 3.6.0
			 * @since 3.7.0 Added to WP_Upgrader::run().
			 */
			do_action( 'upgrader_process_complete', $this, $options['hook_extra'] );

			$this->skin->footer();
		}

		return $result;
	}

Scroll to Top