Filter
uncanny-automator
automator_sanitize_get_field_type
Filters the field type for AutomatorWP's get field type action, allowing customization before it's used.
add_filter( 'automator_sanitize_get_field_type', $callback, 10, 1 );
Description
Filters the sanitized value of a field when creating a post. Developers can use this hook to modify or validate field data before it's saved as post meta, ensuring data integrity and custom handling.
Usage
add_filter( 'automator_sanitize_get_field_type', 'your_function_name', 10, 1 );
Parameters
-
$meta_key(mixed) - The 'text' parameter likely represents the sanitized value of the meta field to be processed.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'automator_sanitize_get_field_type' filter.
*
* This filter allows you to modify the sanitization type for a given field.
* For instance, if you have a field that should be treated as an email address
* for sanitization purposes, you can change the 'text' type to 'email'.
*
* @param string $field_type The current sanitization field type.
* @param mixed $field_key The key of the field being processed.
* @param array $args Additional arguments passed to the filter.
*
* @return string The modified sanitization field type.
*/
add_filter(
'automator_sanitize_get_field_type',
function ( $field_type, $field_key, $args ) {
// Example: If the field key is 'user_email', force sanitization as 'email'.
if ( 'user_email' === $field_key ) {
return 'email';
}
// Example: If the field key is 'post_slug', force sanitization as 'slug'.
if ( 'post_slug' === $field_key ) {
return 'slug';
}
// If no specific handling is needed, return the original field type.
return $field_type;
},
10,
3
);
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/integrations/wp/actions/wp-createpost.php:501
src/integrations/wp/actions/wp-createpost.php:505
if (
true === apply_filters( 'automator_create_post_sanitize_meta_values', true, $meta_key, $meta_value, $recipe_id ) &&
true === apply_filters( 'automator_create_post_sanitize_meta_values_' . $recipe_id, true, $meta_key, $meta_value ) &&
true === apply_filters( 'automator_create_post_sanitize_meta_values_' . sanitize_title( $meta_key ), true, $meta_value, $recipe_id )
) {
$meta_key = Automator()->utilities->automator_sanitize(
$meta_key,
apply_filters( 'automator_sanitize_get_field_type', 'text', $meta_key, array() )
);
$meta_value = Automator()->utilities->automator_sanitize(
$meta_value,
apply_filters( 'automator_sanitize_get_field_type', 'text', $meta_value, array() )
);
}
update_post_meta( $post_id, $meta_key, $meta_value );