Api::filter_virtual_autodetect_zoom( TribeEventsVirtualMeetingsZoomarray $autodetect, string $video_url, string $video_source, WP_Post|null $event, TribeEventsVirtualMeetingsZoomarray $ajax_data )

Filter the autodetect source to detect if a Zoom link.


Parameters

$autodetect

(<span class="TribeEventsVirtualMeetingsZoomarrayTribeEventsVirtualMeetingsZoomarray<string|">TribeEventsVirtualMeetingsZoommixed>) (Required) An array of the autodetect defaults.

$video_url

(string) (Required) The url to use to autodetect the video source.

$video_source

(string) (Required) The optional name of the video source to attempt to autodetect.

$event

(WP_Post|null) (Required) The event post object, as decorated by the tribe_get_event function.

$ajax_data

(<span class="TribeEventsVirtualMeetingsZoomarrayTribeEventsVirtualMeetingsZoomarray<string|">TribeEventsVirtualMeetingsZoommixed>) (Required) An array of extra values that were sent by the ajax script.


Top ↑

Return

(TribeEventsVirtualMeetingsZoomarray<string|TribeEventsVirtualMeetingsZoommixed>) An array of the autodetect results.


Top ↑

Source

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

	public function filter_virtual_autodetect_zoom( $autodetect, $video_url, $video_source, $event, $ajax_data ) {
		if ( $autodetect['detected'] || $autodetect['guess'] ) {
			return $autodetect;
		}

		// All video sources are checked on the first autodetect run, only prevent checking of this source if it is set.
		if ( ! empty( $video_source ) && Zoom_Meta::$key_zoom_source_id !== $video_source ) {
			return $autodetect;
		}

		// If virtual url, fail the request.
		if ( empty( $video_url ) ) {
			$autodetect['message'] = _x( 'No url found. Please enter a Zoom meeting URL or change the selected source.', 'Zoom autodetect missing video url error message.', 'events-virtual' );

			return $autodetect;
		}

		// Attempt to find the Zoom meeting/webinar id from the url.
		preg_match( $this->get_regex_meeting_id_url(), $video_url, $matches );
		$zoom_meeting_id     = isset( $matches['id'] ) ? $matches['id'] : false;
		if ( ! $zoom_meeting_id ) {
			$error_message = _x( 'No Zoom ID found. Please check your meeting URL.', 'No Zoom meeting/webinar ID found for autodetect error message.', 'events-virtual' );
			$autodetect['message'] = $error_message;

			return $autodetect;
		}

		$autodetect['guess'] = Zoom_Meta::$key_zoom_source_id;

		// Use the zoom-account if available, otherwise try with the first account stored in the site.
		$accounts = $this->get_list_of_accounts();
		$account_id = empty( $ajax_data['zoom-account'] ) ? array_key_first($accounts) : esc_attr( $ajax_data['zoom-account'] );

		if ( empty( $account_id ) ) {
			$autodetect['message'] = $this->get_no_account_message();

			return $autodetect;
		}

		$this->load_account_by_id( $account_id );
		if ( ! $this->is_ready() ) {
			$autodetect['message'] = $this->get_no_account_message();

			return $autodetect;
		}

		$data = $this->fetch_meeting_data( $zoom_meeting_id, 'meeting' );

		// If not meeting found, test with webinar.
		if ( empty( $data ) ) {
			$data = $this->fetch_meeting_data( $zoom_meeting_id, 'webinar' );
		}

		// If no meeting or webinar found it is because the account is not authorized or does not exist.
		if ( empty( $data ) ) {
			$autodetect['message'] = _x( 'This Zoom meeting could not be found in the selected account. Please select the associated account below and try again.', 'No Zoom meeting or webinar found for autodetect error message.', 'events-virtual' );

			return $autodetect;
		}

		// Set as virtual event and video source to zoom.
		update_post_meta( $event->ID, Virtual_Events_Meta::$key_virtual, true );
		update_post_meta( $event->ID, Virtual_Events_Meta::$key_video_source, Zoom_Meta::$key_zoom_source_id );
		$event->virtual_video_source = Zoom_Meta::$key_zoom_source_id;

		// Save Zoom data.
		$new_response['body'] = json_encode( $data );
		tribe( Meetings::class )->process_meeting_connection_response( $new_response, $event->ID );

		// Set Zoom as the autodetect source and set up success data and send back to smart url ui.
		update_post_meta( $event->ID, Virtual_Events_Meta::$key_autodetect_source, Zoom_Meta::$key_zoom_source_id );
		$autodetect['detected']          = true;
		$autodetect['autodetect-source'] = Zoom_Meta::$key_zoom_source_id;
		$autodetect['message']           = _x( 'Zoom meeting successfully connected!', 'Zoom meeting/webinar connected success message.', 'events-virtual' );;
		$autodetect['html'] = tribe( Classic_Editor::class )->get_meeting_details( $event, false, $account_id, false );

		return $autodetect;
	}

Top ↑

Changelog

Changelog
Version Description
1.8.0 Introduced.