Filter uncanny-automator

automator_recipe_part_user_type

Filters the user types available for a recipe part, considering the specific recipe part and integration.

add_filter( 'automator_recipe_part_user_type', $callback, 10, 4 );

Description

Filters the user type for a recipe part, allowing modifications to how users are identified or processed. Useful for dynamically setting user roles or specific user queries based on context. Fires after initial user type determination and before saving to post meta.


Usage

add_filter( 'automator_recipe_part_user_type', 'your_function_name', 10, 4 );

Parameters

$type (mixed)
This parameter specifies the user type that the recipe part is intended for, potentially overriding default behavior.
$post_type (mixed)
This parameter represents the detected or current user type for the recipe part.
$item_code (mixed)
This parameter specifies the post type of the current recipe part, which can be used to determine if it's a loop that iterates over users.
$integration_code (mixed)
This parameter contains a code that identifies the specific type of item or action being processed within the recipe.

Return Value

The filtered value.


Examples

/**
 * Modify the user type for a specific recipe part.
 *
 * This filter allows developers to dynamically change the 'user_type'
 * for a given recipe part based on its context, such as the post type,
 * item code, or integration code.
 *
 * For instance, if the recipe part is related to a specific integration
 * that has its own user role mapping, we could override the default
 * user type to ensure the correct users are targeted.
 *
 * @param mixed  $type             The current user type.
 * @param mixed  $post_type        The post type of the recipe part.
 * @param mixed  $item_code        The unique code for the recipe part item.
 * @param mixed  $integration_code The code of the integration the part belongs to.
 * @return mixed The modified user type.
 */
add_filter( 'automator_recipe_part_user_type', function( $type, $post_type, $item_code, $integration_code ) {
	// Example: If the item code is 'my_custom_user_action' and it's part of
	// the 'my_custom_integration', we want to specifically target users with
	// the 'custom_user_role' role.
	if ( 'my_custom_user_action' === $item_code && 'my_custom_integration' === $integration_code ) {
		// Assuming 'custom_user_role' is a valid user role in WordPress.
		return 'custom_user_role';
	}

	// If no specific override is needed, return the original type.
	return $type;
}, 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

src/core/lib/class-automator-functions.php:2580

if ( AUTOMATOR_POST_TYPE_LOOP === $post_type ) {
				$expression = get_post_meta( $post_id, 'iterable_expression', true );
				if ( isset( $expression['type'] ) && 'users' === $expression['type'] ) {
					$type = $expression['type'];
				}
			}

			$type = apply_filters( 'automator_recipe_part_user_type', $type, $post_type, $item_code, $integration_code );
			update_post_meta( $post_id, 'user_type', $type );
		}
	}

	/**
	 * Retrieves the recipe part config.
	 *


Scroll to Top