Filter uncanny-automator-pro

automator_wp_set_user_meta_should_sanitize_fields

Filters whether to sanitize user meta fields before saving them, allowing customization of sanitization behavior.

add_filter( 'automator_wp_set_user_meta_should_sanitize_fields', $callback, 10, 2 );

Description

Allows developers to conditionally disable sanitization for user meta fields. Return `false` to prevent `sanitize_text_field()` from being called on the provided $value. This filter fires before sanitization is applied within the WP_SetUserMeta integration's `sanitize_text_field` method. Use with caution, as disabling sanitization can introduce security risks.


Usage

add_filter( 'automator_wp_set_user_meta_should_sanitize_fields', 'your_function_name', 10, 2 );

Parameters

$value (mixed)
This parameter is a boolean that determines whether fields should be sanitized.
$this (mixed)
This parameter contains the value of the user meta field that is being set, which may or may not be sanitized based on the filter's return value.

Return Value

The filtered value.


Examples

add_filter( 'automator_wp_set_user_meta_should_sanitize_fields', 'my_automator_disable_user_meta_sanitization_for_urls', 10, 3 );

/**
 * Conditionally disable sanitization for specific user meta fields if they are URLs.
 *
 * This example demonstrates how to prevent sanitization when the value being saved
 * is intended to be a URL, as sanitizing URLs can sometimes break them.
 *
 * @param bool   $should_sanitize Whether sanitization should proceed.
 * @param mixed  $value           The value being set for the user meta.
 * @param mixed  $object          The object instance (likely the action object).
 * @return bool                  Returns false to disable sanitization if the value looks like a URL.
 */
function my_automator_disable_user_meta_sanitization_for_urls( $should_sanitize, $value, $object ) {
	// Check if the value is a string and looks like a URL.
	// This is a basic check; a more robust check might involve regex.
	if ( is_string( $value ) && ( str_starts_with( $value, 'http://' ) || str_starts_with( $value, 'https://' ) ) ) {
		// Disable sanitization for this specific value if it's a URL.
		return false;
	}

	// Otherwise, return the original decision for sanitization.
	return $should_sanitize;
}

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

uncanny-automator-pro/src/integrations/wp/actions/wp-setusermeta.php:157

private function sanitize_text_field( $value = '' ) {

		// Only sanitize if its a string.
		if ( ! is_string( $value ) ) {
			return $value;
		}

		if ( apply_filters( 'automator_wp_set_user_meta_should_sanitize_fields', true, $value, $this ) ) {
			return sanitize_text_field( $value );
		}

		return $value;

	}

Scroll to Top