array( 'min_range' => 1, 'max_range' => 12, ), ) ); if ( false === $month_input || null === $month_input ) { $month_input = filter_input( INPUT_GET, 'month', FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1, 'max_range' => 12, ), ) ); } $year_input = filter_input( INPUT_GET, $year_param, FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1970, 'max_range' => 2200, ), ) ); if ( false === $year_input || null === $year_input ) { $year_input = filter_input( INPUT_GET, 'year', FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1970, 'max_range' => 2200, ), ) ); } $cur_month = ( false !== $month_input && null !== $month_input ) ? (int) $month_input : (int) wp_date( 'n' ); $cur_year = ( false !== $year_input && null !== $year_input ) ? (int) $year_input : (int) wp_date( 'Y' ); $tz = wp_timezone(); $start_of_week = (int) get_option( 'start_of_week', 1 ); if ( $start_of_week < 0 || $start_of_week > 6 ) { $start_of_week = 0; } $month = aa_events_calendar_month( $cur_year, $cur_month, $start_of_week ); $weekdays = array( array( 'abbr' => __( 'Sun', 'aa-events' ), 'label' => __( 'Sunday', 'aa-events' ), ), array( 'abbr' => __( 'Mon', 'aa-events' ), 'label' => __( 'Monday', 'aa-events' ), ), array( 'abbr' => __( 'Tue', 'aa-events' ), 'label' => __( 'Tuesday', 'aa-events' ), ), array( 'abbr' => __( 'Wed', 'aa-events' ), 'label' => __( 'Wednesday', 'aa-events' ), ), array( 'abbr' => __( 'Thu', 'aa-events' ), 'label' => __( 'Thursday', 'aa-events' ), ), array( 'abbr' => __( 'Fri', 'aa-events' ), 'label' => __( 'Friday', 'aa-events' ), ), array( 'abbr' => __( 'Sat', 'aa-events' ), 'label' => __( 'Saturday', 'aa-events' ), ), ); $ordered_weekdays = array_merge( array_slice( $weekdays, $start_of_week ), array_slice( $weekdays, 0, $start_of_week ) ); $calendar_occurrences = array(); $events = new WP_Query( array( 'post_type' => 'event', 'posts_per_page' => -1, 'post_status' => 'publish', 'fields' => 'ids', 'no_found_rows' => true, 'update_post_meta_cache' => true, 'update_post_term_cache' => false, ) ); foreach ( $events->posts as $event_id ) { $event_title = get_the_title( $event_id ); $event_permalink = get_permalink( $event_id ); foreach ( aa_events_get_occurrences( $event_id ) as $occurrence_index => $occurrence ) { if ( ! is_array( $occurrence ) || ! aa_events_occurrence_intersects_range( $occurrence, $month['month_start'], $month['month_end'] ) ) { continue; } $occurrence['post_id'] = (int) $event_id; $occurrence['title'] = $event_title; $occurrence['permalink'] = $event_permalink; $occurrence['calendar_occurrence_key'] = aa_events_calendar_occurrence_key( $event_id, $occurrence_index ); $calendar_occurrences[] = $occurrence; } } $calendar_occurrences = aa_events_sort_calendar_occurrences( $calendar_occurrences ); $calendar_weeks = aa_events_group_calendar_weeks( $calendar_occurrences, $month ); $today = new DateTimeImmutable( wp_date( 'Y-m-d' ) . ' 00:00:00', $tz ); $prev = $month['month_start']->modify( '-1 month' ); $next = $month['month_start']->modify( '+1 month' ); $heading_id = wp_unique_id( 'aa-events-calendar-heading-' ); $agenda_heading_id = wp_unique_id( 'aa-events-calendar-agenda-heading-' ); $month_label = wp_date( 'F Y', $month['month_start']->getTimestamp(), $tz ); $current_url = add_query_arg( array() ); $calendar_base_url = remove_query_arg( array( $month_param, $year_param, 'month', 'year' ), $current_url ); $calendar_url = static function ( DateTimeImmutable $date ) use ( $calendar_base_url, $month_param, $year_param ) { return add_query_arg( array( $month_param => (int) $date->format( 'n' ), $year_param => (int) $date->format( 'Y' ), ), $calendar_base_url ); }; ?>