🐞 fix: Update to correct year switch navigation bug
This commit is contained in:
@@ -64,7 +64,7 @@ An approachable, theme‑friendly events plugin for WordPress. It adds an `Event
|
|||||||
- Archive: `/events` uses `templates/archive-event.php`.
|
- Archive: `/events` uses `templates/archive-event.php`.
|
||||||
- Single: each event uses `templates/single-event.php`.
|
- Single: each event uses `templates/single-event.php`.
|
||||||
- Calendar page: Page → Template → “Events Calendar” renders `templates/template-calendar.php` which includes `templates/calendar.php`.
|
- Calendar page: Page → Template → “Events Calendar” renders `templates/template-calendar.php` which includes `templates/calendar.php`.
|
||||||
- Calendar navigation: query args `?month=MM&year=YYYY` change the visible month; “Today” jumps back to the current month.
|
- Calendar navigation: query args `?aa_month=MM&aa_year=YYYY` change the visible month; “Today” jumps back to the current month. (`month`/`year` still work for legacy links.)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ final class AA_Events {
|
|||||||
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
|
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
|
||||||
// Ensure the active theme supports thumbnails for the event post type.
|
// Ensure the active theme supports thumbnails for the event post type.
|
||||||
add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) );
|
add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) );
|
||||||
|
add_filter( 'query_vars', array( $this, 'register_calendar_query_vars' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,4 +126,17 @@ final class AA_Events {
|
|||||||
}
|
}
|
||||||
// If theme support is boolean true (all types), nothing to do.
|
// If theme support is boolean true (all types), nothing to do.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow custom AA Events calendar query vars to persist through canonical redirects.
|
||||||
|
*
|
||||||
|
* @param array $vars Public query vars.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function register_calendar_query_vars( $vars ) {
|
||||||
|
$vars[] = 'aa_month';
|
||||||
|
$vars[] = 'aa_year';
|
||||||
|
|
||||||
|
return $vars;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+38
-5
@@ -9,10 +9,14 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
exit; // Exit if accessed directly.
|
exit; // Exit if accessed directly.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use custom query vars (avoid WP date archive/canonical behavior on `year`)
|
||||||
|
$month_param = 'aa_month';
|
||||||
|
$year_param = 'aa_year';
|
||||||
|
|
||||||
// Get current month and year (read-only query vars; validate instead of nonce)
|
// Get current month and year (read-only query vars; validate instead of nonce)
|
||||||
$month_input = filter_input(
|
$month_input = filter_input(
|
||||||
INPUT_GET,
|
INPUT_GET,
|
||||||
'month',
|
$month_param,
|
||||||
FILTER_VALIDATE_INT,
|
FILTER_VALIDATE_INT,
|
||||||
array(
|
array(
|
||||||
'options' => array(
|
'options' => array(
|
||||||
@@ -22,9 +26,24 @@ $month_input = filter_input(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Back-compat for legacy `month` query arg if present.
|
||||||
|
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(
|
$year_input = filter_input(
|
||||||
INPUT_GET,
|
INPUT_GET,
|
||||||
'year',
|
$year_param,
|
||||||
FILTER_VALIDATE_INT,
|
FILTER_VALIDATE_INT,
|
||||||
array(
|
array(
|
||||||
'options' => array(
|
'options' => array(
|
||||||
@@ -35,6 +54,20 @@ $year_input = filter_input(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Back-compat for legacy `year` query arg if present.
|
||||||
|
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,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
$curMonth = ( false !== $month_input && null !== $month_input ) ? (int) $month_input : (int) wp_date( 'n' );
|
$curMonth = ( false !== $month_input && null !== $month_input ) ? (int) $month_input : (int) wp_date( 'n' );
|
||||||
$curYear = ( false !== $year_input && null !== $year_input ) ? (int) $year_input : (int) wp_date( 'Y' );
|
$curYear = ( false !== $year_input && null !== $year_input ) ? (int) $year_input : (int) wp_date( 'Y' );
|
||||||
|
|
||||||
@@ -140,7 +173,7 @@ $calendarOutput = preg_replace(
|
|||||||
|
|
||||||
<div class="aa-events-calendar-wrap container">
|
<div class="aa-events-calendar-wrap container">
|
||||||
<div class="aa-events-calendar-today-link" style="margin-bottom: 1em;">
|
<div class="aa-events-calendar-today-link" style="margin-bottom: 1em;">
|
||||||
<a href="?month=<?php echo esc_attr( $todayMonth ); ?>&year=<?php echo esc_attr( $todayYear ); ?>" class="aa-events-calendar-today-btn">
|
<a href="?aa_month=<?php echo esc_attr( $todayMonth ); ?>&aa_year=<?php echo esc_attr( $todayYear ); ?>" class="aa-events-calendar-today-btn">
|
||||||
<?php esc_html_e( 'Today', 'aa-events' ); ?>
|
<?php esc_html_e( 'Today', 'aa-events' ); ?>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -154,14 +187,14 @@ $calendarOutput = preg_replace(
|
|||||||
$nextMonthName = wp_date( 'F', $next_ts );
|
$nextMonthName = wp_date( 'F', $next_ts );
|
||||||
?>
|
?>
|
||||||
<a
|
<a
|
||||||
href="?month=<?php echo esc_attr( $prev_month ); ?>&year=<?php echo esc_attr( $prev_year ); ?>"
|
href="?aa_month=<?php echo esc_attr( $prev_month ); ?>&aa_year=<?php echo esc_attr( $prev_year ); ?>"
|
||||||
aria-label="<?php echo esc_attr( "Go to $prevMonthName $prev_year" ); ?>"
|
aria-label="<?php echo esc_attr( "Go to $prevMonthName $prev_year" ); ?>"
|
||||||
>« <?php esc_html_e( 'Previous Month', 'aa-events' ); ?></a>
|
>« <?php esc_html_e( 'Previous Month', 'aa-events' ); ?></a>
|
||||||
|
|
||||||
<h2><?php echo esc_html( wp_date( 'F Y', $first_ts ) ); ?></h2>
|
<h2><?php echo esc_html( wp_date( 'F Y', $first_ts ) ); ?></h2>
|
||||||
|
|
||||||
<a
|
<a
|
||||||
href="?month=<?php echo esc_attr( $next_month ); ?>&year=<?php echo esc_attr( $next_year ); ?>"
|
href="?aa_month=<?php echo esc_attr( $next_month ); ?>&aa_year=<?php echo esc_attr( $next_year ); ?>"
|
||||||
aria-label="<?php echo esc_attr( "Go to $nextMonthName $next_year" ); ?>"
|
aria-label="<?php echo esc_attr( "Go to $nextMonthName $next_year" ); ?>"
|
||||||
><?php esc_html_e( 'Next Month', 'aa-events' ); ?> »</a>
|
><?php esc_html_e( 'Next Month', 'aa-events' ); ?> »</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user