Page_API::save_access_token( string $nonce )

Save a Facebook Page access token using ajax.


Parameters

$nonce

(string) (Required) The save access action nonce to check.


Top ↑

Return

(string) An html message for success or failure when saving.


Top ↑

Source

File: src/Tribe/Meetings/Facebook/Page_API.php

	public function save_access_token( $nonce ) {
		if ( ! $this->check_ajax_nonce( Settings::$save_access_action, $nonce ) ) {
			return false;
		}

		$local_id     = tribe_get_request_var( 'local_id' );
		$page_id      = tribe_get_request_var( 'page_id' );
		$access_token = tribe_get_request_var( 'access_token' );
		// If missing information fail the request.
		if ( empty( $local_id ) || empty( $page_id ) || empty( $access_token ) ) {
			$error_message = _x(
				'The Facebook Page ID, local ID, or access token is missing.',
				'Facebook Page ID, local ID, or access token is missing error message.',
				'events-virtual'
			);
			tribe( Template_Modifications::class )->get_settings_message_template( $error_message, 'error' );

			wp_die();
		}

		// Check if the page exists.
		$page_data = $this->get_page_by_id( $local_id );
		if ( empty( $page_data ) ) {
			$message = _x(
				'No Facebook Page found to update.',
				'Error message if the Facebook Page was not found in the options.',
				'events-virtual'
			);
			tribe( Template_Modifications::class )->get_settings_message_template( $message, 'error' );

			wp_die();
		}

		// Get the access token expiration.
		$expiration = $this->get_access_expiration( $access_token );

		$this->set_page_access_by_id( $local_id, $access_token, $expiration );

		$message = _x(
			'Facebook Page access token saved.',
			'Facebook Page is saved to the options.',
			'events-virtual'
		);
		tribe( Template_Modifications::class )->get_settings_message_template( $message );

		$page = $this->get_page_by_id( $local_id );
		tribe( Template_Modifications::class )->get_page_fields( $local_id, $page );

		wp_die();
	}

Top ↑

Changelog

Changelog
Version Description
1.7.0 Introduced.