Filter uncanny-automator-pro

automator_pro_asyc_actions_group

Filters the group for asynchronous actions before they are processed, allowing modification of the action group.

add_filter( 'automator_pro_asyc_actions_group', $callback, 10, 1 );

Description

Allows developers to modify the group name used for asynchronous actions. This filter fires before an asynchronous action is scheduled, enabling customization of how actions are grouped for processing. The default group is 'Uncanny Automator'.


Usage

add_filter( 'automator_pro_asyc_actions_group', 'your_function_name', 10, 1 );

Parameters

$action (mixed)
This parameter defines the group name for asynchronous actions, defaulting to 'Uncanny Automator'.

Return Value

The filtered value.


Examples

/**
 * Example custom function to modify the async action group.
 *
 * This function demonstrates how to hook into 'automator_pro_asyc_actions_group'
 * to prepend a specific prefix to the default group name, potentially for
 * better organization or identification of asynchronous actions within
 * Uncanny Automator.
 *
 * @param string $group The default group name (e.g., 'Uncanny Automator').
 * @param array  $action The current action data array.
 * @return string The modified group name.
 */
function my_custom_automator_async_group( $group, $action ) {
	// Add a custom prefix to the group name for easier filtering or debugging.
	// We can also conditionally change the group based on the action data.
	if ( isset( $action['ID'] ) && $action['ID'] > 1000 ) {
		return 'high_priority_automator_group';
	}
	return 'my_prefix_' . $group;
}
add_filter( 'automator_pro_asyc_actions_group', 'my_custom_automator_async_group', 10, 2 );

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:407
uncanny-automator-pro/src/core/classes/async-actions.php:1636

public function postpone( $action ) {
		$timestamp = $action['action_data']['async']['timestamp'];

		$hook  = 'automator_async_run_with_hash';
		$group = apply_filters( 'automator_pro_asyc_actions_group', 'Uncanny Automator', $action );

		// Because over 8000 throws a fatal error :(. We
		// are saving the hash of the data in options table as a workaround.
		// Prefixed so cleanup can use an indexed LIKE query.
		$hash = 'automator_async_' . md5( wp_json_encode( $action ) );
		// Save the action data in uap_options. Skip action hooks —
		// this is ephemeral storage, no other code needs to react to it.
		automator_add_option( $hash, $action, false, false );

		return as_schedule_single_action( $timestamp, $hook, array( $hash ), $group );
	}

Internal Usage

Found in uncanny-automator-pro/src/core/loops/process-hooks-callbacks.php:68:

add_filter( 'automator_pro_asyc_actions_group', array( $this, 'use_process_id_as_async_group' ), 10, 2 );
Scroll to Top