Filter uncanny-automator

automator_pro_actions_conditions_list

Filters the list of available actions and conditions for Automator Pro before they are displayed.

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

Description

Filters the list of available actions and conditions before they are registered. Developers can use this hook to dynamically add, remove, or modify actions and conditions based on certain criteria, allowing for custom automation logic. The hook passes the entire list as an array.


Usage

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

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to add custom conditions to Uncanny Automator Pro.
 * This function will be hooked into the 'automator_pro_actions_conditions_list' filter.
 * It allows developers to register their own custom conditions that can be used in Automator recipes.
 *
 * @param array $conditions The existing list of registered conditions.
 * @return array The modified list of registered conditions with custom ones added.
 */
add_filter( 'automator_pro_actions_conditions_list', function( $conditions ) {

    // Define a custom condition for a hypothetical "User Role Change" integration.
    // This condition checks if a user's role has changed to a specific role.
    $conditions['UserRoleChange'] = array(
        'USERROLECHANGE' => array(
            'name'        => __( 'User role is', 'your-text-domain' ),
            'description' => __( 'Checks if the user has a specific role.', 'your-text-domain' ),
            'template'    => 'select', // Using a 'select' template for role selection.
            'options'     => array(
                // This would typically be populated dynamically, but for this example, we'll use static roles.
                'administrator' => __( 'Administrator', 'your-text-domain' ),
                'editor'        => __( 'Editor', 'your-text-domain' ),
                'author'        => __( 'Author', 'your-text-domain' ),
                'contributor'   => __( 'Contributor', 'your-text-domain' ),
                'subscriber'    => __( 'Subscriber', 'your-text-domain' ),
            ),
            'icon'        => 'user-cog', // Example icon name.
        ),
    );

    // Define another custom condition for a hypothetical "Post Published" integration.
    // This condition checks if a post is published and optionally by a specific author.
    $conditions['PostPublished'] = array(
        'POSTPUBLISHED' => array(
            'name'        => __( 'Post is published', 'your-text-domain' ),
            'description' => __( 'Triggers when a post is published.', 'your-text-domain' ),
            'template'    => 'text', // A simple text input for post title or author ID.
            'options'     => array(
                'post_title' => array(
                    'label' => __( 'Post Title Contains', 'your-text-domain' ),
                    'type'  => 'text',
                ),
                'author_id' => array(
                    'label' => __( 'Published by Author ID', 'your-text-domain' ),
                    'type'  => 'number',
                    'optional' => true, // This field is optional.
                ),
            ),
            'icon'        => 'file-alt', // Example icon name.
        ),
    );

    return $conditions;
}, 10, 1 ); // The priority is 10, and it accepts 1 argument.
?>

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/services/resolver/fields-conditions-resolver.php:420
src/core/services/integrations/structure.php:89
src/core/views/html-admin-status.php:692
src/api/components/condition/registry/class-wp-action-condition-registry.php:227
uncanny-automator-pro/src/core/classes/actions-conditions.php:769

protected function resolve_condition_dynamic_name_from_registry( array $recipe_actions_condition ) {
		$integration_code = isset( $recipe_actions_condition['integration'] ) ? (string) $recipe_actions_condition['integration'] : '';
		$condition_code   = isset( $recipe_actions_condition['condition'] ) ? (string) $recipe_actions_condition['condition'] : '';

		if ( '' === $integration_code || '' === $condition_code ) {
			return '';
		}

		$conditions = (array) apply_filters( 'automator_pro_actions_conditions_list', array() );
		$condition  = $conditions[ $integration_code ][ $condition_code ] ?? null;

		if ( ! is_array( $condition ) ) {
			return '';
		}

		$candidates = array(
			$condition['dynamic_name'] ?? '',
			$condition['name_dynamic'] ?? '',
			$condition['name'] ?? '',
		);

		foreach ( $candidates as $candidate ) {
			if ( ! is_string( $candidate ) ) {
				continue;
			}

			$candidate = trim( $candidate );
			if ( '' !== $candidate ) {
				return $candidate;
			}
		}

		return '';
	}

Internal Usage

Found in uncanny-automator-pro/src/core/classes/action-condition.php:149:

add_filter( 'automator_pro_actions_conditions_list', array( $this, 'register' ) );
Scroll to Top