Filter Since 7.0 uncanny-automator

automator_field_value_processed_{$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}). Filters the processed value after it has been prepared for an API field, allowing for field-specific modifications.

add_filter( 'automator_field_value_processed_{$field_code}', $callback, 10, 4 );

Description

Fires after a specific field's value has been processed but before it's returned for API usage. Developers can use this hook to further modify, sanitize, or augment the field value based on its code, type, transport, or full field object. This allows for field-specific data manipulation before it's sent or consumed via the API.


Usage

add_filter( 'automator_field_value_processed_{$field_code}', 'your_function_name', 10, 4 );

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.

Return Value

The filtered value.


Examples

<?php
/**
 * Example: Modify a specific field's processed value before it's used.
 *
 * This example demonstrates how to intercept the processed value of a field
 * with the code 'user_email' and append a specific string to it if it's
 * being processed for the 'rest' transport.
 *
 * @param mixed  $value     The processed value.
 * @param string $type      The field type.
 * @param string $transport The transport identifier (e.g., 'rest', 'mcp').
 * @param object $field     The field object.
 *
 * @return mixed The modified or original processed value.
 */
function my_automator_modify_user_email_value( $value, $type, $transport, $field ) {

    // Check if the field code is 'user_email' and the transport is 'rest'
    if ( $field->get_code() === 'user_email' && $transport === 'rest' ) {
        // Append a string to the email value
        $modified_value = $value . '-processed';

        // Log the modification for debugging (optional)
        // error_log( "Automator: Modified user_email for REST transport. Original: {$value}, New: {$modified_value}" );

        // Return the modified value
        return $modified_value;
    }

    // If the conditions aren't met, return the original value
    return $value;
}
// Hook into the specific field code 'user_email'
add_filter( 'automator_field_value_processed_user_email', 'my_automator_modify_user_email_value', 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/api/services/field/class-field-sanitizer.php:209

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