• Home
  • Knowledgebase
  • DevDocs
  • Translations
  • Support
  • Live Preview

logo DevDocs

By The Events Calendar
Filter by type:
Skip to content
Filter by type:
Search
Browse: Home / Classes / Account_API / Account_API::save_account()
Product: Virtual Events

Account_API::save_account( $response )

{@inheritDoc}


Source

File: src/Tribe/Meetings/Zoom/Account_API.php

	public function save_account( array $response ) {
		if ( ! (
			isset( $response['body'] )
			&& ( false !== $d = json_decode( $response['body'], true ) )
			&& isset( $d['access_token'], $d['refresh_token'], $d['expires_in'] )
		)
		) {
			do_action( 'tribe_log', 'error', __CLASS__, [
				'action'  => __METHOD__,
				'code'    => wp_remote_retrieve_response_code( $response ),
				'message' => 'Response body missing or malformed',
			] );

			return false;
		}

		// Set the access token here as we have to call fetch_user immediately, to get the user information.
		$access_token  = $d['access_token'];
		$refresh_token = $d['refresh_token'];
		$expiration    = $this->get_exiration_time_stamp( $d['expires_in'] );

		// Get the user who authorized the account.
		$user         = $this->fetch_user( 'me', false, $access_token);
		if ( empty( $user['id'] ) ) {
			return false;
		}

		$settings         = $this->fetch_user( $user['id'], true, $access_token );
		$account_data     = $this->prepare_account_data( $user, $access_token, $refresh_token, $expiration, $settings, true );
		$existing_account = $this->get_account_by_id( $account_data['id'] );
		$this->set_account_by_id( $account_data );

		$account_msg = $existing_account ?
			_x( 'Zoom connection refreshed for %1$s', 'The refresh message if the account exists.', 'events-virtual' )
			: _x( 'Zoom Account added for %1$s', 'The refresh message if the account exists.', 'events-virtual' );
		$message = sprintf(
			/* Translators: %1$s: the name of the account that has been added or refreshed from Zoom . */
			$account_msg,
			$this->encryption->decrypt( $account_data['name'] )
		);

		set_transient( Settings::$option_prefix . 'account_message', $message, MINUTE_IN_SECONDS );

		return $access_token;
	}

Expand full source code Collapse full source code

The Events Calendar
  • Home
  • Products
  • Blog
  • Support
© 2026 The Events Calendar Terms and Conditions Privacy