BakerMan

[TEC] Hide certain events from site guests

Aug 6th, 2012
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. /**
  2.  * Filters the list of events. Any events belonging to $eventCategory
  3.  * will be removed if the user is not logged in.
  4.  *
  5.  * @param array $events
  6.  * @return array
  7.  */
  8. function protect_marked_events($events) {
  9.     // If the user is logged in we need take no further action
  10.     if (is_user_logged_in()) return $events;
  11.  
  12.     // The category name or slug we wish to protect
  13.     $eventCategory = 'heavy-metal';
  14.  
  15.     // Filter out any events that belong to the above category
  16.     foreach ($events as $id => $event)
  17.         if (has_term($eventCategory, TribeEvents::TAXONOMY, $event->ID))
  18.             unset($events[$id]);
  19.  
  20.     // Return our modified list of events
  21.     return $events;
  22. }
  23.  
  24. add_filter('tribe_get_events', 'protect_marked_events');
Advertisement
Add Comment
Please, Sign In to add comment