Filter Since 7.0 uncanny-automator

automator_field_type

Filters the field type before sanitization. Allows overriding the field type for all transports. Field type transformation at the transport layer (e.g., REST) should be done before fields reach the sanitizer. Filters the field type before sanitization, allowing custom transformations for specific transports like REST.

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

Description

Filters the field type before sanitization, allowing transport-specific overrides. Use this hook to modify field types for different integrations like REST API or internal transports, ensuring proper data handling before it's processed by the sanitizer.


Usage

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

Parameters

$type (string)
The field type (e.g., 'text', 'textarea', 'markdown', 'html').
$field_code (string)
The field code.
$field (Field)
The Field object.
$transport (string)
The transport identifier ('rest', 'mcp').

Return Value

The filtered value.


Examples

<?php
/**
 * Example of using the 'automator_field_type' filter hook to modify a field type.
 * This example will change the field type to 'textarea' if the field code is 'custom_notes'
 * and the transport is 'rest'.
 *
 * @param string $type       The field type.
 * @param string $field_code The field code.
 * @param object $field      The Field object.
 * @param string $transport  The transport identifier.
 * @return string The modified field type.
 */
function my_automator_custom_field_type( $type, $field_code, $field, $transport ) {
    // Check if the field code is 'custom_notes' and the transport is 'rest'
    if ( 'custom_notes' === $field_code && 'rest' === $transport ) {
        // Change the field type to 'textarea'
        return 'textarea';
    }

    // If the conditions are not met, return the original field type
    return $type;
}
add_filter( 'automator_field_type', 'my_automator_custom_field_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/api/services/field/class-field-sanitizer.php:64

* @since 7.0
		 *
		 * @param string $type       The field type (e.g., 'text', 'textarea', 'markdown', 'html').
		 * @param string $field_code The field code.
		 * @param Field  $field      The Field object.
		 * @param string $transport  The transport identifier ('rest', 'mcp').
		 */
		$type_value = apply_filters(
			'automator_field_type',
			$type_value,
			$field_code,
			$field,
			$transport
		);


Scroll to Top