diff --git a/README.md b/README.md index 7b0b30a..dc88371 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ An approachable, theme‑friendly events plugin for WordPress. It adds an `Event - Archive: `/events` uses `templates/archive-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 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.) --- diff --git a/includes/class-aa-events.php b/includes/class-aa-events.php index 6e90fcb..f8261a1 100644 --- a/includes/class-aa-events.php +++ b/includes/class-aa-events.php @@ -63,6 +63,7 @@ final class AA_Events { add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); // Ensure the active theme supports thumbnails for the event post type. 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. } + + /** + * 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; + } } diff --git a/templates/calendar.php b/templates/calendar.php index fb38f25..41cdbe8 100644 --- a/templates/calendar.php +++ b/templates/calendar.php @@ -9,32 +9,65 @@ if ( ! defined( 'ABSPATH' ) ) { 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) $month_input = filter_input( - INPUT_GET, - 'month', - FILTER_VALIDATE_INT, - array( - 'options' => array( - 'min_range' => 1, - 'max_range' => 12, - ), - ) + INPUT_GET, + $month_param, + FILTER_VALIDATE_INT, + array( + 'options' => array( + 'min_range' => 1, + 'max_range' => 12, + ), + ) ); +// 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( - INPUT_GET, - 'year', - FILTER_VALIDATE_INT, - array( - 'options' => array( - // Choose a sane range for years. - 'min_range' => 1970, - 'max_range' => 2200, - ), - ) + INPUT_GET, + $year_param, + FILTER_VALIDATE_INT, + array( + 'options' => array( + // Choose a sane range for years. + 'min_range' => 1970, + 'max_range' => 2200, + ), + ) ); +// 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' ); $curYear = ( false !== $year_input && null !== $year_input ) ? (int) $year_input : (int) wp_date( 'Y' ); @@ -139,11 +172,11 @@ $calendarOutput = preg_replace( ?>
- +
" - >« + href="?aa_month=&aa_year=" + aria-label="" + >« -

+

- " - > » + " + > »