Advertisement
BakerMan

Potentially correct all day event end date (front end)

Dec 19th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  1. /**
  2.  * If we assume that the_title() or get_the_title() will be run before the event
  3.  * dates display, but after they have been obtained from tribe_get_end_date(),
  4.  * we should be able to repurpose the_title filter to correct multiday end dates.
  5.  */
  6. add_filter( 'the_title', 'maybe_correct_end_date' );
  7.  
  8. /**
  9.  * Intended to run on a string filter (simply as a convenient point in time to run,
  10.  * it does not modify the value passed in).
  11.  *
  12.  * @param $passthrough
  13.  * @return mixed
  14.  */
  15. function maybe_correct_end_date( $passthrough ) {
  16.     tribe_correct_end_date();
  17.     return $passthrough;
  18. }
  19.  
  20. /**
  21.  * In The Events Calendar 3.3 some all day events may accidentally have the end date
  22.  * changed to the day before the start date. This function attempts to detect and
  23.  * correct that.
  24.  */
  25. function tribe_correct_end_date() {
  26.     global $post;
  27.  
  28.     // We are interested only in all day event posts
  29.     if ( TribeEvents::POSTTYPE !== $post->post_type || ! tribe_event_is_all_day() ) return;
  30.  
  31.     // Compare start and end dates - we want to catch ones ending before they start
  32.     $start = TribeDateUtils::dateOnly( $post->EventStartDate );
  33.     $end = TribeDateUtils::dateOnly( $post->EventEndDate );
  34.  
  35.     // If the end date makes sense we're all good, if not make a correction
  36.     if ( $end >= $start ) return;
  37.     $post->EventEndDate = $start;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement