=== Cron Guard ===
Contributors: chillichalli, oddlogix
Tags: cron, wp-cron, monitoring, scheduled tasks, cron jobs
Requires at least: 5.0
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.5.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Monitor WP Cron health, detect stalled or missed cron jobs, and get actionable guidance to fix issues.

== Description ==

Cron Guard is a comprehensive monitoring solution for WordPress cron jobs. It helps you detect when cron jobs are failing, identify stalled or missed scheduled tasks, and provides host-specific instructions to fix common issues.

= Features =

* **Health Monitoring** - Detect if WP Cron has executed within a configurable time threshold
* **Scheduled Events List** - View all scheduled cron hooks with last run time, next run time, and interval
* **Overdue Detection** - Flag overdue or stalled hooks with clear visual indicators
* **Rolling Log** - Lightweight logging of cron execution events
* **Admin Dashboard** - Clear, non-technical UI showing overall health status and detailed hook information
* **Fix Assistant** - Host-specific instructions for setting up real cron jobs
* **Admin Bar Indicator** - Quick status indicator in the WordPress admin bar

= Premium Features =

* **Email Alerts** - Receive notifications when cron is stalled or repeatedly missing schedules
* **Webhook Alerts** - Send alerts to any webhook endpoint
* **Slack Integration** - Formatted Slack notifications with action buttons
* **Discord Integration** - Formatted Discord notifications with embeds
* **Verification System** - Test and confirm real cron execution
* **Advanced Diagnostics** - Deep system analysis and troubleshooting
* **Agency Dashboard** - Monitor cron health across all your client sites from one screen, with per-site uptime trends (Agency & Agency Plus)
* **White-Label Client Reports** - Branded, printable per-site cron-health reports (your logo, name, and accent color), viewable on demand and emailed monthly (Agency & Agency Plus)
* **Site Auto-Discovery** - Add client sites in bulk by pasting a list, or let client sites enroll themselves with a shared hub token (Agency & Agency Plus)
* **Encrypted Connection Keys** - Client API keys are encrypted at rest using your wp-config secret keys (Agency & Agency Plus)

= Why You Need This =

WordPress relies on WP-Cron for critical tasks like:

* Publishing scheduled posts
* Sending emails
* Running backups
* Processing orders (WooCommerce)
* Updating plugins and themes

When WP-Cron fails silently, these tasks stop working. Cron Guard gives you visibility into your cron health and alerts you before problems become critical.

= Multi-Site Management for Agencies =

Managing cron across dozens of client sites? The **Agency Dashboard** (Agency and Agency Plus plans) brings every site's cron health onto one screen. Connect each client site with a secure key, and your hub polls them on a schedule and on demand — showing health status, overdue and stalled hooks, the last successful run, and a 7-day uptime trend for each site, with a one-click link into any site's own Cron Guard.

Because the hub polls each site over a secure REST endpoint, you still see the truth even when a client's own WP-Cron has stopped — the exact failure you need to catch. Turn on the email digest to get a scheduled summary the moment any client site needs attention, so you don't have to keep the dashboard open. No external service required; your hub is just another WordPress site running Cron Guard.

Need something client-facing? Generate **white-label reports** for any connected site — branded with your logo, agency name, and accent color — viewable on demand and printable straight to PDF from your browser, or emailed to each client automatically every month.

Onboarding lots of sites? **Bulk-import** them by pasting a list, or flip on **self-enrollment** so each client site registers itself with your hub using a shared token — no copying keys one at a time. Every stored connection key is **encrypted at rest** with a key derived from your site's secret keys, so a database dump alone never exposes them.

= Supported Hosts =

The Fix Assistant provides specific setup instructions for:

* WP Engine
* Kinsta
* SiteGround
* Bluehost
* GoDaddy
* DreamHost
* Cloudways
* Flywheel
* Pantheon
* Pressable
* cPanel hosts
* Plesk hosts
* Generic VPS/Dedicated servers

== Installation ==

1. Upload the `cron-guard` folder to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Navigate to **Cron Guard** in the admin menu to view your cron health

= Setting Up Real Cron (Recommended) =

For best reliability, disable WordPress's built-in cron and use a real server cron job:

1. Add to your `wp-config.php`:

`define('DISABLE_WP_CRON', true);`

2. Set up a server cron job (every 5 minutes recommended):

`*/5 * * * * wget -q -O /dev/null "https://yoursite.com/wp-cron.php" >/dev/null 2>&1`

The **Fix Assistant** page provides detailed, host-specific instructions for your hosting environment.

== Frequently Asked Questions ==

= What is WP-Cron? =

WP-Cron is WordPress's built-in task scheduler. Unlike a real server cron, WP-Cron only runs when someone visits your site. This means on low-traffic sites, scheduled tasks may be delayed or missed entirely.

= Why are my cron jobs not running? =

Common causes include:

* Low site traffic (WP-Cron needs page visits to trigger)
* DISABLE_WP_CRON is set but no real cron is configured
* Hosting blocking loopback requests
* Server resource limits
* Plugin conflicts
* SSL certificate issues

Use the Fix Assistant to diagnose your specific issue.

= How do I set up a real cron job? =

The Fix Assistant provides step-by-step instructions for your specific hosting provider. Generally, you need to:

1. Add `define('DISABLE_WP_CRON', true);` to wp-config.php
2. Set up a server cron job to hit wp-cron.php every 5 minutes

= What's the difference between Warning and Critical status? =

* **Warning** - Cron hasn't run within your configured threshold (default: 15 minutes)
* **Critical** - Cron hasn't run for more than double your threshold (default: 30 minutes)

= Can I use external cron services? =

Yes! If your host doesn't support real cron, you can use external services like:

* EasyCron
* cron-job.org
* UptimeRobot

The Fix Assistant includes setup instructions for these services.

= Does this plugin slow down my site? =

No. Cron Guard is designed to be lightweight:

* Logs are stored in WordPress options (no custom database tables)
* Rolling log with maximum 500 entries
* Automatic cleanup of old logs
* Cron profiling only runs during cron execution

= How is this different from WP Crontrol? =

They solve different problems and work well side by side. WP Crontrol is a cron *management* tool for editing, adding, deleting, pausing, and manually running individual cron events. Cron Guard is a cron *monitoring and alerting* tool that watches your cron health and tells you the moment something breaks.

Cron Guard focuses on things WP Crontrol does not do:

* Proactive alerts (email, webhook, Slack, Discord) when cron stalls or repeatedly misses its schedule
* A historical rolling log of cron execution events
* A plain-language health dashboard with Warning/Critical status, built for site owners and agency clients rather than developers
* An in-dashboard Fix Assistant with host-specific instructions for setting up real cron
* Verification that real server cron is actually executing

If you need to hand-edit, pause, or create individual cron events, WP Crontrol is the right tool. If you need to know when cron fails and how to fix it, that's Cron Guard. Many sites happily run both.

== External Services ==

This plugin optionally connects to the following third-party services when configured by the user:

= Slack API =

When Slack alerts are enabled, the plugin sends notification messages to a user-configured Slack Incoming Webhook URL. Data sent includes: site name, site URL, cron health status, and alert details. No personal data is transmitted. Slack is operated by Salesforce, Inc.

* [Slack API documentation](https://api.slack.com/messaging/webhooks)
* [Slack Privacy Policy](https://slack.com/trust/privacy/privacy-policy)

= Discord API =

When Discord alerts are enabled, the plugin sends notification messages to a user-configured Discord Webhook URL. Data sent includes: site name, site URL, cron health status, and alert details. No personal data is transmitted.

* [Discord Developer documentation](https://discord.com/developers/docs/resources/webhook)
* [Discord Privacy Policy](https://discord.com/privacy)

= Generic Webhooks =

When webhook alerts are enabled, the plugin sends a JSON POST request to any user-configured URL. Data sent includes: site name, site URL, cron health status, and alert details. The webhook URL is entirely user-controlled.

= Freemius SDK =

This plugin uses the Freemius SDK for optional usage analytics and future licensing. No data is collected unless the user opts in during activation. Freemius is operated by Freemius, Inc.

* [Freemius Privacy Policy](https://freemius.com/privacy/)
* [Freemius Terms of Service](https://freemius.com/terms/)

= External Cron Services (Referenced Only) =

The Fix Assistant page references third-party cron services (EasyCron, cron-job.org, UptimeRobot) as alternatives for setting up server-side cron. The plugin does not connect to or transmit data to these services. Users who choose to use these services do so independently.

== Screenshots ==

1. Dashboard - Overall cron health status and quick stats
2. Scheduled Events - Complete list of all cron events with status indicators
3. Fix Assistant - Host-specific setup instructions
4. Logs - Filterable log viewer with event details
5. Settings - Configuration options and premium features
6. Agency Dashboard - Monitor cron health across all client sites with per-site uptime trends (Agency & Agency Plus)

== Changelog ==

= 1.5.0 =
* Security (Pro and up): outbound alert URLs (Webhook, Slack, Discord) are now validated before a request is sent, blocking alerts aimed at internal or private network addresses.
* Security (Agency/Agency Plus): connected-site connection keys at rest now use authenticated AES-256-GCM encryption, which detects tampering. Keys saved by earlier versions continue to work and are upgraded over time.
* Security (Agency/Agency Plus): client self-enrollment now uses single-use, time-limited tokens instead of one shared token. Only a hash of each token is stored, each client must prove control of its site (its connection key is verified) before it is added, and disabling enrollment immediately revokes every outstanding token. After upgrading, re-enable enrollment and generate fresh tokens as needed.
* Maintenance: updated the bundled Freemius SDK.
* No changes for free users.

= 1.4.0 =
* New (Agency/Agency Plus): client-site auto-discovery — bulk-import sites by pasting a "URL, key, email" list (existing sites matched by URL are updated, not duplicated), or enable self-enrollment so client sites register themselves with the hub via a shared, revocable enrollment token over a secure REST endpoint.
* Security (Agency/Agency Plus): connected-site connection keys are now encrypted at rest (AES-256-CBC) with a key derived from this site's wp-config secret keys. Existing plaintext keys are migrated automatically on upgrade. No changes for free users.

= 1.3.0 =
* New (Agency/Agency Plus): white-label client reports — branded, printable cron-health reports for any connected site, with your logo, agency name, and accent color. View on demand from the Agency Dashboard (print or save as PDF) or have them emailed to each client automatically every month. Optional per-site client email plus a "Send Test Report" button. No changes for free users.

= 1.2.0 =
* New (Agency/Agency Plus): scheduled Agency email digest — the hub emails a summary whenever any connected client site is in a warning, critical, or unreachable state. Configurable frequency (daily or twice daily) and recipient, with a "Send Test Digest" button. No changes for free users.

= 1.1.1 =
* New (Agency/Agency Plus): multi-site Agency Dashboard — monitor cron health across all your client sites from one hub, with per-site 7-day uptime trends. Each site exposes a secure, key-authenticated REST endpoint that the hub polls (works even when a client's own WP-Cron is down). No changes for free users.

= 1.0.9 =
* Premium: reorganized licensing into Pro, Agency, and Agency Plus plans. No changes for free users.

= 1.0.8 =
* Add the Freemius free/premium auto-deactivation mechanism (`set_basename`), so activating the premium version cleanly deactivates the free version and vice versa. No change for free users.

= 1.0.7 =
* Load the Freemius SDK through the Composer autoloader (`vendor/autoload.php`), matching the recommended Composer integration. No functional change.

= 1.0.6 =
* Confirmed compatible with WordPress 7.0 (tested on WP 7.0 / PHP 8.2).
* Timezone clarity: every displayed time now shows the site's timezone, with an "All times shown in …" note on the Dashboard, Scheduled Events, and Logs screens.
* Times are now formatted with `wp_date()` for correct, DST-aware display of named timezones; alert emails and Slack/Discord notifications now include the timezone too.
* Added a "How is this different from WP Crontrol?" FAQ entry.

= 1.0.5 =
* WordPress.org compliance: restructure premium-only code so the Freemius deploy script physically strips it from the free build (suffixed `__premium_only` methods and `__premium_only.php` files).
* Free build no longer contains the license/plan class, the premium settings UI, the verification flow, or the alert/webhook/Slack/Discord implementations.
* Removed the upgrade CTA from the Settings page.
* Bumped Freemius SDK to 2.13.1.

= 1.0.0 =
* Initial release
* Core health monitoring functionality
* Admin dashboard with status indicators
* Scheduled events list with performance metrics
* Rolling event log with filtering
* Fix Assistant with host-specific instructions
* Email alerts (Premium)
* Webhook alerts (Premium)
* Slack integration (Premium)
* Discord integration (Premium)
* Verification system (Premium)

== Upgrade Notice ==

= 1.5.0 =
Security hardening for Pro and Agency plans: validated alert URLs, authenticated AES-256-GCM key encryption, and single-use self-enrollment tokens. Existing keys keep working. After upgrading, re-enable client self-enrollment and generate fresh tokens if you use it. No functional change for free users.

= 1.4.0 =
Adds client-site auto-discovery (bulk import + self-enrollment) and encrypts stored connection keys at rest, for Agency and Agency Plus plans. Existing keys migrate automatically. No functional change for free users.

= 1.3.0 =
Adds branded, printable white-label client reports (on-demand and monthly email) for Agency and Agency Plus plans. No functional change for free users.

= 1.2.0 =
Adds a scheduled email digest of at-risk client sites for Agency and Agency Plus plans. No functional change for free users.

= 1.1.1 =
Adds the multi-site Agency Dashboard for Agency and Agency Plus plans. No functional change for free users.

= 1.0.9 =
Premium licensing/plan updates only. No functional change for free users.

= 1.0.8 =
Adds clean auto-switching between the free and premium versions. No functional change for free users.

= 1.0.7 =
Internal maintenance: loads the Freemius SDK via the Composer autoloader. No functional change.

= 1.0.6 =
Confirmed compatible with WordPress 7.0, plus clearer timezone display across all screens and alerts.

= 1.0.0 =
Initial release of Cron Guard.
