Filter
uncanny-automator-pro
automator_pro_formatter_number_formats
Filters the available number formatting options for the Formatter integration, allowing customization of how numbers are displayed.
add_filter( 'automator_pro_formatter_number_formats', $callback, 10, 1 );
Description
Fires after default number formatting options are registered. Developers can add, modify, or remove formatting options for the Number Formatter integration. This hook provides full control over how numbers are presented in Uncanny Automator Pro recipes.
Usage
add_filter( 'automator_pro_formatter_number_formats', 'your_function_name', 10, 1 );
Parameters
-
$formats(mixed) - This parameter is an array that will be populated with available number formatting options.
Return Value
The filtered value.
Examples
/**
* Adds a custom number formatting option for Uncanny Automator Pro.
*
* This example demonstrates how to add a new format type called 'scientific'
* which will format numbers using scientific notation.
*
* @param array $formats The existing number format configurations.
* @return array The modified array of number format configurations.
*/
add_filter( 'automator_pro_formatter_number_formats', function( $formats ) {
// Define the new format type.
$formats['scientific'] = array(
'name' => _x( 'Scientific Notation', 'Number formatter', 'uncanny-automator-pro' ),
'callback' => function( $input ) {
// Ensure the input is numeric before attempting to format.
if ( is_numeric( $input ) ) {
return sprintf( '%e', $input );
}
return $input; // Return original input if not numeric.
},
);
return $formats;
}, 10, 1 );
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/number-formatter.php:200
public function get_formats() {
$formats = array();
$formats['round'] = array(
'name' => _x( 'Round to integer', 'Number formatter', 'uncanny-automator-pro' ),
);
$formats['round_to_one'] = array(
'name' => _x( 'Round to one decimal place', 'Number formatter', 'uncanny-automator-pro' ),
);
$formats['round_to_two'] = array(
'name' => _x( 'Round to two decimal places', 'Number formatter', 'uncanny-automator-pro' ),
);
$formats['currency_english'] = array(
'name' => _x( 'Currency English notation (1,234.56)', 'Number formatter', 'uncanny-automator-pro' ),
);
$formats['currency_french'] = array(
'name' => _x( 'Currency French notation (1 234,56)', 'Number formatter', 'uncanny-automator-pro' ),
);
$formats['currency_dot'] = array(
'name' => _x( 'Currency with dot decimals (1 234.56)', 'Number formatter', 'uncanny-automator-pro' ),
);
$formats['floor'] = array(
'name' => _x( 'Round down (floor)', 'Number formatter', 'uncanny-automator-pro' ),
);
$formats['ceil'] = array(
'name' => _x( 'Round up (ceil)', 'Number formatter', 'uncanny-automator-pro' ),
);
$formats['is_even'] = array(
'name' => _x( 'Is even (returns 1 for even values, 0 for odd)', 'Number formatter', 'uncanny-automator-pro' ),
);
$formats['default_zero'] = array(
'name' => _x( 'Default zero (replace empty value with zero)', 'Number formatter', 'uncanny-automator-pro' ),
);
foreach ( $formats as $id => &$format ) {
$format['callback'] = array( $this, 'format_' . $id );
}
return apply_filters( 'automator_pro_formatter_number_formats', $formats );
}