Filter uncanny-automator

automator_sanitize_get_field_type_html

Filters the HTML output for a field type when retrieving it, allowing for modification of the generated HTML and associated options.

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

Description

This filter hook allows developers to modify the HTML output for specific field types within the plugin's core utilities. You can hook into `automator_sanitize_get_field_type_html` to alter the generated HTML, influence the `$option_code`, or adjust the `$options` array. It's particularly useful for customizing how rich text or HTML-enabled fields are rendered, offering fine-grained control over their presentation.


Usage

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

Parameters

$option_code (mixed)
This parameter contains the sanitized HTML string representing the field type.
$options (mixed)
This parameter contains the code identifier for the field being processed.

Return Value

The filtered value.


Examples

add_filter(
	'automator_sanitize_get_field_type_html',
	function ( $html, $option_code, $options ) {
		// This filter hook is typically used to determine if a field should be rendered as HTML (e.g., using a rich text editor like TinyMCE).
		// The default logic in the source context already handles this based on 'supports_tinymce'.
		// This example demonstrates how you might further process or conditionally change the field type to HTML
		// if there are other custom requirements beyond the basic 'supports_tinymce' flag.

		// For instance, imagine a scenario where specific 'option_codes' are always meant to be rich text,
		// regardless of the 'supports_tinymce' flag, for administrative convenience.
		$always_rich_text_codes = array( 'custom_email_body', 'user_welcome_message' );

		if ( in_array( $option_code, $always_rich_text_codes, true ) ) {
			// Force the field type to 'html' if it's one of the designated codes.
			return 'html';
		}

		// If the default 'supports_tinymce' logic (handled before this filter) indicated HTML, we return it.
		// Otherwise, if this custom logic didn't trigger a change, we return the original value passed to the filter,
		// which is likely 'html' if the 'supports_tinymce' condition was met in the calling function.
		return $html;
	},
	10, // Priority: default is 10
	3  // Accepted arguments: $html, $option_code, $options
);

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:710

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 );
	}


Scroll to Top