Filter uncanny-automator-pro

automator_pro_formatter_output_date_formats

Filters the available date formats for the Formatter integration's output.

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

Description

Filters the available date format options for the Uncanny Automator date formatter. Developers can use this hook to add, remove, or modify the default date formats offered to users for displaying dates in their automations. This allows for custom date presentation beyond the standard WordPress options.


Usage

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

Parameters

$options (mixed)
This parameter contains an array of available date format options that can be used to display dates within Uncanny Automator Pro.

Return Value

The filtered value.


Examples

// Add a custom date format option to the Uncanny Automator Pro date formatter
add_filter( 'automator_pro_formatter_output_date_formats', 'my_custom_automator_date_format', 10, 1 );

function my_custom_automator_date_format( $options ) {
	// Assuming $options is an array of arrays, where each inner array has 'text' and 'value'.
	// We'll add our custom format to the beginning of the list.

	// Get the current date and time for previewing the custom format
	$current_date = new DateTime();

	// Define our custom format: Day of the week, Month Day, Year at Hour:Minute AM/PM
	$custom_format_title = __( 'Custom - Day, Month Day, Year at Hour:Minute AM/PM', 'my-text-domain' );
	$custom_format_value = 'l, F j, Y at g:i A';

	// Add the custom format to the beginning of the options array
	array_unshift( $options, array(
		'text'  => $custom_format_title . ' (' . $current_date->format( $custom_format_value ) . ')',
		'value' => $custom_format_value,
	) );

	// Return the modified options array
	return $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

uncanny-automator-pro/src/integrations/datetime/actions/uoa-generate-new-datetime.php:132
uncanny-automator-pro/src/integrations/datetime/actions/uoa-apply-datetime-modifier.php:140
uncanny-automator-pro/src/integrations/datetime/actions/uoa-generate-new-date.php:99
uncanny-automator-pro/src/integrations/formatter/actions/date-formatter.php:230

public function date_format_options() {

		//$formats   = $this->date_time_formats();
		$formats = array(
			'Mmm DD, YYYY 12-hour'            => 'M d, Y g:i a',
			'Mmm DD, YYYY 24-hour'            => 'M d, Y H:i',
			'MM/DD/YYYY 12-hour'              => 'm/d/Y g:i a',
			'MM/DD/YYYY 24-hour with seconds' => 'm/d/Y H:i:s',
			'DD/MM/YYYY 12-hour with seconds' => 'd/m/Y g:i:s a',
			'DD/MM/YYYY 24-hour'              => 'd/m/Y H:i',
			'YYYY-MM-DD 24-hour with seconds' => 'Y-m-d H:i:s',
			'DD-Mmm-YYYY 12-hour'             => 'd-M-Y g:i a',
			'YYYY/MM/DD 24-hour'              => 'Y/m/d H:i',
			// Additional formats
			'RFC 2822 Format'                 => 'r', // Example: Thu, 21 Dec 2000 16:01:07 +0200
			'ISO 8601 Format'                 => 'c', // Example: 2004-02-12T15:19:21+00:00
			'Unix Timestamp'                  => 'U', // Example: 161718
			// Considering adding UTC might mean showing the time in UTC, adding a specific format for it.
			'UTC Time'                        => 'Y-m-dTH:i:sZ', // ISO 8601 format in UTC
		);

		$base_date = new DateTime();

		$options   = array();
		$options[] = array(
			'value' => 'site_format',
			'text'  => _x( "Site's date and time format", 'Date formatter', 'uncanny-automator-pro' ),
		);

		foreach ( $formats as $title => $format ) {
			$options[] = array(
				'text'  => $title . ' (' . $base_date->format( $format ) . ')',
				'value' => $format,
			);
		}

		return apply_filters( 'automator_pro_formatter_output_date_formats', $options );
	}


Scroll to Top