Filter uncanny-automator

automator_google_calendar_date_format

Filter the date format. Filters the date format used for Google Calendar events, allowing customization of how dates are displayed.

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

Description

Filters the date format used for Google Calendar events. Developers can use this hook to customize how dates are displayed, ensuring compatibility with different regional settings or specific event requirements. The hook fires before the date is sent to the Google Calendar API, allowing for dynamic format adjustments.


Usage

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

Parameters

$date_format (string)
The date format.
$this (GCALENDAR_ADDEVENT)
The current instance.

Return Value

string The date format.


Examples

<?php
/**
 * Example: Change the Google Calendar date format to include the year and month.
 * This is useful if you want to ensure that the year and month are always
 * explicitly included in the date sent to Google Calendar, even if the
 * site's default date format doesn't always show them.
 */
add_filter( 'automator_google_calendar_date_format', function ( $date_format, $gcalendar_action_instance ) {
	// Check if the current instance is for adding an event and if the date format is not already comprehensive.
	// We assume $gcalendar_action_instance is an object of type GCALENDAR_ADDEVENT or similar.
	// The check for $date_format is just an example to show conditional logic.
	if ( $gcalendar_action_instance instanceof GCALENDAR_ADDEVENT && strpos( $date_format, 'Y' ) === false && strpos( $date_format, 'm' ) === false ) {
		// Modify the date format to include the year and month.
		return 'Y-m-d';
	}

	// Otherwise, return the original date format.
	return $date_format;
}, 10, 2 );
?>

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/integrations/google-calendar/actions/gcalendar-addevent.php:486

protected function get_date_format() {
		/**
		 * Filter the date format.
		 *
		 * @param string $date_format The date format.
		 * @param GCALENDAR_ADDEVENT $this The current instance.
		 *
		 * @return string The date format.
		 * @example
		 * add_filter( 'automator_google_calendar_date_format', function ( $date_format, $this ) {
		 *  return 'Y-m-d';
		 * }, 10, 2 );
		 */
		return apply_filters( 'automator_google_calendar_date_format', get_option( 'date_format', 'F j, Y' ), $this );
	}


Internal Usage

Found in src/integrations/google-calendar/actions/gcalendar-addevent.php:482:

* add_filter( 'automator_google_calendar_date_format', function ( $date_format, $this ) {
Scroll to Top