Zoom_Webinar_Helpers::get_webinars( string $label = null, string $option_code = 'ZOOMWEBINARS', array $args = array() )


Parameters Parameters

$label

(Optional)

Default value: null

$option_code

(Optional)

Default value: 'ZOOMWEBINARS'

$args

(Optional)

Default value: array()


Top ↑

Return Return

(mixed)


Source Source

File: src/integrations/zoom-webinar/helpers/zoom-webinar-helpers.php

	public function get_webinars( $label = null, $option_code = 'ZOOMWEBINARS', $args = array() ) {

		if ( ! $this->load_options ) {
			return Automator()->helpers->recipe->build_default_options_array( $label, $option_code );
		}

		if ( ! $label ) {
			$label = __( 'Webinar', 'uncanny-automator' );
		}

		$args = wp_parse_args(
			$args,
			array(
				'uo_include_any' => false,
				'uo_any_label'   => __( 'Any Webinar', 'uncanny-automator' ),
			)
		);

		$token        = key_exists( 'token', $args ) ? $args['token'] : true;
		$is_ajax      = key_exists( 'is_ajax', $args ) ? $args['is_ajax'] : false;
		$target_field = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
		$end_point    = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
		$options      = array();

		if ( Automator()->helpers->recipe->load_helpers ) {
			$client = $this->get_client();

			if ( ! $client || empty( $client['access_token'] ) ) {
				return Automator()->helpers->recipe->build_default_options_array( $label, $option_code );
			}

			// API register call
			$response = wp_remote_post(
				$this->automator_api,
				array(
					'body' =>
						array(
							'action'       => 'get_webinars',
							'access_token' => $client['access_token'],
							'page_number'  => 1,
							'page_size'    => 1000,
							'type'         => 'upcoming',
						),
				)
			);

			$response_code = wp_remote_retrieve_response_code( $response );

			if ( $response_code === 200 ) {

				$response_body = json_decode( wp_remote_retrieve_body( $response ), true );

				if ( count( $response_body['data']['webinars'] ) > 0 ) {

					foreach ( $response_body['data']['webinars'] as $key => $webinar ) {

						$webinar_key                            = (string) $webinar['id'];
						$options[ $webinar_key . '-objectkey' ] = $webinar['topic'];

					}
				}
			}
		}

		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			'supports_tokens' => $token,
			'is_ajax'         => $is_ajax,
			'fill_values_in'  => $target_field,
			'endpoint'        => $end_point,
			'options'         => $options,
		);

		return apply_filters( 'uap_option_zoom_get_webinars', $option );
	}