=== Calendar Crawl Guard ===
Contributors: web321
Author: Shawn DeWolfe, Web321 Marketing Ltd.
Author URI: https://web321.co/
Donate link: https://www.paypal.com/paypalme/web321co/10
Tags: the events calendar, all-in-one event calendar, crawl, seo, canonical
Requires at least: 6.0
Tested up to: 6.8
Requires PHP: 8.0
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Tames the near-infinite URL space generated by The Events Calendar and the All-in-One Event Calendar. Redirects, terminates, or feeds authority to a short list of canonical URLs.

== Description ==

Event calendars let crawlers walk an effectively infinite set of date-parameterized URLs (every view, every date, always with prev/next links). Each is a dynamic, usually empty page that fires PHP and queries the database — wasting bandwidth, server load, and crawl budget. Calendar Crawl Guard supports both **The Events Calendar** and the **All-in-One Event Calendar** (Timely).

This plugin intercepts those requests at `parse_request`, *before* the main query runs, and applies one of three responses:

* **301 redirect** for alternate-but-equivalent paths (duplicate query strings, alternate presentation views, recurring-event instance permalinks).
* **410 Gone** (or 404) for calendar dates outside a configurable window (default: current month +/- 6 months).
* **403 Forbidden** (optional) for known bad bots, matched by user-agent.

It also feeds indexing authority to your canonical pages with canonical tags and `noindex` hints on non-primary views, and can add targeted `robots.txt` rules for feeds and filter parameters.

A built-in "Test a URL" tool on the settings page previews the exact verdict for any calendar URL using the same engine that runs live. Each calendar is detected automatically and its native views are normalized to a common vocabulary, so one set of settings governs both.

== Features ==

* Early interception (before the expensive main query) for real load reduction.
* Configurable canonical window in months.
* Per-class response selection: 301 / 404 / 410 / 403.
* Supports The Events Calendar and the All-in-One Event Calendar via a provider layer.
* Reads The Events Calendar's configurable archive and single slugs (never hardcoded).
* Cache-Control / Expires headers on rejected responses so a front cache serves repeats.
* Leverages The Events Calendar's own `tribe_events_add_no_index_meta` filter.
* WP-CLI commands: bulk URL tester (wp ccg test) and window-boundary scanner (wp ccg scan).
* Optional MySQL logging with a 24-hour summary.
* Skips admin, AJAX, cron, REST, and logged-in users by default.
* Auto-generated documentation page; View/Edit Docs buttons on the settings screen.

== Installation ==

1. Upload the `calendar-crawl-guard` folder to `/wp-content/plugins/`.
2. Activate the plugin through the Plugins screen.
3. Go to Settings -> Calendar Crawl Guard, confirm the window and policy, and use the Test a URL tool before going live.

== Frequently Asked Questions ==

= Will this slow my site down? =
No — rejected requests exit before the main query and template render, so they cost far less than a normal page load.

= Why 410 instead of 404 for old dates? =
410 Gone is a permanent signal: crawlers drop the URL and stop revisiting.

= Does it touch single event pages? =
No. Single events are always allowed. Only recurring-event instance permalinks fold back to the base event, and only if enabled.

== Changelog ==

= 1.0.0 =
* Initial release.
