Google_Calendar_Helpers::list_calendars_dropdown()

Method list_calendars_dropdown.


Description Description

A wp_ajax callback method.


Top ↑

Return Return

(Uncanny_Automatorvoid.)


Source Source

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

	public function list_calendars_dropdown() {

		Automator()->utilities->ajax_auth_check();

		$response = get_transient( 'automator_google_calendar_calendar_list' );

		$items = array();

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

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

			wp_die();

		}

		// Otherwise, request live data.
		try {

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

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

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

		} catch ( \Exception $e ) {

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

		}

		echo wp_json_encode( $items );

		wp_die();

	}