Action Dynamic uncanny-automator

automator_after_save_tokens_{dynamic}

> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Fires after tokens are saved for an Events Manager booking, providing access to trigger meta and booking details.

add_action( 'automator_after_save_tokens_{dynamic}', $callback, 10, 3 );

Description

Fires after saving specific Events Manager tokens, dynamically named like `automator_after_save_tokens_booking_id`. Developers can hook into this to perform custom actions or modify saved token data related to the trigger. The `$trigger_meta`, `$trigger_meta_args`, and `$em_booking_obj` parameters provide context about the saved tokens.


Usage

add_action( 'automator_after_save_tokens_{dynamic}', 'your_function_name', 10, 3 );

Parameters

$trigger_meta (mixed)
This parameter contains information related to the trigger that initiated the action.
$trigger_meta_args (mixed)
This parameter holds metadata related to the trigger event that has been saved.
$em_booking_obj (mixed)
This parameter contains additional arguments related to the trigger's metadata.

Examples

/**
 * Example of using the 'automator_after_save_tokens_{dynamic}' action hook.
 *
 * This function demonstrates how to hook into the automator_after_save_tokens_
 * action, specifically when dealing with 'events-manager' tokens related to bookings.
 * It logs the saved trigger meta and booking object for debugging purposes.
 *
 * @param mixed $trigger_meta The base trigger meta key.
 * @param mixed $trigger_meta_args The arguments used for inserting trigger meta.
 * @param mixed $em_booking_obj The Events Manager booking object.
 */
add_action( 'automator_after_save_tokens_EM_BOOKING', function( $trigger_meta, $trigger_meta_args, $em_booking_obj ) {

    // Check if we are dealing with an actual Events Manager booking object.
    if ( ! is_a( $em_booking_obj, 'EM_Booking' ) ) {
        return;
    }

    // For demonstration, let's log the details that were just saved.
    // In a real-world scenario, you might perform other actions like:
    // - Sending a notification if a specific token was saved.
    // - Updating another system based on the booking details.
    // - Performing conditional logic based on the saved meta.

    // Log the trigger meta and arguments.
    error_log( sprintf(
        'automator_after_save_tokens_EM_BOOKING: Trigger Meta: %s, Trigger Meta Args: %s',
        print_r( $trigger_meta, true ),
        print_r( $trigger_meta_args, true )
    ) );

    // Log details from the booking object.
    error_log( sprintf(
        'automator_after_save_tokens_EM_BOOKING: Booking ID: %d, Event ID: %d, User ID: %d',
        $em_booking_obj->booking_id,
        $em_booking_obj->event_id,
        $em_booking_obj->person_id
    ) );

}, 10, 3 ); // Priority 10, accepts 3 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

src/integrations/events-manager/tokens/em-tokens.php:293

$trigger_meta_args['meta_value'] = $location_url;
		Automator()->insert_trigger_meta( $trigger_meta_args );

		$trigger_meta_args['meta_key']   = $trigger_meta . '_LOCATION_LINK_TITLE';
		$trigger_meta_args['meta_value'] = $location_link_text;
		Automator()->insert_trigger_meta( $trigger_meta_args );

		do_action( 'automator_after_save_tokens_' . $trigger_meta, $trigger_meta, $trigger_meta_args, $em_booking_obj );
	}
}

Scroll to Top