Action uncanny-automator-pro

automator_pro_magic_link_triggered

Fires automator_pro_magic_button_triggered action when a magic button is triggered. Fires when a Magic Button is triggered, providing saved meta and results for further automation.

add_action( 'automator_pro_magic_link_triggered', $callback, 10, 1 );

Description

Fires when a Magic Link button is successfully triggered by a user. This hook passes `$save_meta` and `$result` arrays, allowing developers to perform custom actions, log activity, or modify data after a Magic Link has been processed by Uncanny Automator Pro.


Usage

add_action( 'automator_pro_magic_link_triggered', 'your_function_name', 10, 1 );

Parameters

$save_meta (array)
- **$result** `array`

Examples

<?php
/**
 * Logs the details of a triggered Uncanny Automator Magic Link to the WordPress debug log.
 *
 * This function hooks into the 'automator_pro_magic_link_triggered' action,
 * which fires when a Magic Link is activated in Uncanny Automator Pro.
 * It then logs the provided metadata and result arrays for debugging purposes.
 *
 * @param array $save_meta An array containing metadata related to the trigger.
 * @param array $result    An array containing the result of the trigger.
 */
add_action( 'automator_pro_magic_link_triggered', function( $save_meta, $result ) {

	// Check if WordPress debugging is enabled.
	if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {

		// Log the $save_meta array.
		if ( ! empty( $save_meta ) ) {
			error_log( 'Uncanny Automator Pro - Magic Link Triggered - Save Meta: ' . print_r( $save_meta, true ) );
		}

		// Log the $result array.
		if ( ! empty( $result ) ) {
			error_log( 'Uncanny Automator Pro - Magic Link Triggered - Result: ' . print_r( $result, true ) );
		}
	}

}, 10, 2 ); // Priority 10, accepts 2 arguments.

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/magic-button/triggers/magic-button-anon-magic-link.php:156
uncanny-automator-pro/src/integrations/magic-button/triggers/magic-button-magic-link.php:175

public function save_anon_data( $trigger_id, $user_id ) {
		$recipe_id = Automator()->get->maybe_get_recipe_id( $trigger_id );

		$args_to_pass = array(
			'code'             => $this->trigger_code,
			'meta'             => $this->trigger_meta,
			'recipe_to_match'  => $recipe_id,
			'trigger_to_match' => $trigger_id,
			'ignore_post_id'   => true,
			'user_id'          => $user_id,
		);
		$results      = Automator()->maybe_add_trigger_entry( $args_to_pass, false );
		// Save trigger meta
		if ( $results ) {
			foreach ( $results as $result ) {
				if ( true === $result['result'] ) {
					$save_meta = array(
						'user_id'        => $user_id,
						'trigger_id'     => $result['args']['trigger_id'],
						'run_number'     => $result['args']['run_number'], //get run number
						'trigger_log_id' => $result['args']['trigger_log_id'],
						'ignore_user_id' => true,
					);

					if ( $user_id != 0 ) {
						$user_data = get_userdata( $user_id );

						$save_meta['meta_key']   = 'email';
						$save_meta['meta_value'] = $user_data->user_email;
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'username';
						$save_meta['meta_value'] = $user_data->user_login;
						Automator()->insert_trigger_meta( $save_meta );

						$save_meta['meta_key']   = 'user_id';
						$save_meta['meta_value'] = $user_data->ID;
						Automator()->insert_trigger_meta( $save_meta );
					}

					if ( automator_filter_has_var( 'automator_button_post_id' ) ) {
						$save_meta['meta_key']   = 'automator_button_post_id';
						$save_meta['meta_value'] = absint( automator_filter_input( 'automator_button_post_id' ) );
						Automator()->insert_trigger_meta( $save_meta );
						$post_data = get_post( absint( automator_filter_input( 'automator_button_post_id' ) ) );
						if ( ! empty( $post_data ) && isset( $post_data->ID ) ) {

							/**
							 * Fires automator_pro_magic_button_triggered action when a magic button is triggered.
							 *
							 * @param array $save_meta
							 * @param array $result
							 *
							 * @return void
							 */
							do_action( 'automator_pro_magic_link_triggered', $save_meta, $result );

							$save_meta['meta_key']   = 'automator_button_post_title';
							$save_meta['meta_value'] = $post_data->post_title;
							Automator()->insert_trigger_meta( $save_meta );

							$save_meta['meta_key']   = 'automator_button_post_url';
							$save_meta['meta_value'] = get_permalink( $post_data->ID );
							Automator()->insert_trigger_meta( $save_meta );
						}
					}
					Automator()->maybe_trigger_complete( $result['args'] );
				}
			}
		}
	}

Scroll to Top