auto_plugin_install-plugin_installed
Fires after a plugin is successfully installed via the auto-plugin-install functionality, passing package and namespace details.
add_action( 'auto_plugin_install-plugin_installed', $callback, 10, 1 );
Description
Fires after a plugin is successfully installed via the automator. Developers can use this hook to perform custom actions, such as updating settings, sending notifications, or triggering other automations, immediately following a plugin installation. The hook passes the plugin's package details and the current namespace.
Usage
add_action( 'auto_plugin_install-plugin_installed', 'your_function_name', 10, 1 );
Parameters
-
$package(mixed) - The `$package` parameter contains information about the plugin that has just been installed.
Examples
/**
* Log the successful installation of a plugin.
*
* This function is hooked into the 'auto_plugin_install-plugin_installed' action
* to record information about the plugin that was just installed.
*
* @param object $package The plugin package details.
* @param string $namespace The namespace of the installer.
*/
function my_plugin_installation_logger( $package, $namespace ) {
// Ensure the package object has a 'slug' or 'name' to identify the plugin.
$plugin_slug = '';
if ( isset( $package->slug ) && ! empty( $package->slug ) ) {
$plugin_slug = $package->slug;
} elseif ( isset( $package->name ) && ! empty( $package->name ) ) {
$plugin_slug = $package->name;
}
// Avoid logging if we couldn't identify the plugin.
if ( empty( $plugin_slug ) ) {
error_log( 'auto_plugin_install-plugin_installed: Could not identify plugin slug.' );
return;
}
// In a real-world scenario, you might log this to a custom database table,
// a file, or send it to an external analytics service.
// For this example, we'll use WordPress's error_log.
$log_message = sprintf(
'Plugin "%s" installed successfully via Uncanny One-Click Installer (Namespace: %s).',
esc_html( $plugin_slug ),
esc_html( $namespace )
);
error_log( $log_message );
// You could also potentially perform other actions here, like:
// - Triggering a welcome notice for the newly installed plugin.
// - Updating a custom option in the database.
// - Sending a notification to an administrator.
}
add_action( 'auto_plugin_install-plugin_installed', 'my_plugin_installation_logger', 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
src/install-automator/vendor/uncanny-one-click-installer/includes/PluginSilentUpgrader.php:610
public function install( $package, $args = array() ) {
$result = parent::install( $package, $args );
if ( true === $result ) {
do_action( 'auto_plugin_install-plugin_installed', $package, __NAMESPACE__ );
}
return $result;
}