Action
uncanny-automator-pro
add_action_wp_hook
Fires after a specific WordPress hook is executed, providing access to the current action and its arguments.
add_action( 'add_action_wp_hook', $callback, 10, 1 );
Description
Fires after a new action has been registered with the `add_action()` function, providing access to the current action's name and any arguments passed. Developers can use this hook to perform custom logic when actions are added, such as logging or modifying the action's behavior before it's executed.
Usage
add_action( 'add_action_wp_hook', 'your_function_name', 10, 1 );
Parameters
-
$args(mixed) - This parameter represents the name of the currently executing action hook.
Examples
add_action( 'add_action_wp_hook', 'my_custom_action_handler', 10, 2 );
/**
* Handles the 'add_action_wp_hook' action.
*
* This function demonstrates how to hook into the 'add_action_wp_hook'
* action, which is triggered internally by Uncanny Automator Pro when
* an action is being added. It receives the current action's name and
* any arguments passed to it.
*
* @param string $current_action The name of the currently executing action.
* @param array $args An array of arguments passed to the action.
*/
function my_custom_action_handler( $current_action, $args ) {
// For demonstration purposes, let's log when this hook fires
// and what arguments it receives. In a real-world scenario,
// you might perform specific logic based on $current_action or $args.
if ( ! empty( $args ) ) {
// Let's assume the first argument might be a user ID or a post ID
// and we want to do something with it.
$primary_identifier = reset( $args ); // Get the first element without removing it.
// Example: If the primary identifier looks like a user ID, fetch the user.
if ( is_numeric( $primary_identifier ) ) {
$user = get_user_by( 'id', intval( $primary_identifier ) );
if ( $user ) {
error_log( "add_action_wp_hook triggered for action: {$current_action} with primary identifier (user): " . $user->user_login );
} else {
error_log( "add_action_wp_hook triggered for action: {$current_action} with primary identifier (numeric, but not a valid user ID): " . $primary_identifier );
}
} else {
error_log( "add_action_wp_hook triggered for action: {$current_action} with primary identifier (non-numeric): " . $primary_identifier );
}
} else {
error_log( "add_action_wp_hook triggered for action: {$current_action} with no additional arguments." );
}
// This hook is an 'action', so typically you wouldn't return a value
// unless you specifically intended to modify something in the original
// Uncanny Automator Pro code (which is generally not recommended for actions).
// However, if the 'register_listener' function were modified to expect
// a return value, you might do something like:
// return 'Processed successfully';
}
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/integrations/plugin-actions/triggers/run-add-action.php:239
public static function register_listener( ...$args ) {
do_action( 'add_action_wp_hook', current_action(), $args );
if ( ! empty( $args ) ) {
return array_shift( $args );
}
}