Filter uncanny-automator-pro

ua_acf_field_meta_value

Filters the meta value retrieved for an Advanced Custom Fields field before it is returned to the user.

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

Description

Allows modification of an ACF field's meta value before it's used in Uncanny Automator triggers. Useful for transforming complex field types (like images or arrays) into a string format suitable for trigger conditions. Handles image URL retrieval and array-to-string conversion.


Usage

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

Parameters

$meta_value (mixed)
This parameter contains the meta value retrieved from the post or user meta data, which may be modified based on the field type, such as converting an attachment ID to its URL for image fields.

Return Value

The filtered value.


Examples

/**
 * Example filter to modify the meta value for the 'ua_acf_field_meta_value' hook.
 * This example specifically targets fields of type 'text' or 'textarea'
 * and trims any leading/trailing whitespace from the meta value.
 *
 * @param mixed $meta_value The original meta value retrieved from ACF.
 * @return mixed The modified meta value.
 */
add_filter( 'ua_acf_field_meta_value', function( $meta_value ) {
	// Assuming $field_object is available in the context where this filter is applied.
	// In a real scenario, you might need to pass $field_object as an argument
	// if the hook's context doesn't inherently provide it.
	// For this example, we'll simulate checking the field type.

	// In the actual Uncanny Automator Pro source, $field_object is available.
	// Let's assume for this example that we have access to it.
	// If not, you would need to check if $meta_value is already processed
	// or find another way to determine the field type if it's crucial.

	// Hypothetical check for field type. In the real Uncanny Automator code,
	// this check would be based on the $field_object.
	// For demonstration, let's assume the meta_value comes from a text/textarea field.
	// You would replace this logic with actual checks if you need to be specific.

	if ( is_string( $meta_value ) ) {
		// Trim whitespace for text and textarea fields
		$meta_value = trim( $meta_value );
	}

	// You could add other conditional logic here based on field types or values.
	// For instance, if you wanted to URL-encode values for a specific field:
	// if ( 'url' === $field_object['type'] ) {
	//     $meta_value = urlencode( $meta_value );
	// }

	return $meta_value;
}, 10, 1 ); // 10 is the priority, 1 is the number of accepted arguments.

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/acf/triggers/acf-post-field-updated.php:290
uncanny-automator-pro/src/integrations/acf/triggers/acf-user-post-field-updated.php:323

// Added support for image type.
						if ( 'image' === $field_object['type'] ) {
							$meta_value = wp_get_attachment_url( $meta_value );
						}

						// Check if meta value is array convert to string separated by comma.
						if ( is_array( $meta_value ) ) {
							$meta_value = apply_filters( 'ua_acf_field_meta_value', implode( ', ', $meta_value ) );
						}

						// Added support for true or false.
						if ( 'true_false' === $field_object['type'] ) {
							$values     = array( 'False', 'True' );
							$meta_value = $values[ $meta_value ];
						}

Scroll to Top