Cron Jobs & Scheduled Tasks
LicenceForge registers four WP-Cron events during plugin activation. These scheduled tasks handle license expiration, data cleanup, email notifications, and webhook retries. All background work depends on WP-Cron executing reliably.
Warning
WP-Cron is triggered by site visits. If your site receives little traffic, scheduled tasks may run late or not at all. Set up a real server-side cron job to ensure timely execution. See Replacing WP-Cron with a Server Cron below.
Scheduled Events Overview
The following table summarizes every cron event registered by LicenceForge.
| Event Hook | Frequency | Purpose |
|---|---|---|
wplf_daily_maintenance |
Daily | Runs all core maintenance tasks via WPLF_Maintenance::run_daily_tasks() |
wplf_check_expiring_licenses |
Daily | Sends email notifications for licenses expiring within 7 days |
wplf_cleanup_analytics |
Weekly | Additional pass to purge analytics data older than 365 days |
wplf_webhook_retry |
Every 5 minutes | Retries failed webhook events (up to 10 per run) |
Daily Maintenance Tasks
The wplf_daily_maintenance event calls WPLF_Maintenance::run_daily_tasks(), which executes the following sub-tasks in order. Each sub-task runs independently -- a failure in one does not prevent the others from executing.
expire_old_licenses()
Scans for licenses whose expiration date plus the configured grace period (wplf_grace_period_days) has passed. Matching licenses are transitioned from active to expired status. The grace period defaults to 3 days but is configurable in Licences > Settings.
cleanup_old_audit_logs()
Deletes audit log entries older than the configured retention period. The retention period is controlled by the wplf_audit_retention_days option, which defaults to 90 days. See Data Retention for configuration details.
cleanup_old_webhook_events()
Deletes webhook event records older than 30 days from the wplf_webhook_events table. This retention period is hardcoded and not configurable.
cleanup_old_analytics()
Deletes analytics records older than 365 days from the wplf_analytics table. This retention period is hardcoded. The weekly wplf_cleanup_analytics event performs an additional cleanup pass as a safety net.
auto_deactivate_expired()
Deactivates all site activations associated with licenses that have an expired or cancelled status. This task only runs when the wplf_auto_deactivate option is set to true (the default).
When auto-deactivation fires, each affected activation is removed from the wplf_activations table and an entry is written to the audit log.
check_health_alerts()
Runs the full suite of health checks. If any check returns a warning or error status and health alerts are enabled, an alert email is sent to the configured address. See Health Alerts for setup instructions.
Expiring License Notifications
The wplf_check_expiring_licenses event queries for active licenses whose expiration date falls within the next 7 days. For each match, it sends a notification email to the license holder using the configured email template.
Note
Email notifications must be enabled globally via the wplf_email_notifications option. If disabled, this cron event still runs but produces no output. See Email Configuration for details.
Webhook Retry Processing
The wplf_webhook_retry event runs every 5 minutes and processes up to 10 failed webhook events per execution. Events are retried with exponential backoff until they either succeed or exceed the maximum retry count. Events that exceed MAX_RETRIES are marked as permanently failed and no longer retried.
Permanently failed events remain in the database for 30 days (subject to the webhook event cleanup) and are flagged in the health checks.
Manual Execution
You can trigger all daily maintenance tasks on demand without waiting for WP-Cron.
Via the Admin Panel
Navigate to Licences > Settings and click the Run Maintenance Tasks button. This immediately calls WPLF_Maintenance::run_daily_tasks() and displays the results.
Via WP-CLI
Run the maintenance cron event directly from the command line:
wp cron event run wplf_daily_maintenance
To run all LicenceForge cron events at once:
wp cron event run wplf_daily_maintenance
wp cron event run wplf_check_expiring_licenses
wp cron event run wplf_cleanup_analytics
wp cron event run wplf_webhook_retry
Tracking the Last Run
Each time WPLF_Maintenance::run_daily_tasks() completes, the current Unix timestamp is saved to the wplf_last_maintenance_run option. This value is used by:
- The cron health check to detect stale maintenance runs
- The admin dashboard to display when maintenance last executed
You can inspect this value via WP-CLI:
wp option get wplf_last_maintenance_run
Replacing WP-Cron with a Server Cron
For production sites, replace the default WP-Cron behavior with a real server-side cron job. This ensures tasks run on schedule regardless of site traffic.
Step 1: Disable WP-Cron Triggering on Page Load
Add the following line to your wp-config.php file:
define( 'DISABLE_WP_CRON', true );
Step 2: Add a System Cron Job
Open your crontab and add an entry that calls wp-cron.php at regular intervals. Every 5 minutes is recommended to match the webhook retry schedule:
crontab -e
*/5 * * * * curl -s https://example.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
Alternatively, use WP-CLI if it is available on your server:
*/5 * * * * cd /path/to/wordpress && wp cron event run --due-now > /dev/null 2>&1
Tip
After configuring a server cron, verify it is working by checking the wplf_last_maintenance_run timestamp after the next expected daily run. The health check will also report an error if maintenance has not run in over 48 hours.
Troubleshooting
Tasks Not Running
If scheduled tasks are not executing, check the following:
- Verify the cron events are registered:
wp cron event list --fields=hook,next_run_relative | grep wplf - Confirm
DISABLE_WP_CRONis not set totruewithout a server cron replacement. - Check that no caching plugin is interfering with
wp-cron.phprequests. - Ensure your hosting provider does not restrict outgoing HTTP requests to
wp-cron.php.
Re-registering Cron Events
If cron events are missing (for example, after a database migration), deactivate and reactivate LicenceForge. This re-registers all four scheduled events without affecting your data or settings.
Related Pages
- Health Checks -- System health monitoring and alerting
- Data Retention -- Configurable retention periods for logs and analytics
- Email Configuration -- Email notification settings and templates
- Installation -- Initial plugin setup and activation