Tribe__Events__Dates__Known_Range::update_known_range( int $event_id )
Intelligently updates our record of the earliest start date/latest event date in the system. If the existing earliest/latest values have not been superseded by the new post’s start/end date then no update takes place.
Contents
This is deliberately hooked into save_post, rather than save_post_tribe_events, to avoid issues where the removal/restoration of hooks within addEventMeta() etc might stop this method from actually being called (relates to a core WP bug).
Parameters
- $event_id
-
(int) (Required)
Source
File: src/Tribe/Dates/Known_Range.php
public function update_known_range( $event_id ) {
$is_earliest_date_marker = in_array( $event_id, tribe_get_option( 'earliest_date_markers', array() ) );
$is_latest_date_marker = in_array( $event_id, tribe_get_option( 'latest_date_markers', array() ) );
if ( $is_earliest_date_marker || $is_latest_date_marker ) {
$this->rebuild_known_range();
return;
}
$current_min = tribe_events_earliest_date();
$current_max = tribe_events_latest_date();
$event_start = tribe_get_start_date( $event_id, false, Tribe__Date_Utils::DBDATETIMEFORMAT );
$event_end = tribe_get_end_date( $event_id, false, Tribe__Date_Utils::DBDATETIMEFORMAT );
if ( $current_min > $event_start ) {
$this->rebuild_known_range();
tribe_update_option( 'earliest_date', $event_start );
}
if ( $current_max < $event_end ) {
$this->rebuild_known_range();
tribe_update_option( 'latest_date', $event_end );
}
}