Action Since 6.7.0 uncanny-automator

automator_trigger_marked_complete

Fires after a trigger has been successfully marked as complete in the database. This hook allows developers to perform additional operations when a trigger is marked complete, such as logging, notifications, or triggering other processes. Fires after a trigger is marked complete, providing IDs for actions like logging or notifications.

add_action( 'automator_trigger_marked_complete', $callback, 10, 5 );

Description

Fires after a trigger is successfully marked as complete in the database. Use this action to perform post-completion tasks like sending notifications, updating custom data, or initiating further automation based on the completed trigger, user, and recipe IDs. It's crucial for extending automation logic and custom event handling.


Usage

add_action( 'automator_trigger_marked_complete', 'your_function_name', 10, 5 );

Parameters

$trigger_id (int)
The trigger ID that was marked complete.
$user_id (int)
The user ID associated with the trigger.
$recipe_id (int)
The recipe ID associated with the trigger.
$recipe_log_id (int|null)
The recipe log ID associated with the trigger.
$trigger_log_id (int|null)
The trigger log ID that was marked complete.

Examples

// Log a detailed message when a trigger is marked as complete, including optional log IDs.
add_action( 'automator_trigger_marked_complete', 'log_automator_trigger_completion', 10, 5 );

function log_automator_trigger_completion( $trigger_id, $user_id, $recipe_id, $recipe_log_id, $trigger_log_id ) {
    $log_message = sprintf(
        'Automator Trigger Marked Complete: Trigger ID %d, User ID %d, Recipe ID %d.',
        $trigger_id,
        $user_id,
        $recipe_id
    );

    if ( $recipe_log_id !== null ) {
        $log_message .= sprintf( ' Recipe Log ID %d.', $recipe_log_id );
    }

    if ( $trigger_log_id !== null ) {
        $log_message .= sprintf( ' Trigger Log ID %d.', $trigger_log_id );
    }

    // Log to the WordPress debug log for system administrators to review.
    error_log( $log_message );

    // Example: If you wanted to update user meta when a specific trigger completes for a user.
    // This is a simplified example; real-world use might involve checking $trigger_id and $recipe_id.
    if ( $trigger_id === 123 && $recipe_id === 456 ) {
        update_user_meta( $user_id, 'automator_trigger_123_completed', true );
    }
}

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/core/lib/utilities/db/class-automator-db-handler-triggers.php:429

public function mark_complete( $trigger_id, $user_id, $recipe_id, $recipe_log_id, $trigger_log_id ) {
		$update = array(
			'completed' => true,
			'date_time' => current_time( 'mysql' ),
		);

		$where = array(
			'user_id'              => $user_id,
			'automator_trigger_id' => $trigger_id,
			'automator_recipe_id'  => $recipe_id,
		);

		$update_format = array(
			'%d',
			'%s',
		);

		$where_format = array(
			'%d',
			'%d',
			'%d',
		);

		if ( null !== $trigger_log_id && is_int( $trigger_log_id ) ) {
			$where['ID']    = absint( $trigger_log_id );
			$where_format[] = '%d';
		}

		if ( null !== $recipe_log_id && is_int( $recipe_log_id ) ) {
			$where['automator_recipe_log_id'] = absint( $recipe_log_id );
			$where_format[]                   = '%d';
		}

		$updated = $this->update( $update, $where, $update_format, $where_format );

		if ( $updated ) {
			/**
			 * Fires after a trigger has been successfully marked as complete in the database.
			 *
			 * This hook allows developers to perform additional operations when a trigger
			 * is marked complete, such as logging, notifications, or triggering other processes.
			 *
			 * @since 6.7.0
			 *
			 * @param int      $trigger_id     The trigger ID that was marked complete.
			 * @param int      $user_id        The user ID associated with the trigger.
			 * @param int      $recipe_id      The recipe ID associated with the trigger.
			 * @param int|null $recipe_log_id  The recipe log ID associated with the trigger.
			 * @param int|null $trigger_log_id The trigger log ID that was marked complete.
			 *
			 * @example
			 * // Hook into the trigger completion event
			 * add_action( 'automator_trigger_marked_complete', 'my_custom_trigger_complete_handler', 10, 5 );
			 *
			 * function my_custom_trigger_complete_handler( $trigger_id, $user_id, $recipe_id, $recipe_log_id, $trigger_log_id ) {
			 *     error_log( "Trigger {$trigger_id} completed for user {$user_id} in recipe {$recipe_id}" );
			 * }
			 */
			do_action( 'automator_trigger_marked_complete', $trigger_id, $user_id, $recipe_id, $recipe_log_id, $trigger_log_id );
		}

		return $updated;
	}

Internal Usage

Found in src/core/lib/utilities/db/class-automator-db-handler-triggers.php:423:

* add_action( 'automator_trigger_marked_complete', 'my_custom_trigger_complete_handler', 10, 5 );
Scroll to Top