Action uncanny-automator-pro

automator_pro_schedule_trigger_option_updated

Fires when a schedule trigger option is updated for a recipe, providing access to old and new values.

add_action( 'automator_pro_schedule_trigger_option_updated', $callback, 10, 4 );

Description

Fires after a schedule trigger option is updated for a recipe. Developers can use this hook to perform custom actions when schedule trigger settings change, such as logging changes, invalidating caches, or triggering further automation based on the updated value. The hook provides the trigger object, recipe ID, meta key, and the value before the update.


Usage

add_action( 'automator_pro_schedule_trigger_option_updated', 'your_function_name', 10, 4 );

Parameters

$trigger (mixed)
This parameter contains the trigger object from the schedule.
$recipe_id (mixed)
This parameter contains the trigger object that was updated.
$meta_key (mixed)
This parameter contains the ID of the recipe that triggered the update.
$before_update_value (mixed)
This parameter contains the meta key of the option that was updated.

Examples

<?php

/**
 * Example callback function for the automator_pro_schedule_trigger_option_updated hook.
 * This function logs the details of a schedule trigger option update.
 *
 * @param mixed $trigger The schedule trigger object.
 * @param mixed $recipe_id The ID of the recipe associated with the trigger.
 * @param mixed $meta_key The meta key that was updated.
 * @param mixed $before_update_value The value of the meta key before the update.
 */
function my_automator_pro_schedule_trigger_updated( $trigger, $recipe_id, $meta_key, $before_update_value ) {
    // Ensure we have a valid trigger and recipe ID to work with.
    if ( ! $trigger || ! $recipe_id ) {
        error_log( 'automator_pro_schedule_trigger_option_updated called with invalid data.' );
        return;
    }

    // For demonstration purposes, we'll log the update details.
    // In a real scenario, you might trigger other actions, update options, etc.

    // Get the trigger type for logging purposes.
    $trigger_type = ( is_object( $trigger ) && isset( $trigger->get_trigger_type ) ) ? $trigger->get_trigger_type() : 'Unknown Trigger Type';

    // Log the details of the update.
    error_log( sprintf(
        'Uncanny Automator Pro: Schedule trigger option updated for Recipe ID %1$s. Trigger: "%2$s", Meta Key: "%3$s". Value changed from "%4$s".',
        $recipe_id,
        $trigger_type,
        $meta_key,
        print_r( $before_update_value, true ) // Use print_r for complex values
    ) );

    // Example: If a specific meta key is updated, perform a different action.
    if ( 'schedule_date' === $meta_key && is_object( $trigger ) && method_exists( $trigger, 'get_options' ) ) {
        $trigger_options = $trigger->get_options();
        if ( isset( $trigger_options['schedule_date'] ) ) {
            error_log( sprintf(
                'Uncanny Automator Pro: Schedule date updated for Recipe ID %1$s. New date: "%2$s".',
                $recipe_id,
                $trigger_options['schedule_date']
            ) );
            // You could here re-schedule a cron job, send a notification, etc.
        }
    }
}
add_action( 'automator_pro_schedule_trigger_option_updated', 'my_automator_pro_schedule_trigger_updated', 10, 4 );

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/schedule/helpers/schedule-helpers.php:91

public function trigger_recipe_option_updated( $item, $meta_key, $meta_value, $before_update_value, $recipe_id, $return ) {
		if ( ! isset( $return['recipes_object'] ) ) {
			return;
		}

		if ( empty( $return['recipes_object'] ) || ! isset( $return['recipes_object'][ $recipe_id ] ) ) {
			return;
		}

		// If the item is not a trigger, do nothing
		if ( 'uo-trigger' !== $item->post_type ) {
			return;
		}

		// If the trigger is set to draft, do nothing
		if ( 'draft' === $item->post_status ) {
			return;
		}

		// If the recipe is set to draft, do nothing
		if ( 'draft' === get_post_status( $recipe_id ) ) {
			return;
		}

		$recipe_object = $return['recipes_object'][ $recipe_id ];

		if ( false === $this->has_schedule_trigger( $recipe_object ) ) {
			return;
		}

		$trigger = $this->get_schedule_trigger( $recipe_object );

		do_action( 'automator_pro_schedule_trigger_option_updated', $trigger, $recipe_id, $meta_key, $before_update_value );
	}

Internal Usage

Found in uncanny-automator-pro/src/integrations/schedule/triggers/trigger-specific-date.php:25:

add_action( 'automator_pro_schedule_trigger_option_updated', array( $this, 'trigger_option_updated' ), 10, 4 );

Found in uncanny-automator-pro/src/integrations/schedule/triggers/recurring-trigger.php:24:

add_action( 'automator_pro_schedule_trigger_option_updated', array( $this, 'trigger_option_updated' ), 10, 4 );

Found in uncanny-automator-pro/src/integrations/schedule/triggers/recurring-weekday.php:25:

add_action( 'automator_pro_schedule_trigger_option_updated', array( $this, 'trigger_option_updated' ), 10, 4 );
Scroll to Top