Action uncanny-automator

automator_event_{$event_name}

Fires after an AutomatorWP API event is triggered, passing event data for customization.

add_action( 'automator_event_{$event_name}', $callback, 10, 1 );

Description

Fired after an API event is processed, this hook allows developers to perform custom actions based on the specific event. Listeners receive the event data as a parameter, enabling dynamic responses and integrations. Use this hook to extend API functionality with custom logic.


Usage

add_action( 'automator_event_{$event_name}', 'your_function_name', 10, 1 );

Parameters

$data (mixed)
This parameter contains the data associated with the specific event that has been triggered.

Examples

// Example: Hook into the 'automator_event_user_registered' action to send a welcome email.
// We expect one argument: the $data object which is of type Event_Dto.
add_action( 'automator_event_user_registered', function ( $event_data ) {
	// Check if the $event_data is indeed an instance of Event_Dto and has the expected structure.
	if ( $event_data instanceof You_Are_Using_A_Placeholder_NamespaceEvent_Dto && isset( $event_data->payload['user_id'] ) ) {
		$user_id = $event_data->payload['user_id'];
		$user = get_user_by( 'id', $user_id );

		if ( $user instanceof WP_User ) {
			// In a real scenario, you would integrate with an email sending service or use wp_mail().
			// For this example, we'll just log that the welcome email would be sent.
			error_log( "Automator: Sending welcome email to user ID: " . $user_id . " (Email: " . $user->user_email . ")" );

			// Example of sending a welcome email using wp_mail()
			/*
			$to = $user->user_email;
			$subject = 'Welcome to Our Awesome Platform!';
			$message = 'Hi ' . $user->display_name . ",nnWelcome aboard! We're thrilled to have you.nnBest regards,nYour Team";
			$headers = array('Content-Type: text/plain; charset=UTF-8');

			wp_mail( $to, $subject, $message, $headers );
			*/
		}
	}
}, 10, 1 ); // Priority 10, accepts 1 argument.

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/api/events/class-dispatcher.php:25

public static function dispatch( string $event_name, ?Event_Dto $data = null ): void {
		do_action( "automator_event_{$event_name}", $data );
	}

Scroll to Top