Filter Since 7.0 uncanny-automator

automator_field_value_processed

Filters the processed field value before it's added to config. Allows third-party plugins and internal code to customize value processing for specific transports or use cases. Useful for populating values from WordPress database or applying custom transformations. Filters the processed field value before it's added to configuration, allowing customization for specific transports or use cases.

add_filter( 'automator_field_value_processed', $callback, 10, 5 );

Description

Fires after a field value has been processed and sanitized but before it's added to the configuration. Developers can use this filter to modify the processed value based on field type, transport, or other contextual data. This is ideal for dynamic value population, applying custom formatting, or ensuring data integrity before it's used in an API integration.


Usage

add_filter( 'automator_field_value_processed', 'your_function_name', 10, 5 );

Parameters

$value (mixed)
The processed value.
$type (string)
The field type.
$transport (string)
The transport identifier (e.g., 'rest', 'mcp').
$field (Field)
The field object.
$field_code (string)
The field code.

Return Value

The filtered value.


Examples

// Hook into the automator_field_value_processed filter to modify a specific field's value.
// This example targets a field with the code 'user_email' and the type 'text'.
// If the value is not empty, it will prepend 'processed_' to it.
add_filter(
	'automator_field_value_processed',
	function ( $value, $type, $transport, $field, $field_code ) {
		// Check if this is the specific field and type we want to modify.
		if ( 'user_email' === $field_code && 'text' === $type ) {
			// Ensure the value is not empty before attempting to prepend.
			if ( ! empty( $value ) && is_string( $value ) ) {
				// Prepend a string to the value.
				return 'processed_' . $value;
			}
		}

		// If it's not the field we're looking for, or if the value is empty, return the original value.
		return $value;
	},
	10, // Priority: 10 is the default, adjust if needed.
	5  // Accepted args: The filter passes 5 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

src/api/services/field/class-field-sanitizer.php:187

public function process_value( Field $field, string $transport ) {
		$value = $this->sanitize_value( $field, $transport );

		$field_type = $field->get_type();
		$type_value = $field_type->get_value();

		// Repeater fields need JSON encoding if they're arrays.
		if ( Field_Types::REPEATER === $type_value && is_array( $value ) ) {
			$value = wp_json_encode( $value );
		}

		// Slash JSON values for proper database storage.
		// update_post_meta() calls wp_unslash(), so we need to pre-slash JSON.
		if ( is_string( $value ) && $this->is_json_string( $value ) ) {
			$value = wp_slash( $value );
		}

		$field_code = $field->get_code();

		/**
		 * Filters the processed field value before it's added to config.
		 *
		 * Allows third-party plugins and internal code to customize
		 * value processing for specific transports or use cases.
		 * Useful for populating values from WordPress database or
		 * applying custom transformations.
		 *
		 * @since 7.0
		 *
		 * @param mixed  $value      The processed value.
		 * @param string $type       The field type.
		 * @param string $transport  The transport identifier (e.g., 'rest', 'mcp').
		 * @param Field  $field      The field object.
		 * @param string $field_code The field code.
		 */
		$value = apply_filters(
			'automator_field_value_processed',
			$value,
			$type_value,
			$transport,
			$field,
			$field_code
		);

		/**
		 * Filters the processed value for a specific field code.
		 *
		 * Dynamic hook that allows field-code-specific processing modifications.
		 * Follows WordPress pattern (e.g., pre_update_option_{$option}).
		 *
		 * @since 7.0
		 *
		 * @param mixed  $value     The processed value.
		 * @param string $type      The field type.
		 * @param string $transport The transport identifier (e.g., 'rest', 'mcp').
		 * @param Field  $field     The field object.
		 */
		return apply_filters(
			"automator_field_value_processed_{$field_code}",
			$value,
			$type_value,
			$transport,
			$field
		);
	}


Scroll to Top