Last active
August 29, 2015 14:15
-
-
Save stephenharris/03384d1382a88b39e6c2 to your computer and use it in GitHub Desktop.
Excludes bookings for other organisers from Event Organiser's Pro bookings admin page
This file contains hidden or 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 | |
/** | |
* Excludes bookings for other organisers from Event Organiser's Pro bookings admin page | |
* Applies only to users who do not have permission to manage others' bookings | |
* (see Settings > Event Organiser > Permissions). | |
*/ | |
function sod_eo_pro_bookings_for_event_organiser( $clauses, $query ){ | |
global $wpdb; | |
$organiser = get_current_user_id(); | |
if( current_user_can( 'manage_others_eo_bookings' ) || !$organiser || 'eo_booking' != $query->get( 'post_type' ) ){ | |
return $clauses; | |
} | |
//Check which screen we're on | |
$screen = get_current_screen(); | |
if( !is_admin() || !$screen || 'event_page_bookings' != $screen->id ){ | |
return $clauses; | |
} | |
$postalias = "{$wpdb->posts}eo"; | |
$postmetaalias = "{$wpdb->postmeta}eo"; | |
$clauses['join'] .= "INNER JOIN {$wpdb->postmeta} AS {$postmetaalias} | |
ON {$wpdb->posts}.ID = {$postmetaalias}.post_id | |
INNER JOIN {$wpdb->posts} AS {$postalias} | |
ON {$postalias}.ID = {$postmetaalias}.meta_value"; | |
$clauses['where'] .= $wpdb->prepare( | |
" AND {$postmetaalias}.meta_key = '_eo_booking_event_id' | |
AND {$postalias}.post_author = %d", | |
$organiser | |
); | |
return $clauses; | |
} | |
add_filter( 'posts_clauses', 'sod_eo_pro_bookings_for_event_organiser', 10, 2 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment