Filter
uncanny-automator
automator_sanitize_get_field_type_text
Filters the text field type for sanitization, allowing modification of its value and associated options before it's saved.
add_filter( 'automator_sanitize_get_field_type_text', $callback, 10, 2 );
Description
Sanitizes and returns the field type when retrieving field options. Developers can use this filter to override the default 'text' field type or modify its handling. This hook fires when checking for existing field options and returns the determined field type.
Usage
add_filter( 'automator_sanitize_get_field_type_text', 'your_function_name', 10, 2 );
Parameters
-
$option_code(mixed) - This parameter represents the default or intended field type, which is 'text' if no specific type is determined.
-
$options(mixed) - This parameter holds the code or identifier of the specific option field being processed.
Return Value
The filtered value.
Examples
/**
* Example of how to use the 'automator_sanitize_get_field_type_text' filter.
*
* This filter allows you to modify the default 'text' field type returned by
* the automator_sanitize_get_field_type function under certain conditions.
*
* In this example, we'll check if the $option_code contains "email" and,
* if so, change the field type to "email".
*
* @param string $field_type The default field type, which is 'text' in this context.
* @param mixed $option_code The code for the option being processed.
* @param mixed $options The full options array.
*
* @return string The modified field type.
*/
add_filter( 'automator_sanitize_get_field_type_text', function( $field_type, $option_code, $options ) {
// Check if the option code suggests it's an email field
if ( is_string( $option_code ) && strpos( $option_code, 'email' ) !== false ) {
// If it contains 'email', change the field type to 'email'
return 'email';
}
// Otherwise, return the original field type
return $field_type;
}, 10, 3 ); // 10 is the priority, 3 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
src/core/lib/utilities/class-automator-utilities.php:705
src/core/lib/utilities/class-automator-utilities.php:720
public function maybe_get_field_type( $option_code, $options ) {
// if nothing is set, return text
if ( empty( $options ) || ! isset( $options['fields'] ) || ! isset( $options['fields'][ $option_code ] ) ) {
return apply_filters( 'automator_sanitize_get_field_type_text', 'text', $option_code, $options );
}
// if tinymce is set to yes, return HTML
if ( isset( $options['fields'][ $option_code ]['supports_tinymce'] ) && 'true' === (string) $options['fields'][ $option_code ]['supports_tinymce'] ) {
return apply_filters( 'automator_sanitize_get_field_type_html', 'html', $option_code, $options );
}
// if markdown is set to yes, return HTML
if ( isset( $options['fields'][ $option_code ]['supports_markdown'] ) && 'true' === (string) $options['fields'][ $option_code ]['supports_markdown'] ) {
return apply_filters( 'automator_sanitize_get_field_type_markdown', 'markdown', $option_code, $options );
}
// No type found
if ( ! isset( $options['fields'][ $option_code ]['type'] ) || empty( $options['fields'][ $option_code ]['type'] ) ) {
return apply_filters( 'automator_sanitize_get_field_type_text', 'text', $option_code, $options );
}
// Return type
$type = (string) $options['fields'][ $option_code ]['type'];
return apply_filters( 'automator_sanitize_get_field_type_' . $type, $type, $option_code, $options );
}