Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * If we assume that the_title() or get_the_title() will be run before the event
- * dates display, but after they have been obtained from tribe_get_end_date(),
- * we should be able to repurpose the_title filter to correct multiday end dates.
- */
- add_filter( 'the_title', 'maybe_correct_end_date' );
- /**
- * Intended to run on a string filter (simply as a convenient point in time to run,
- * it does not modify the value passed in).
- *
- * @param $passthrough
- * @return mixed
- */
- function maybe_correct_end_date( $passthrough ) {
- tribe_correct_end_date();
- return $passthrough;
- }
- /**
- * In The Events Calendar 3.3 some all day events may accidentally have the end date
- * changed to the day before the start date. This function attempts to detect and
- * correct that.
- */
- function tribe_correct_end_date() {
- global $post;
- // We are interested only in all day event posts
- if ( TribeEvents::POSTTYPE !== $post->post_type || ! tribe_event_is_all_day() ) return;
- // Compare start and end dates - we want to catch ones ending before they start
- $start = TribeDateUtils::dateOnly( $post->EventStartDate );
- $end = TribeDateUtils::dateOnly( $post->EventEndDate );
- // If the end date makes sense we're all good, if not make a correction
- if ( $end >= $start ) return;
- $post->EventEndDate = $start;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement