upgrader_post_install
Filter the installation response after the installation has finished. Filters the installation response after an update or plugin installation completes, providing access to results and extra data.
add_filter( 'upgrader_post_install', $callback, 10, 3 );
Description
Fires after a plugin or theme installation completes. Developers can filter the installation `$response` (true/false or WP_Error) to indicate success or failure. `$hook_extra` provides context, and `$result` contains detailed installation data. Use this to perform custom actions or modify installation outcomes.
Usage
add_filter( 'upgrader_post_install', 'your_function_name', 10, 3 );
Parameters
-
$response(bool) - Installation response.
-
$hook_extra(array) - Extra arguments passed to hooked filters.
-
$result(array) - Installation result data.
Return Value
The filtered value.
Examples
<?php
/**
* Example: Log successful plugin installations and potentially modify the response.
*
* This filter hook is triggered after a plugin has been successfully installed or updated.
* We can use it to perform custom actions like logging, sending notifications, or
* even slightly altering the success response if needed.
*/
add_filter(
'upgrader_post_install',
function ( $response, $hook_extra, $result ) {
// Check if the installation was successful. $response typically indicates success/failure.
// The $result array contains more detailed information about the upgrade.
if ( $response && is_array( $result ) && isset( $result['plugin'] ) ) {
// Log the successful installation for debugging or auditing purposes.
// In a real-world scenario, you might use a more sophisticated logging mechanism.
error_log(
sprintf(
'Plugin installed/updated successfully: %s. Version: %s',
$result['plugin'],
$result['version']
)
);
// Example: If a specific plugin was installed, you might want to trigger
// a custom action or modify the response slightly.
if ( 'my-special-plugin/my-special-plugin.php' === $result['plugin'] ) {
// Let's say we want to add a custom success message to the result
// if this specific plugin was installed.
// Note: Modifying $result directly might not be what you want,
// and returning a modified $response is often safer.
// For this example, we'll just demonstrate logging.
}
// If you wanted to modify the response itself, you could return a different boolean or an error.
// For example, to simulate a failure after a successful installation for testing:
// if ( 'some-plugin/some-plugin.php' === $result['plugin'] ) {
// return new WP_Error( 'custom_upgrade_error', 'Something went wrong after installing some-plugin.' );
// }
// Crucially, for filters, you must return a value.
// If we don't want to alter the original response, we return it.
return $response;
}
// If the installation wasn't successful, or if the result is not as expected,
// we should return the original $response.
return $response;
},
10, // Priority: Default priority.
3 // Accepted arguments: The number of arguments our callback function accepts.
);
?>
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:559
* @param bool $response Installation response.
* @param array $hook_extra Extra arguments passed to hooked filters.
* @param array $result Installation result data.
*
* @since 2.8.0
*
*/
$res = apply_filters( 'upgrader_post_install', true, $args['hook_extra'], $this->result );
if ( is_wp_error( $res ) ) {
$this->result = $res;
return $res;
}