Abstract_Meetings::ajax_update( string|null $nonce = null )

Handles the request to update a Zoom meeting or webinar.


Parameters

$nonce

(string|null) (Optional) The nonce that should accompany the request.

Default value: null


Top ↑

Return

(bool) Whether the request was handled or not.


Top ↑

Source

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

	public function ajax_update( $nonce = null ) {
		if ( ! $this->check_ajax_nonce( static::$update_action, $nonce ) ) {
			return false;
		}

		$event = $this->check_ajax_post();

		if ( ! $event ) {
			return false;
		}

		$post_id = $event->ID;

		$zoom_id = tribe_get_request_var( 'zoom_id' );
		if ( empty( $zoom_id ) ) {
			return false;
		}

		$alternative_hosts = tribe_get_request_var( 'zoom_alternative_hosts' );

		$body = [
			'settings' => [
				'alternative_hosts' => esc_attr( implode( ";", $alternative_hosts ) ),
			]
		];

		/**
		 * Filters the contents of the request that will be made to the Zoom API to update a meeting or webinar.
		 *
		 * @since 1.4.0
		 *
		 * @param array<string,mixed> The current content of the request body.
		 * @param \WP_Post $event The event post object, as decorated by the `tribe_get_event` function.
		 * @param Meetings $this  The current API handler object instance.
		 */
		$body = apply_filters(
			"tribe_events_virtual_ajax_update_meetings_zoom_{$this::$meeting_type}_request_body",
			$body,
			$event,
			$this
		);

		$success = false;

		// Update.
		$this->api->patch(
			Api::$api_base . "{$this::$api_endpoint}/{$zoom_id}",
			[
				'headers' => [
					'Authorization' => $this->api->token_authorization_header(),
					'Content-Type'  => 'application/json; charset=utf-8',
				],
				'body'    => wp_json_encode( $body ),
			],
			Api::PATCH_RESPONSE_CODE
		)->then(
			function ( array $response ) use ( $post_id, $event, &$success ) {
				$this->process_meeting_update_response( $response, $event, $post_id );

				$success = true;

				wp_die();
			}

		)->or_catch(
			static function ( \WP_Error $error ) use ( $event ) {
				do_action(
					'tribe_log',
					'error',
					__CLASS__,
					[
						'action'  => __METHOD__,
						'code'    => $error->get_error_code(),
						'message' => $error->get_error_message(),
					]
				);

				$error_data    = wp_json_encode( $error->get_error_data() );
				$decoded       = json_decode( $error_data, true );
				$error_message = null;
				if ( false !== $decoded && is_array( $decoded ) && isset( $decoded['message'] ) ) {
					$error_message = $decoded['message'];
				}

				// Do something to indicate failure with $error_message?
				$this->classic_editor->render_meeting_generation_error_details( $event, $error_message, true );
			}
		);

		return $success;
	}

Top ↑

Changelog

Changelog
Version Description
1.4.0 Introduced.