Filter uncanny-automator

automator_loopable_should_encode_html_entities

Filters whether HTML entities should be encoded for loopable automator data, allowing customization of output.

add_filter( 'automator_loopable_should_encode_html_entities', $callback, 10, 1 );

Description

Allows developers to control HTML entity encoding for loopable data. By default, it's enabled (true). Developers can set it to false to prevent encoding, useful when data already contains or intentionally needs raw HTML.


Usage

add_filter( 'automator_loopable_should_encode_html_entities', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to use the 'automator_loopable_should_encode_html_entities' filter.
 *
 * This example disables HTML entity encoding for loopable data when a specific
 * user role is detected, which might be useful if the data is already
 * properly escaped or if the consuming system handles encoding differently.
 */
add_filter( 'automator_loopable_should_encode_html_entities', 'my_custom_loopable_encoding_logic', 10, 1 );

/**
 * Custom logic to conditionally disable HTML entity encoding.
 *
 * @param bool $encode_html_entities The default value, true to encode, false to not.
 * @return bool False if the current user has the 'editor' role, true otherwise.
 */
function my_custom_loopable_encoding_logic( $encode_html_entities ) {
	// Check if the current user is logged in and has the 'editor' role.
	if ( is_user_logged_in() ) {
		$current_user = wp_get_current_user();
		if ( in_array( 'editor', (array) $current_user->roles ) ) {
			// If the user is an editor, we might want to skip encoding for easier debugging or
			// if the editor is expected to handle escaping themselves.
			return false;
		}
	}

	// For all other cases, return the default value.
	return $encode_html_entities;
}

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/services/loopable/data-integrations/utils.php:339

public static function should_encode_html_entities() {
		return apply_filters( 'automator_loopable_should_encode_html_entities', true );
	}

Scroll to Top