Filter uncanny-automator-pro

automator_pro_async_action_custom_date_time

Filters the custom date and time value for asynchronous actions.

add_filter( 'automator_pro_async_action_custom_date_time', $callback, 10, 3 );

Description

Filters the formatted date and time value for asynchronous actions. Developers can modify the custom date/time string, allowing for dynamic date parsing and token manipulation before it's applied to the action. This hook fires after initial token parsing and before the final timestamp generation.


Usage

add_filter( 'automator_pro_async_action_custom_date_time', 'your_function_name', 10, 3 );

Parameters

$custom_value (mixed)
This parameter holds the custom date or time value that has been potentially processed by tokens.
$action (mixed)
This parameter holds the custom date and/or time value that has been processed and potentially contains parsed tokens.
$this (mixed)
This parameter contains information about the specific action being processed, including its data and meta-information.

Return Value

The filtered value.


Examples

add_filter( 'automator_pro_async_action_custom_date_time', 'my_custom_automator_date_time', 10, 3 );

/**
 * Example of how to filter the custom date/time value for an Uncanny Automator Pro async action.
 * This example adjusts the date/time by adding 24 hours if the original value is today.
 *
 * @param mixed $custom_value The original custom date/time value.
 * @param array $action       The action array.
 * @param object $object      The object instance from which the filter is applied (likely an AsyncActions instance).
 * @return mixed              The modified custom date/time value.
 */
function my_custom_automator_date_time( $custom_value, $action, $object ) {
	// Ensure $custom_value is a string and not empty before processing.
	if ( ! is_string( $custom_value ) || empty( $custom_value ) ) {
		return $custom_value;
	}

	// Check if the value is a timestamp representing today.
	// We assume $custom_value is already a timestamp at this point due to prior processing.
	// If it's a timestamp for today, add 24 hours.
	$current_timestamp = time();
	$timestamp_today_start = strtotime( 'today' );
	$timestamp_today_end = strtotime( 'tomorrow' ) - 1;

	if ( $custom_value >= $timestamp_today_start && $custom_value <= $timestamp_today_end ) {
		// Add 24 hours (in seconds) to the timestamp.
		$custom_value = $custom_value + DAY_IN_SECONDS;
	}

	return $custom_value;
}

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/core/classes/async-actions.php:490

public function get_custom_delay( $action ) {

		// Get async custom value
		$custom_value = $action['action_data']['meta']['async_custom'];

		$custom_value = $this->handle_timestamp_tokens( $custom_value );
		// Parse it via token parser
		$custom_value = Automator()->parse->text( $custom_value, $action['recipe_id'], $action['user_id'], $this->args );

		// Generate a timestamp
		$custom_value = $this->parse_date_time_string( $custom_value );

		return apply_filters( 'automator_pro_async_action_custom_date_time', $custom_value, $action, $this );
	}

Scroll to Top