Filter uncanny-automator

automator_google_calendar_add_event_timezone

Filters the timezone string for Google Calendar events when adding them.

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

Description

Filter the timezone string used when adding events to Google Calendar. Developers can modify this to enforce a specific timezone, override the default, or dynamically set the timezone based on custom logic before the event is created via the Google Calendar integration.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Example of filtering the Google Calendar event timezone.
 *
 * This function allows you to dynamically alter the timezone string used
 * when adding an event to Google Calendar via the Automator plugin.
 * For instance, you might want to override the default timezone with
 * a specific timezone based on a user's selection or another logic.
 *
 * @param string|null $timezone_string The current timezone string. Defaults to null if not explicitly set elsewhere.
 * @return string The modified timezone string to be used for the Google Calendar event.
 */
add_filter( 'automator_google_calendar_add_event_timezone', function( $timezone_string ) {

	// Let's say we want to force a specific timezone for all events added by this automation.
	// In a real scenario, this might come from a dynamic user preference or another meta field.
	$forced_timezone = 'America/New_York'; // Example: Eastern Standard Time

	// Check if a timezone was already provided by the plugin or other filters.
	// If not, or if we want to unconditionally override, we can set our desired timezone.
	// For this example, we'll unconditionally set it.
	return $forced_timezone;

}, 10, 1 ); // Priority 10, accepts 1 argument.

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

'end_date'                   => $this->autoformat_date( $end_date ),
			'end_time'                   => $this->autoformat_time( $end_time ),
			'attendees'                  => str_replace( ' ', '', trim( $attendees ) ),
			'notification_email'         => $notification_email,
			'notification_popup'         => $notification_popup,
			'notification_time_email'    => $notification_time_email,
			'notification_time_popup'    => $notification_time_popup,
			'timezone'                   => ! empty( $timezone ) ? $timezone : apply_filters( 'automator_google_calendar_add_event_timezone', Automator()->get_timezone_string() ),
			// Google Calendar endpoint is written so the date format can be changed from the Client.
			'date_format'                 => $this->get_date_format(),
			'time_format'                 => $this->get_time_format(),
			// Event settings.
			'visibility'                  => $visibility,
			'transparency'                => $transparency,
			// Guest permissions.

Scroll to Top