Filter uncanny-automator-pro

automator_pro_formatter_text_formats

Filters the available text formats for the Formatter integration, allowing modification before they are displayed.

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

Description

Filters the available text formatting options for the Uncanny Automator text formatter. Developers can use this hook to add, remove, or modify text formatting actions before they are presented to the user. The hook fires after default formats are defined but before they are returned.


Usage

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

Parameters

$formats (mixed)
This parameter contains an array of text formatting options available for use within the Uncanny Automator Pro plugin.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of adding a custom text format to Uncanny Automator Pro's text formatter.
 * This example adds a new format called "Truncate" that limits the text length and adds an ellipsis.
 *
 * @param array $formats An associative array of text format configurations.
 * @return array The modified array of text format configurations.
 */
add_filter( 'automator_pro_formatter_text_formats', 'my_custom_automator_text_formats', 10, 1 );

function my_custom_automator_text_formats( $formats ) {

	// Add our new "Truncate" format
	$formats['truncate'] = array(
		'name'     => _x( 'Truncate', 'Text formatter', 'uncanny-automator-pro' ),
		'callback' => 'my_automator_format_truncate', // Our custom callback function
		'params'   => array( // Parameters the user can configure
			array(
				'label' => __( 'Max Length', 'uncanny-automator-pro' ),
				'name'  => 'max_length',
				'type'  => 'number',
				'default' => 100,
				'description' => __( 'The maximum number of characters to display before truncating.', 'uncanny-automator-pro' ),
			),
			array(
				'label' => __( 'Ellipsis', 'uncanny-automator-pro' ),
				'name'  => 'ellipsis',
				'type'  => 'text',
				'default' => '...',
				'description' => __( 'The string to append if the text is truncated.', 'uncanny-automator-pro' ),
			),
		),
	);

	return $formats;
}

/**
 * Custom callback function for the "Truncate" text format.
 *
 * @param string $input The original text input.
 * @param array  $params An array of parameters from the format configuration (e.g., max_length, ellipsis).
 * @return string The truncated text.
 */
function my_automator_format_truncate( $input, $params = array() ) {
	$max_length = isset( $params['max_length'] ) ? intval( $params['max_length'] ) : 100;
	$ellipsis   = isset( $params['ellipsis'] ) ? sanitize_text_field( $params['ellipsis'] ) : '...';

	if ( mb_strlen( $input ) > $max_length ) {
		return mb_substr( $input, 0, $max_length ) . $ellipsis;
	}

	return $input;
}

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/formatter/actions/text-formatter.php:224

'name' => _x( 'Remove spaces', 'Text formatter', 'uncanny-automator-pro' ),
		);

		foreach ( $formats as $id => &$format ) {
			$format['callback'] = array( $this, 'format_' . $id );
		}

		return apply_filters( 'automator_pro_formatter_text_formats', $formats );
	}

	public function format_uppercase( $input ) {
		return strtoupper( $input );
	}

	public function format_lowercase( $input ) {


Scroll to Top