Last active
March 31, 2021 16:10
-
-
Save skyshab/7d6e5a83e39778e4570a87d79e89b247 to your computer and use it in GitHub Desktop.
Allow all IAC attendees to view protected content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Allow all IAC attendees to view protected content. | |
add_filter( 'tribe_tickets_shortcode_can_see_content', static function( $can_see_content, $filter_args ) { | |
// Only run our logic below if the user is logged in or if they cannot currently see the content. | |
if ( ! is_user_logged_in() || $can_see_content ) { | |
return $can_see_content; | |
} | |
// Get the logged in user. | |
$current_user = wp_get_current_user(); | |
// Define query args as empty array by default. | |
$args = []; | |
// If specific tickets are defined in the shortcode, add query args. | |
if ( isset( $filter_args['ticket_ids'] ) && ! empty( $filter_args['ticket_ids'] ) ) { | |
$args = [ | |
'by' => [ | |
'ticket' => $filter_args['ticket_ids'] | |
] | |
]; | |
} | |
// Get a list of attendees. | |
$attendees = Tribe__Tickets__Tickets::get_event_attendees_by_args( $filter_args['post_id'], $args ); | |
// Loop through the attendees. | |
foreach( $attendees['attendees'] as $attendee ) { | |
// If current user is one of the attendees, show protected content. | |
if( isset( $attendee['holder_email'] ) && $current_user->user_email === $attendee['holder_email'] ) { | |
return true; | |
} | |
} | |
// No attendee matches. | |
return false; | |
}, 100, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment