Action Since 3.7.0 Added to WP_Upgrader::run(). uncanny-continuing-education-credits

upgrader_process_complete

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

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

Description

Fires after any upgrade process (plugin, theme, core, or translation) completes. Developers can use this to perform actions based on the upgrade type, bulk status, or specific items updated. The hook provides the `WP_Upgrader` instance and extra data about the upgrade.


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

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

/**
 * Handles the completion of an upgrade process (plugin, theme, or core).
 *
 * This function logs the details of the completed upgrade and sends a notification
 * to administrators if a plugin update was successful.
 *
 * @param WP_Upgrader $upgrader The WP_Upgrader instance.
 * @param array       $hook_extra An array of extra data about the upgrade process.
 */
function my_plugin_handle_update_completion( $upgrader, $hook_extra ) {

	// Log the update details for debugging or auditing.
	error_log( 'Upgrade Process Complete:' );
	error_log( print_r( $hook_extra, true ) );

	// Check if the upgrade was for a plugin and was successful.
	if ( 'plugin' === $hook_extra['type'] && 'update' === $hook_extra['action'] && ! empty( $hook_extra['plugins'] ) ) {
		$updated_plugins = $hook_extra['plugins'];

		// Potentially send an email notification to administrators.
		// For this example, we'll just log that an email would be sent.
		foreach ( $updated_plugins as $plugin_basename ) {
			error_log( sprintf( 'Plugin "%s" was successfully updated.', $plugin_basename ) );
			// In a real scenario, you might:
			// wp_mail( get_option( 'admin_email' ), 'Plugin Updated', 'A plugin on your site has been updated.' );
		}
	}

	// If it was a theme update, you could add similar logic.
	if ( 'theme' === $hook_extra['type'] && 'update' === $hook_extra['action'] && ! empty( $hook_extra['themes'] ) ) {
		$updated_themes = $hook_extra['themes'];
		foreach ( $updated_themes as $theme_slug ) {
			error_log( sprintf( 'Theme "%s" was successfully updated.', $theme_slug ) );
		}
	}

	// If it was a core update:
	if ( 'core' === $hook_extra['type'] && 'update' === $hook_extra['action'] ) {
		error_log( 'WordPress core was successfully updated.' );
	}

	// If it was a translation update:
	if ( 'translation' === $hook_extra['type'] && 'update' === $hook_extra['action'] && ! empty( $hook_extra['translations'] ) ) {
		foreach ( $hook_extra['translations'] as $translation_data ) {
			error_log( sprintf( 'Translation for "%s" (%s) was successfully updated.', $translation_data['slug'], $translation_data['language'] ) );
		}
	}
}

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

src/install-automator/vendor/uncanny-one-click-installer/includes/PluginSilentUpgrader.php:240

*     }
			 * }
			 * @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