Filter Since Legacy uncanny-automator

automator_wpcpostcontent_should_sanitize

Filters whether to sanitize content when saving posts, defaulting to false for no sanitization.

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

Description

Control whether the content of WordPress posts, when used as an action in automations, should undergo sanitization. By default, sanitization is disabled. Return `true` to enable `wp_kses_post()` sanitization for post content.


Usage

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

Parameters

$should_sanitize (bool)
Whether to apply wp_kses_post(). Default false.
$data (array)
The field data array.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the 'automator_wpcpostcontent_should_sanitize' filter.
 * This example will conditionally sanitize the post content if a specific user role is detected.
 *
 * @param bool  $should_sanitize The current value of whether to sanitize.
 * @param array $data            The array of data being processed by Automator.
 *
 * @return bool Whether the post content should be sanitized.
 */
add_filter( 'automator_wpcpostcontent_should_sanitize', function( $should_sanitize, $data ) {
	// Check if the current user has the 'editor' role.
	// We only want to sanitize post content for editors if they are explicitly adding specific HTML tags
	// that might be considered unsafe by default wp_kses_post.
	if ( is_user_logged_in() && current_user_can( 'editor' ) ) {
		// If the current user is an editor, we want to allow sanitization to happen.
		// This is just an example, you might have more complex logic here based on other data.
		return true;
	}

	// Otherwise, keep the default behavior (which is false by default, meaning no sanitization).
	return $should_sanitize;
}, 10, 2 );

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-legacy-hooks.php:108
src/core/lib/utilities/class-automator-utilities.php:583

public function handle_wpcpostcontent( $sanitized, $original, string $type, string $transport, Field $field ) {
		// Build the data array in legacy format for filter compatibility.
		$data = array( 'WPCPOSTCONTENT' => $sanitized );

		/**
		 * Filters whether to sanitize WPCPOSTCONTENT with wp_kses_post().
		 *
		 * @since Legacy
		 *
		 * @param bool  $should_sanitize Whether to apply wp_kses_post(). Default false.
		 * @param array $data            The field data array.
		 */
		if ( apply_filters( 'automator_wpcpostcontent_should_sanitize', false, $data ) ) {
			$sanitized = wp_kses_post( $sanitized );
		}

		/**
		 * Filters whether to apply wp_slash() to WPCPOSTCONTENT.
		 *
		 * @since Legacy
		 *
		 * @param bool  $should_slash Whether to apply wp_slash(). Default false.
		 * @param array $data         The field data array.
		 */
		if ( apply_filters( 'automator_wpcpostcontent_should_wp_slash', false, $data ) ) {
			$sanitized = wp_slash( $sanitized );
		}

		return $sanitized;
	}


Scroll to Top