Tribe__Events__Community__Tickets__Main::user_has_read_private_shop_orders( array $all_caps, array $caps, array $args )

Alter the read_private_shop_orders cap if the order contains a ticket that is attached to an event created by the current user


Parameters #

$all_caps

(array) (Required) User capabilities

$caps

(array) (Required) Caps being checked

$args

(array) (Required) Additional user_cap args


Top ↑

Return #

(array)


Top ↑

Source #

File: src/Tribe/Main.php

	public function user_has_read_private_shop_orders( $all_caps, $caps, $args ) {
		// Bail if there isn't a cap or user_id
		if ( empty( $caps[0] ) || empty( $args[1] ) ) {
			return $all_caps;
		}

		$cap = $caps[0];
		$user_id = absint( $args[1] );

		// Bail if this isn't the cap we care about
		if ( 'read_private_shop_orders' !== $cap ) {
			return $all_caps;
		}

		// If there isn't a post id for the order, bail
		if ( empty( $args[2] ) ) {
			return $all_caps;
		}

		$order_id = absint( $args[2] );

		$query_args = array(
			'post_type' => 'tribe_wooticket',
			'post_status' => 'publish',
			'meta_key' => '_tribe_wooticket_order',
			'meta_value' => $order_id,
		);

		$posts = get_posts( $query_args );
		foreach ( $posts as $post ) {
			$event_id = get_post_meta( $post->ID, '_tribe_wooticket_event', true );
			$event = get_post( $event_id );
			if ( $user_id === (int) $event->post_author ) {
				$all_caps[ $cap ] = true;
				return $all_caps;
			}
		}

		return $all_caps;
	}