Filter Since 7.0 uncanny-automator

automator_field_type_{$field_code}

Filters the field type for a specific field code. Dynamic hook that allows field-code-specific type overrides. Follows WordPress pattern (e.g., pre_update_option_{$option}). Filters the field type for a specific field code when processing API requests.

add_filter( 'automator_field_type_{$field_code}', $callback, 10, 3 );

Description

Filters the field type for a specific field code before sanitization. Use this dynamic hook to override default field types based on their code, enabling custom rendering or handling in integrations. Fires after field definition and before sanitization by type.


Usage

add_filter( 'automator_field_type_{$field_code}', 'your_function_name', 10, 3 );

Parameters

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

Return Value

The filtered value.


Examples

/**
 * Example of how to use the 'automator_field_type_your_field_code' filter.
 *
 * This filter allows you to change the sanitization type for a specific field.
 * For instance, if you have a custom field type that should always be treated
 * as raw HTML, you can hook into this filter to enforce that.
 *
 * Replace 'your_field_code' with the actual field code you want to target.
 */
add_filter(
	'automator_field_type_your_field_code', // Replace 'your_field_code' with the actual field code.
	function ( string $type, AutomatorAPIServicesFieldField $field, string $transport ) : string {
		// In this example, we're forcing a specific field code to be treated as 'html'
		// regardless of its original type. This could be useful if you have a custom
		// field that is specifically designed to hold and display HTML content.
		// We check the transport to ensure this logic only applies when needed.
		if ( 'rest' === $transport ) {
			return 'html'; // Force the sanitization type to 'html'.
		}

		// If the transport is not 'rest' or if you don't want to change the type,
		// return the original type to maintain default behavior.
		return $type;
	},
	10, // Priority: Standard priority.
	3  // Accepted args: $type, $field, $transport.
);

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:84

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

		$sanitized = $this->sanitize_by_type( $value, $type_value, $has_tokens );


Scroll to Top