Api::fetch_users()

Get the List of all Users


Return

(array) An array of users from the Zoom API.


Top ↑

Source

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

	public function fetch_users() {
		if ( ! $this->get_token_authorization_header() ) {
			return [];
		}

		$args = [
			'page_size'   => 300,
			'page_number' => 1,
		];

		/**
		 * Filters the arguments for fetching users.
		 *
		 * @since 1.8.0
		 * @since 1.8.2 Correct duplicated hook name.
		 *
		 * @param array<string|string> $args The default arguments to fetch users.
		 */
		$args = (array) apply_filters( 'tec_events_virtual_zoom_user_get_arguments', $args );

		$page_query_atts = [
			'start' => 1,
			'limit' => 20,
		];
		/**
		 * Filters the attributes for getting all of an account's users with pagination support.
		 *
		 * @since 1.8.2
		 *
		 * @param array<string|string> $args The default attributes to fetch users through pagination.
		 */
		$page_query_atts = (array) apply_filters( 'tec_events_virtual_zoom_user_pagination_attributes', $page_query_atts );

		// Get the initial page of users.
		$users = $this->fetch_users_with_args( $args );

		// Support Pagination of users for accounts with over 300 users.
		if ( isset( $users['page_count'] ) && $users['page_count'] > $page_query_atts['start'] ) {
			// Use the filtered default arguments for the base of pagination queries.
			$page_args = $args;

			// Number of pages to get. If no limit, do the total number of pages.
			// If there is a limit, do the smaller amount between the total number of pages and the limit.
			$pages = $page_query_atts['limit'] ? min( $page_query_atts['start'] + $page_query_atts['limit'], $users['page_count'] + 1 ) : $users['page_count'] + 1;

			for ( $i = $page_query_atts['start'] + 1; $i < $pages; $i ++ ) {
				$page_args['page_number'] = $i;

				$page_of_users = $this->fetch_users_with_args( $page_args );

				if ( ! isset( $page_of_users['users'] ) ) {
					continue;
				}

				// merge in the current page of users to the previous.
				$users['users'] = array_merge( $users['users'], $page_of_users['users'] );
			}
		}

		return $users;
	}

Top ↑

Changelog

Changelog
Version Description
1.8.2 - Add pagination support.
1.4.0 Introduced.