eventsmanager

Custom conditional placeholder for event categories

Nov 19th, 2014
419
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. New conditional placeholder for events category has events
  3.  
  4. USAGE:
  5. <ul>
  6. [categories_list hide_empty=1]
  7. {has_upcoming_events}
  8. <li>#_CATEGORYLINK</li>
  9. {/has_upcoming_events}
  10. [/categories_list]
  11. </ul>
  12.  
  13. */
  14. add_action('em_category_output_condition', 'my_em_category_output_condition', 1, 4);
  15. function my_em_category_output_condition($replacement, $condition, $match, $EM_Category){
  16. if( is_object($EM_Category) && preg_match('/^has_upcoming_events$/',$condition, $matches) ){
  17. if( EM_Events::count(array('scope'=>'future','category'=>$EM_Category->term_id)) > 0 ){
  18. $replacement = preg_replace("/\{\/?$condition\}/", '', $match);
  19. }else{
  20. $replacement = '';
  21. }
  22. }
  23. return $replacement;
  24. }
RAW Paste Data