SHARE
TWEET

Custom event attribute check http

eventsmanager Oct 17th, 2017 191 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  this snippet will check if custom event attribute contains http:// or not
  3.  
  4.  Sample Usage:
  5.  
  6.  {is_not_valid_url}
  7.  <a href="http://#_ATT{test}">#_ATT{test}</a>
  8.  {/is_not_valid_url}
  9.  
  10.  {is_valid_url}
  11.  <a href="#_ATT{test}">#_ATT{test}</a>
  12.  {/is_valid_url}
  13.  
  14.   **Replace "test" with your custom event attribute
  15.  
  16.  */
  17. function filterEventOutputCondition($replacement, $condition, $match, $EM_Event){
  18.     if (is_object($EM_Event)) {
  19.  
  20.         switch ($condition) {
  21.  
  22.  
  23.             case 'is_valid_url':
  24.  
  25.                 if (is_array($EM_Event->event_attributes) &&  substr($EM_Event->event_attributes['test'], 0, 7) == 'http://'  )
  26.                     $replacement = preg_replace('/\{\/?is_valid_url\}/', '', $match);
  27.                 else
  28.                     $replacement = '';
  29.                 break;
  30.  
  31.             case 'is_not_valid_url':
  32.  
  33.                 if (is_array($EM_Event->event_attributes) &&  substr($EM_Event->event_attributes['test'], 0, 7) != 'http://' )
  34.                     $replacement = preg_replace('/\{\/?is_not_valid_url\}/', '', $match);
  35.                 else
  36.                     $replacement = '';
  37.                 break;
  38.  
  39.         }
  40.  
  41.     }
  42.  
  43.     return $replacement;
  44. }
  45.  
  46. add_filter('em_event_output_condition', 'filterEventOutputCondition', 100, 4);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top