Home › Forums › Calendar Products › Events Calendar PRO › Hide/show events to relevant roles
- This topic has 1 reply, 2 voices, and was last updated 12 years, 3 months ago by
Brook.
-
AuthorPosts
-
January 9, 2014 at 12:57 am #89132
elliottrichmond
ParticipantI have a site using Events Calendar Pro and with multiple roles eg RoleA, RoleB, RoleC etc
I would like to categories Events to only show them to certain Roles but have public Events also for instance:
non registered can see all Public events
RoleC can see category events for Public, RoleA, RoleB and RoleC
RoleB can category events for Public, RoleA and RoleB only
RoleA can see category events for Public, RoleA only
I hope this makes sense, I can see there is a hacked functions to remove events for non registered users but I’m not sure where to iterate a conditional to check for roles and event categories:
// Let’s restrict events to logged in users only
add_filter(‘pre_get_posts’, ‘restrict_events’, 100);function restrict_events($query) {
// Do nothing if the current user is logged in
$user = wp_get_current_user();
if (isset($user->ID) and $user->ID > 0) return;// We are only interested in event queries
if (!isset($query->query_vars[‘post_type’]) or $query->query_vars[‘post_type’] !== TribeEvents::POSTTYPE) return;// Remove the results
add_filter(‘the_posts’, ‘wipeout_posts’, 100);}
function wipeout_posts($posts) {
// Tidy up first of all
remove_filter(‘the_posts’, ‘wipeout_posts’, 100);// Return an empty array – but we could iterate through and be selective about what is removed,
// or inject a stub post or even redirect to a “Sorry you must be logged in” page
return array();
}January 13, 2014 at 7:46 am #91197Brook
ParticipantHowdy elliottrichmond,
That make complete sense. I believe this snippet should really help you. It excludes events from the Events Category that has the slug “exclude-slug” for everyone except administrators. You can modify this using your custom roles, and add in more roles/cats to exclude within that one function.
I threw this together pretty quick and am not able to test it much. I just wanted to get you started in the right direction. You should definitely thoroughly test your site to make sure this does all you need it to, and then add or modify logic where appropriate.
Please let me know if that helps, or it the code needs any extra explaining. Thank you!
– Brook
-
AuthorPosts
- The topic ‘Hide/show events to relevant roles’ is closed to new replies.
