<?php
/**
* Event Tickets - Remove Checked-In Attendees from wp-admin table
*
* Can help the Attendees List table screen's performance after some of the attendees have been checked in.
* Modified from Barry's original version on May 24, 2017, to support all ticket types.
* Ideas: only do this if a specific query parameter exists, or only do this if a button is clicked (but then the point about this being a performance improvement would no longer be valid)
*
* @param $query
*
* @link https://gist.github.com/cliffordp/d1643e84bb41dda0a5c86100ae52b07f
*/
function attendee_screen_filter_out_checked_in_attendees( $query ) {
$attendee_post_types = array(
'tribe_rsvp_attendees',
'tribe_wooticket',
'tribe_eddticket',
'tribe_wpecticket',
'tribe_shoppticket',
);
if ( ! in_array( $query->get( 'post_type' ), $attendee_post_types ) ) {
return;
}
// Reform meta query - filter out those already checked in
$meta_query = array(
array(
'key' => $query->get( 'meta_key' ),
'value' => $query->get( 'meta_value' ),
),
// RSVP
array(
'key' => '_tribe_rsvp_checkedin',
'compare' => 'NOT EXISTS',
),
// WooCommerce
array(
'key' => '_tribe_wooticket_checkedin',
'compare' => 'NOT EXISTS',
),
// EDD
array(
'key' => '_tribe_eddticket_checkedin',
'compare' => 'NOT EXISTS',
),
// WPEC
array(
'key' => '_tribe_wpecticket_checkedin',
'compare' => 'NOT EXISTS',
),
// Shopp
array(
'key' => '_tribe_shoppticket_checkedin',
'compare' => 'NOT EXISTS',
),
);
// Clear out previous meta query
$query->set( 'meta_key', '' );
$query->set( 'meta_value', '' );
// Update
$query->set( 'meta_query', $meta_query );
}
function attendee_screen_remove_checked_in_attendees_setup() {
add_action( 'pre_get_posts', 'attendee_screen_filter_out_checked_in_attendees', 200 );
}
function attendee_screen_remove_checked_in_attendees_teardown( $passthru ) {
remove_action( 'pre_get_posts', 'attendee_screen_filter_out_checked_in_attendees', 200 );
return $passthru;
}
add_action( 'tribe_tickets_attendees_page_inside', 'attendee_screen_remove_checked_in_attendees_setup' );
add_filter( 'tribe_tickets_event_attendees', 'attendee_screen_remove_checked_in_attendees_teardown' );