Advertisement
Guest User

Events Manager conditional placeholders for custom attribute

a guest
May 15th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. /**
  2. * add some conditional output conditions for Events Manager
  3. * @param string $replacement
  4. * @param string $condition
  5. * @param string $match
  6. * @param object $EM_Event
  7. * @return string
  8. */
  9. function filterEventOutputCondition($replacement, $condition, $match, $EM_Event){
  10.     if (is_object($EM_Event)) {
  11.  
  12.         switch ($condition) {
  13.  
  14.             // replace LF with HTML line breaks
  15.             case 'nl2br':
  16.                 // remove conditional
  17.                 $replacement = preg_replace('/\{\/?nl2br\}/', '', $match);
  18.                 // process any placeholders and replace LF
  19.                 $replacement = nl2br($EM_Event->output($replacement));
  20.                 break;
  21.  
  22.             // #_ATT{Website}
  23.             case 'has_att_yournewattribute':
  24.                 if (is_array($EM_Event->event_attributes) && !empty($EM_Event->event_attributes['yournewattribute']))
  25.                     $replacement = preg_replace('/\{\/?has_att_yournewattribute\}/', '', $match);
  26.                 else
  27.                     $replacement = '';
  28.                 break;
  29.  
  30.         }
  31.  
  32.     }
  33.  
  34.     return $replacement;
  35. }
  36.  
  37. add_filter('em_event_output_condition', 'filterEventOutputCondition', 10, 4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement