Google_Calendar_Helpers::get_calendar_options()

Method get_calendar_options.


Description Description

Retrieves the calendar options fields.


Top ↑

Return Return

(array) The option items.


Source Source

File: src/integrations/google-calendar/helpers/google-calendar-helpers.php

	public function get_calendar_options() {

		$response = get_transient( 'automator_google_calendar_calendar_list' );

		$items = array();

		// Serve from cache.
		if ( false !== $response ) {

			if ( is_array( $response ) && ! empty( $response ) ) {

				$response = $this->parse_response( $response['data'] );

				foreach ( $response as $calendar ) {

					$items[ $calendar['value'] ] = $calendar['text'];

				}
			}

			return $items;
		}

		// Otherwise, request live data.
		try {

			$response = $this->api_call(
				array(
					'action' => 'list_calendars',
				),
				null
			);

			set_transient( 'automator_google_calendar_calendar_list', $response, 5 * MINUTE_IN_SECONDS );

			if ( is_array( $response ) && ! empty( $response ) ) {

				$response = $this->parse_response( $response['data'] );

				foreach ( $response as $calendar ) {

					$items[ $calendar['value'] ] = $calendar['text'];

				}
			}

			return $items;

		} catch ( \Exception $e ) {

			$items = array(
				/* translators: Error message */
				'' => sprintf( esc_html__( '%1$s: %2$s Please try again later.', 'uncanny-automator' ), $e->getCode(), $e->getMessage() ),
			);

		}

		return $items;

	}