Tribe__Tickets_Plus__Attendees_List::get_attendees( WP_Post|int $post_id, int $limit = 20 )

Returns an Array ready for printing of the Attendees List


Parameters

$post_id

(WP_Post|int) (Required) Post object or ID.

$limit

(int) (Optional) Limit of attendees to be retrieved.

Default value: 20


Top ↑

Return

(array)


Top ↑

Source

File: src/Tribe/Attendees_List.php

	public function get_attendees( $post_id, $limit = 20 ) {
		$post   = get_post( $post_id );
		$output = [];

		if ( ! $post instanceof WP_Post ) {
			return $output;
		}

		$args = [
			'by' => [
				// Exclude people who have opted out or not specified optout.
				'optout' => 'no_or_none',
			],
		];

		/**
		 * Allow for adjusting the limit of attendees retrieved for the front-end "Who's Attending?" list.
		 *
		 * @since 4.5.5
		 *
		 * @param int $limit Number of attendees to retrieve.
		 */
		$limit = (int) apply_filters( 'tribe_tickets_plus_attendees_list_limit', $limit );

		/**
		 * Allow for adjusting the limit of attendees fetched from the database for the front-end "Who's Attending?" list.
		 *
		 * @since 4.10.5
		 *
		 * @param int $limit_attendees Number of attendees to retrieve. Default is no limit -1.
		 */
		$limit_attendees = (int) apply_filters( 'tribe_tickets_plus_attendees_list_limit_attendees', -1 );

		if ( 0 < $limit_attendees ) {
			$args['per_page'] = $limit_attendees;
		}

		$attendees  = Tribe__Tickets__Tickets::get_event_attendees( $post->ID, $args );
		$emails     = [];
		$has_broken = false;

		// Bail if there are no attendees
		if ( empty( $attendees ) || ! is_array( $attendees ) ) {
			return $output;
		}

		$excluded_statuses = [
			'no',
			'failed',
		];

		foreach ( $attendees as $key => $attendee ) {
			// Skip when we already have another email like this one.
			if ( in_array( $attendee['purchaser_email'], $emails, true ) ) {
				continue;
			}

			// Skip "Failed" orders and folks who've RSVPed as "Not Going".
			if ( in_array( $attendee['order_status'], $excluded_statuses, true ) ) {
				continue;
			}

			if ( ! $has_broken && is_numeric( $limit ) && $limit < $key + 1 ) {
				$has_broken = true;
			}

			$html = '';

			if ( $has_broken ) {
				$html .= '<span class="tribe-attendees-list-hidden">';
			} else {
				$html .= '<span class="tribe-attendees-list-shown">';
			}

			$html .= get_avatar( $attendee['purchaser_email'], 40, '', $attendee['purchaser_name'] );
			$html .= '</span>';

			$emails[] = $attendee['purchaser_email'];

			$output[ $attendee['attendee_id'] ] = $html;
		}

		if ( $has_broken ) {
			$output['show-more'] = sprintf(
				'<a href="#show-all-attendees" data-offset="%1$s" title="%2$s" class="tribe-attendees-list-showall avatar">%3$s</a>',
				esc_attr( $limit ),
				esc_attr__( 'Load all attendees', 'event-tickets-plus' ),
				get_avatar( '', 40, '', esc_attr__( 'Load all attendees', 'event-tickets-plus' ) )
			);
		}

		return $output;
	}

Top ↑

Changelog

Changelog
Version Description
5.10.1 Introduced.