-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththe-perfect-wp-cron.php
More file actions
60 lines (49 loc) · 1.9 KB
/
the-perfect-wp-cron.php
File metadata and controls
60 lines (49 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Plugin Name: The Perfect WP Cron
* Plugin URI: https://github.com/Ultimate-Multisite/the-perfect-wp-cron
* Description: Event-loop job queue for WordPress. Executes WP Cron and Action Scheduler jobs at exact scheduled times with zero polling using Workerman.
* Version: 1.0.0
* Author: David Stone
* Author URI: https://ultimatemultisite.com
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Requires PHP: 8.1
* Network: true
*/
if (!defined('ABSPATH')) {
return;
}
define('QW_PLUGIN_DIR', __DIR__);
define('QW_PLUGIN_URL', plugin_dir_url(__FILE__));
// Autoload: Bedrock's site autoloader handles this in most installs.
// For standalone installs, fall back to the plugin's own vendor autoloader.
if (!class_exists('QueueWorker\\Config')) {
require_once __DIR__ . '/vendor/autoload.php';
}
// Don't register interceptors inside the worker process itself
if (defined('QUEUE_WORKER_RUNNING') && QUEUE_WORKER_RUNNING) {
return;
}
add_action('init', ['QueueWorker\\Cron_Interceptor', 'register']);
add_action('action_scheduler_init', ['QueueWorker\\Action_Scheduler_Bridge', 'register']);
// Admin menu
$menu_hook = is_multisite() ? 'network_admin_menu' : 'admin_menu';
add_action($menu_hook, ['QueueWorker\\Admin_Page', 'register_menu']);
// AJAX handlers (always on admin_init, even on network admin)
add_action('wp_ajax_qw_worker_status', ['QueueWorker\\Admin_Page', 'ajax_worker_status']);
// WP-CLI commands
if (defined('WP_CLI') && WP_CLI) {
WP_CLI::add_command('queue', 'QueueWorker\\CLI_Commands');
}
// Activation hook: create job log table
register_activation_hook(__FILE__, function () {
QueueWorker\Job_Log::ensure_table();
});
// Daily cleanup cron
add_action('qw_cleanup_job_log', function () {
QueueWorker\Job_Log::cleanup();
});
if (!wp_next_scheduled('qw_cleanup_job_log')) {
wp_schedule_event(time(), 'daily', 'qw_cleanup_job_log');
}