Advertisement
BakerMan

Untitled

Feb 26th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * The Events Calendar inserts "spoof" posts when the template_include hook fires.
  3.  * We'll hook into that also, but later on, to remove the unnecessary second post.
  4.  */
  5. add_filter('template_include', 'correctTribePostSpoofing', 50);
  6.  
  7. /**
  8.  * Checks if post spoofing has happened and, if so, leaves only one "spoof post"
  9.  * in place.
  10.  *
  11.  * @param $unused (pass-through var)
  12.  * @return mixed ($unused)
  13.  */
  14. function correctTribePostSpoofing($unused) {
  15.     global $posts;
  16.  
  17.     // A key indicator that spoofing took place is a post count greater than 1
  18.     if (count($posts) < 2) return $unused;
  19.  
  20.     // Inspect the first post: does it look like a spoof?
  21.     if ($posts[0]->ID === 1 and empty($posts[0]->guid) and $posts[0]->post_type === TribeEvents::POSTTYPE) {
  22.         // Discard all but the first post
  23.         $posts = array_slice($posts, 0, 1);
  24.     }
  25.  
  26.     // We don't actually want to change the template selection
  27.     return $unused;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement