-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-page.php
More file actions
838 lines (726 loc) · 33.5 KB
/
admin-page.php
File metadata and controls
838 lines (726 loc) · 33.5 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
<?php
/**
* Demo admin page for WP-Queue examples.
* Provides visual interface to run and monitor job examples.
* Organized by tabs: Queue Only, Cron Only, Mixed (Cron + Queue).
*/
if (! defined('ABSPATH')) {
exit;
}
// Register admin page
add_action('admin_menu', static function (): void {
add_menu_page(
'WP-Queue Demo',
'WP-Queue Demo',
'manage_options',
'wp-queue-demo',
'wp_queue_demo_page',
'dashicons-clock',
30,
);
});
// Enqueue scripts and styles
add_action('admin_enqueue_scripts', static function ($hook): void {
if ($hook !== 'toplevel_page_wp-queue-demo') {
return;
}
wp_enqueue_script('wp-queue-demo-js', WP_QUEUE_DEMO_URL.'assets/js/demo.js', ['jquery'], WP_QUEUE_DEMO_VERSION, true);
wp_enqueue_style('wp-queue-demo-css', WP_QUEUE_DEMO_URL.'assets/css/demo.css', [], WP_QUEUE_DEMO_VERSION);
wp_localize_script('wp-queue-demo-js', 'wpQueueDemo', [
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('wp_queue_demo_nonce'),
]);
});
/**
* Get examples configuration organized by category.
*/
function wp_queue_demo_get_examples(): array
{
return [
'queue' => [
'label' => 'Queue Only',
'description' => 'Examples using only queue processing without scheduling.',
'examples' => [
[
'id' => 'simple_log',
'title' => 'Simple Logging',
'description' => 'Basic queue job that writes a message to log file. Demonstrates minimal queue usage.',
'complexity' => 'Simple',
'color' => 'green',
'job_class' => 'ExamplePlugin\\Jobs\\QueueOnly\\SimpleLogJob',
],
[
'id' => 'delayed_notification',
'title' => 'Delayed Notification',
'description' => 'Send notification with delay and retry on failure. Demonstrates delayed dispatch and retry mechanism.',
'complexity' => 'Medium',
'color' => 'blue',
'job_class' => 'ExamplePlugin\\Jobs\\QueueOnly\\DelayedNotificationJob',
],
[
'id' => 'chained_processing',
'title' => 'Chained Processing',
'description' => 'Process items in batches with job chaining. One job dispatches another for remaining items.',
'complexity' => 'Medium',
'color' => 'purple',
'job_class' => 'ExamplePlugin\\Jobs\\QueueOnly\\ChainedProcessingJob',
],
],
],
'cron' => [
'label' => 'Cron Only',
'description' => 'Examples using WP-Cron scheduling. Jobs auto-unschedule after completion.',
'examples' => [
[
'id' => 'scheduled_cleanup',
'title' => 'Scheduled Cleanup',
'description' => 'Runs every 5 minutes to clean temporary data. Auto-unschedules after execution.',
'complexity' => 'Simple',
'color' => 'green',
'job_class' => 'ExamplePlugin\\Jobs\\CronOnly\\ScheduledCleanupJob',
'schedule' => '5min',
],
[
'id' => 'daily_report',
'title' => 'Daily Report',
'description' => 'Generates daily site report and sends to admin. Auto-unschedules after completion.',
'complexity' => 'Medium',
'color' => 'blue',
'job_class' => 'ExamplePlugin\\Jobs\\CronOnly\\DailyReportJob',
'schedule' => 'daily',
],
[
'id' => 'hourly_health_check',
'title' => 'Hourly Health Check',
'description' => 'Monitors system health hourly. Sends alerts if issues found. Auto-unschedules after execution.',
'complexity' => 'Medium',
'color' => 'teal',
'job_class' => 'ExamplePlugin\\Jobs\\CronOnly\\HourlyHealthCheckJob',
'schedule' => 'hourly',
],
],
],
'mixed' => [
'label' => 'Mixed (Cron + Queue)',
'description' => 'Complex examples combining scheduled triggers with queue processing.',
'examples' => [
[
'id' => 'scheduled_import',
'title' => 'Scheduled Import',
'description' => 'Cron triggers import, queue processes individual items. Demonstrates cron + queue pattern.',
'complexity' => 'Complex',
'color' => 'orange',
'job_class' => 'ExamplePlugin\\Jobs\\Mixed\\ScheduledImportJob',
'schedule' => '30min',
],
[
'id' => 'sync_with_notify',
'title' => 'Sync with Notifications',
'description' => 'Scheduled sync dispatches notification jobs to queue. Separation of concerns pattern.',
'complexity' => 'Complex',
'color' => 'indigo',
'job_class' => 'ExamplePlugin\\Jobs\\Mixed\\ScheduledSyncWithNotifyJob',
'schedule' => '15min',
],
[
'id' => 'batch_processor',
'title' => 'Batch Processor',
'description' => 'Scheduled batch splits work into queue chunks. Scalable parallel processing pattern.',
'complexity' => 'Complex',
'color' => 'red',
'job_class' => 'ExamplePlugin\\Jobs\\Mixed\\ScheduledBatchProcessorJob',
'schedule' => 'hourly',
],
],
],
];
}
/**
* Check if a cron job is currently scheduled.
*/
function wp_queue_demo_is_job_scheduled(string $jobClass): bool
{
$hookName = 'wp_queue_job_'.$jobClass;
return wp_next_scheduled($hookName) !== false;
}
/**
* Get next scheduled time for a job.
*/
function wp_queue_demo_get_next_run(string $jobClass): ?int
{
$hookName = 'wp_queue_job_'.$jobClass;
$timestamp = wp_next_scheduled($hookName);
return $timestamp !== false ? $timestamp : null;
}
// AJAX handler for running queue jobs
add_action('wp_ajax_wp_queue_demo_run', static function (): void {
check_ajax_referer('wp_queue_demo_nonce', 'nonce');
$job_type = sanitize_key($_POST['job_type'] ?? '');
$job = null;
// Find job configuration
$examples = wp_queue_demo_get_examples();
$jobConfig = null;
foreach ($examples as $category) {
foreach ($category['examples'] as $example) {
if ($example['id'] === $job_type) {
$jobConfig = $example;
break 2;
}
}
}
if (! $jobConfig) {
wp_send_json_error('Unknown job type: '.$job_type);
return;
}
$jobClass = $jobConfig['job_class'];
// Create job based on type
switch ($job_type) {
// Queue Only jobs
case 'simple_log':
$job = new $jobClass('Test message at '.date('Y-m-d H:i:s'));
break;
case 'delayed_notification':
$job = new $jobClass(
get_option('admin_email'),
'Test Notification',
'This is a test notification from WP-Queue Demo.',
);
break;
case 'chained_processing':
$items = [];
for ($i = 1; $i <= 25; $i++) {
$items[] = ['id' => $i, 'name' => "Item {$i}"];
}
$job = new $jobClass($items);
break;
// Cron and Mixed jobs - create instance for manual dispatch
default:
$job = new $jobClass();
break;
}
// Get job ID before dispatch
$job_id = $job->getId();
// Store job tracking info
set_transient("wp_queue_demo_job_{$job_id}", [
'status' => 'queued',
'type' => $job_type,
'started_at' => time(),
], 600);
// Dispatch to queue
\WPQueue\WPQueue::dispatch($job);
error_log("WP-Queue Demo: Job {$job_type} dispatched with ID: {$job_id}");
wp_send_json_success(['job_id' => $job_id, 'type' => $job_type]);
});
// AJAX handler for scheduling cron jobs
add_action('wp_ajax_wp_queue_demo_schedule', static function (): void {
check_ajax_referer('wp_queue_demo_nonce', 'nonce');
$job_type = sanitize_key($_POST['job_type'] ?? '');
// Find job configuration
$examples = wp_queue_demo_get_examples();
$jobConfig = null;
foreach (['cron', 'mixed'] as $category) {
if (! isset($examples[$category])) {
continue;
}
foreach ($examples[$category]['examples'] as $example) {
if ($example['id'] === $job_type) {
$jobConfig = $example;
break 2;
}
}
}
if (! $jobConfig) {
wp_send_json_error('Unknown cron job type: '.$job_type);
return;
}
$jobClass = $jobConfig['job_class'];
$schedule = $jobConfig['schedule'] ?? 'hourly';
// Check if already scheduled
if (wp_queue_demo_is_job_scheduled($jobClass)) {
wp_send_json_error('Job is already scheduled');
return;
}
// Schedule the job
$hookName = 'wp_queue_job_'.$jobClass;
// Map schedule names to WP cron schedules
$scheduleMap = [
'5min' => 'wp_queue_5min',
'10min' => 'wp_queue_10min',
'15min' => 'wp_queue_15min',
'30min' => 'wp_queue_30min',
'hourly' => 'hourly',
'daily' => 'daily',
];
$wpSchedule = $scheduleMap[$schedule] ?? 'hourly';
// Add custom schedules if needed
add_filter('cron_schedules', function ($schedules) {
$schedules['wp_queue_5min'] = ['interval' => 300, 'display' => 'Every 5 Minutes'];
$schedules['wp_queue_10min'] = ['interval' => 600, 'display' => 'Every 10 Minutes'];
$schedules['wp_queue_15min'] = ['interval' => 900, 'display' => 'Every 15 Minutes'];
$schedules['wp_queue_30min'] = ['interval' => 1800, 'display' => 'Every 30 Minutes'];
return $schedules;
});
// Schedule the event
$result = wp_schedule_event(time(), $wpSchedule, $hookName);
if ($result === false) {
wp_send_json_error('Failed to schedule job');
return;
}
// Mark as scheduled in job class if method exists
if (method_exists($jobClass, 'markScheduled')) {
$jobClass::markScheduled();
}
$nextRun = wp_next_scheduled($hookName);
error_log("WP-Queue Demo: Cron job {$job_type} scheduled, next run: ".date('Y-m-d H:i:s', $nextRun));
wp_send_json_success([
'scheduled' => true,
'next_run' => $nextRun,
'next_run_formatted' => date('Y-m-d H:i:s', $nextRun),
]);
});
// AJAX handler for unscheduling cron jobs
add_action('wp_ajax_wp_queue_demo_unschedule', static function (): void {
check_ajax_referer('wp_queue_demo_nonce', 'nonce');
$job_type = sanitize_key($_POST['job_type'] ?? '');
// Find job configuration
$examples = wp_queue_demo_get_examples();
$jobConfig = null;
foreach (['cron', 'mixed'] as $category) {
if (! isset($examples[$category])) {
continue;
}
foreach ($examples[$category]['examples'] as $example) {
if ($example['id'] === $job_type) {
$jobConfig = $example;
break 2;
}
}
}
if (! $jobConfig) {
wp_send_json_error('Unknown cron job type: '.$job_type);
return;
}
$jobClass = $jobConfig['job_class'];
$hookName = 'wp_queue_job_'.$jobClass;
// Unschedule all events for this hook
$timestamp = wp_next_scheduled($hookName);
if ($timestamp) {
wp_unschedule_event($timestamp, $hookName);
}
// Clear all events with this hook
wp_clear_scheduled_hook($hookName);
error_log("WP-Queue Demo: Cron job {$job_type} unscheduled");
wp_send_json_success(['unscheduled' => true]);
});
// AJAX handler for getting cron status
add_action('wp_ajax_wp_queue_demo_cron_status', static function (): void {
check_ajax_referer('wp_queue_demo_nonce', 'nonce');
$examples = wp_queue_demo_get_examples();
$status = [];
foreach (['cron', 'mixed'] as $category) {
if (! isset($examples[$category])) {
continue;
}
foreach ($examples[$category]['examples'] as $example) {
$jobClass = $example['job_class'];
$hookName = 'wp_queue_job_'.$jobClass;
$nextRun = wp_next_scheduled($hookName);
$status[$example['id']] = [
'scheduled' => $nextRun !== false,
'next_run' => $nextRun ?: null,
'next_run_formatted' => $nextRun ? date('Y-m-d H:i:s', $nextRun) : null,
];
}
}
wp_send_json_success($status);
});
/**
* AJAX handler for checking job status
*/
add_action('wp_ajax_wp_queue_demo_status', function (): void {
check_ajax_referer('wp_queue_demo_nonce', 'nonce');
$job_id = sanitize_text_field($_POST['job_id'] ?? '');
if (empty($job_id)) {
wp_send_json_error('Job ID is required');
return;
}
// Check real WP-Queue logs for job status
$logs = \WPQueue\WPQueue::logs()->all();
$job_status = 'queued';
$message = null;
foreach (array_reverse($logs) as $log) {
if ($log['job_id'] === $job_id) {
$job_status = $log['status'];
$message = $log['message'] ?? null;
break;
}
}
if ($job_status === 'queued') {
$queues = ['default', 'high', 'low', 'emails', 'imports', 'notifications', 'processing', 'sync', 'batch', 'reports', 'monitoring'];
$found_in_queue = false;
foreach ($queues as $queue) {
$queue_jobs = get_site_option('wp_queue_jobs_'.$queue, []);
if (isset($queue_jobs[$job_id])) {
$found_in_queue = true;
if ($queue_jobs[$job_id]['reserved_at'] !== null) {
$job_status = 'running';
}
break;
}
}
if (! $found_in_queue && empty($logs)) {
$tracking = get_transient("wp_queue_demo_job_{$job_id}");
if ($tracking && is_array($tracking)) {
$elapsed = time() - ($tracking['started_at'] ?? time());
if ($elapsed > 30) {
$job_status = 'completed';
}
}
}
}
wp_send_json_success([
'status' => $job_status,
'message' => $message,
]);
});
/**
* AJAX handler for fetching logs
*/
add_action('wp_ajax_wp_queue_demo_logs', function (): void {
check_ajax_referer('wp_queue_demo_nonce', 'nonce');
$formatted_logs = [];
$queue_logs = \WPQueue\WPQueue::logs()->recent(30);
foreach ($queue_logs as $log) {
$timestamp = date('d-M-Y H:i:s', $log['timestamp']);
$job_class = basename(str_replace('\\', '/', $log['job_class']));
$status_icon = match ($log['status']) {
'completed' => '✓',
'failed' => '✗',
default => '→',
};
$message = "[{$timestamp} UTC] WP-Queue Demo: {$status_icon} {$job_class} - {$log['status']}";
if (! empty($log['message'])) {
$message .= " ({$log['message']})";
}
$formatted_logs[] = $message;
}
$error_log = ini_get('error_log');
if ($error_log && file_exists($error_log) && is_readable($error_log)) {
$log_content = @file_get_contents($error_log);
if ($log_content) {
$lines = explode("\n", trim($log_content));
$recent_lines = array_slice($lines, -30);
foreach ($recent_lines as $line) {
if (strpos($line, 'WP-Queue Demo') !== false || strpos($line, 'WP Queue:') !== false) {
if (! in_array($line, $formatted_logs)) {
$formatted_logs[] = $line;
}
}
}
}
}
$formatted_logs = array_slice($formatted_logs, -25);
wp_send_json_success(['logs' => $formatted_logs]);
});
/**
* Render the demo page with tabs
*/
function wp_queue_demo_page(): void
{
$examples = wp_queue_demo_get_examples();
$activeTab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'queue';
if (! isset($examples[$activeTab])) {
$activeTab = 'queue';
}
?>
<div class="wrap">
<h1>WP-Queue Demo Dashboard</h1>
<div class="wp-queue-demo-notice">
<p><?php esc_html_e('Interactive demo showcasing WP-Queue capabilities with real-world examples.', 'wp-queue-demo'); ?></p>
<p><strong><?php esc_html_e('Queue Only', 'wp-queue-demo'); ?></strong> - <?php esc_html_e('manual dispatch', 'wp-queue-demo'); ?> | <strong><?php esc_html_e('Cron Only', 'wp-queue-demo'); ?></strong> - <?php esc_html_e('scheduled execution', 'wp-queue-demo'); ?> | <strong><?php esc_html_e('Mixed', 'wp-queue-demo'); ?></strong> - <?php esc_html_e('cron triggers queue jobs', 'wp-queue-demo'); ?></p>
<p class="wp-queue-demo-tip"><strong>💡 <?php esc_html_e('Tip:', 'wp-queue-demo'); ?></strong> <?php esc_html_e('Jobs are processed by WP-Cron every minute. Chained jobs (like Chained Processing) create new jobs automatically. Use "Unschedule" to stop recurring cron jobs.', 'wp-queue-demo'); ?></p>
</div>
<!-- Tabs Navigation -->
<nav class="nav-tab-wrapper wp-queue-demo-tabs">
<?php foreach ($examples as $tabKey => $tabData) { ?>
<a href="?page=wp-queue-demo&tab=<?php echo esc_attr($tabKey); ?>"
class="nav-tab <?php echo $activeTab === $tabKey ? 'nav-tab-active' : ''; ?>">
<?php echo esc_html($tabData['label']); ?>
<span class="tab-count"><?php echo count($tabData['examples']); ?></span>
</a>
<?php } ?>
</nav>
<!-- Tab Content -->
<div class="wp-queue-demo-tab-content">
<p class="tab-description"><?php echo esc_html($examples[$activeTab]['description']); ?></p>
<div class="wp-queue-demo-grid">
<?php
$isCronTab = in_array($activeTab, ['cron', 'mixed']);
foreach ($examples[$activeTab]['examples'] as $example) {
$jobClass = $example['job_class'];
$isScheduled = $isCronTab ? wp_queue_demo_is_job_scheduled($jobClass) : false;
$nextRun = $isCronTab ? wp_queue_demo_get_next_run($jobClass) : null;
?>
<div class="wp-queue-demo-card <?php echo esc_attr($example['color']); ?>"
data-job-type="<?php echo esc_attr($example['id']); ?>"
data-is-cron="<?php echo $isCronTab ? '1' : '0'; ?>">
<div class="wp-queue-demo-card-header">
<h3><?php echo esc_html($example['title']); ?></h3>
<span class="wp-queue-demo-complexity"><?php echo esc_html($example['complexity']); ?></span>
</div>
<div class="wp-queue-demo-card-body">
<p><?php echo esc_html($example['description']); ?></p>
<?php if ($isCronTab && isset($example['schedule'])) { ?>
<div class="wp-queue-demo-schedule-info">
<span class="schedule-label">Schedule:</span>
<span class="schedule-value"><?php echo esc_html($example['schedule']); ?></span>
</div>
<?php } ?>
<div class="wp-queue-demo-status" id="status-<?php echo esc_attr($example['id']); ?>">
<?php if ($isCronTab) { ?>
<?php if ($isScheduled) { ?>
<span class="status-indicator scheduled">
Scheduled
<span class="next-run">Next: <?php echo date('H:i:s', $nextRun); ?></span>
</span>
<?php } else { ?>
<span class="status-indicator idle">Not Scheduled</span>
<?php } ?>
<?php } else { ?>
<span class="status-indicator idle">Ready</span>
<?php } ?>
</div>
</div>
<div class="wp-queue-demo-card-footer">
<?php if ($isCronTab) { ?>
<!-- Cron control buttons -->
<div class="wp-queue-demo-cron-controls">
<button type="button" class="wp-queue-demo-run-btn wp-queue-demo-run-btn--primary"
data-job-type="<?php echo esc_attr($example['id']); ?>"
data-action="run">
Run Now
</button>
<button type="button" class="wp-queue-demo-run-btn wp-queue-demo-run-btn--schedule <?php echo $isScheduled ? 'hidden' : ''; ?>"
data-job-type="<?php echo esc_attr($example['id']); ?>"
data-action="schedule">
Schedule
</button>
<button type="button" class="wp-queue-demo-run-btn wp-queue-demo-run-btn--danger <?php echo ! $isScheduled ? 'hidden' : ''; ?>"
data-job-type="<?php echo esc_attr($example['id']); ?>"
data-action="unschedule">
Unschedule
</button>
</div>
<?php } else { ?>
<!-- Queue only - single run button -->
<button type="button" class="wp-queue-demo-run-btn"
data-job-type="<?php echo esc_attr($example['id']); ?>">
Run Job
</button>
<?php } ?>
</div>
</div>
<?php } ?>
</div>
</div>
<div class="wp-queue-demo-logs">
<h2><?php esc_html_e('Recent Activity', 'wp-queue-demo'); ?></h2>
<div class="wp-queue-demo-log-container">
<pre id="demo-logs"><?php esc_html_e('Waiting for job activity...', 'wp-queue-demo'); ?></pre>
</div>
<button type="button" class="wp-queue-demo-run-btn wp-queue-demo-run-btn--secondary" id="refresh-logs"><?php esc_html_e('Refresh Logs', 'wp-queue-demo'); ?></button>
</div>
<!-- Why WP-Queue Section -->
<div class="wp-queue-demo-info-section">
<h2><?php esc_html_e('Why WP-Queue?', 'wp-queue-demo'); ?></h2>
<div class="wp-queue-info-grid">
<div class="wp-queue-info-card">
<h3>🚀 <?php esc_html_e('Performance', 'wp-queue-demo'); ?></h3>
<p><?php esc_html_e('Heavy tasks run in the background without blocking user requests. Your site stays fast while processing thousands of items.', 'wp-queue-demo'); ?></p>
</div>
<div class="wp-queue-info-card">
<h3>🔄 <?php esc_html_e('Reliability', 'wp-queue-demo'); ?></h3>
<p><?php esc_html_e('Automatic retries on failure, exponential backoff, and detailed logging ensure no job is lost.', 'wp-queue-demo'); ?></p>
</div>
<div class="wp-queue-info-card">
<h3>⏰ <?php esc_html_e('Scheduling', 'wp-queue-demo'); ?></h3>
<p><?php esc_html_e('Schedule recurring tasks with PHP attributes. No manual cron setup required.', 'wp-queue-demo'); ?></p>
</div>
<div class="wp-queue-info-card">
<h3>🎯 <?php esc_html_e('Simplicity', 'wp-queue-demo'); ?></h3>
<p><?php esc_html_e('Laravel-inspired API. Just create a Job class and dispatch it. WP-Queue handles the rest.', 'wp-queue-demo'); ?></p>
</div>
</div>
<h3><?php esc_html_e('Real-World Use Cases', 'wp-queue-demo'); ?></h3>
<div class="wp-queue-use-cases">
<div class="use-case-category">
<h4>📧 <?php esc_html_e('Email & Notifications', 'wp-queue-demo'); ?></h4>
<ul>
<li><?php esc_html_e('Bulk email campaigns (newsletters, promotions)', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Order confirmation emails', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Password reset notifications', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Push notifications to mobile apps', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('SMS alerts for critical events', 'wp-queue-demo'); ?></li>
</ul>
</div>
<div class="use-case-category">
<h4>🛒 <?php esc_html_e('E-Commerce', 'wp-queue-demo'); ?></h4>
<ul>
<li><?php esc_html_e('Product import from CSV/XML/API', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Inventory sync with ERP systems', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Price updates from suppliers', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Order export to fulfillment services', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Abandoned cart recovery emails', 'wp-queue-demo'); ?></li>
</ul>
</div>
<div class="use-case-category">
<h4>🖼️ <?php esc_html_e('Media Processing', 'wp-queue-demo'); ?></h4>
<ul>
<li><?php esc_html_e('Image optimization and compression', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Video transcoding', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('PDF generation (invoices, reports)', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Thumbnail regeneration', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Watermark application', 'wp-queue-demo'); ?></li>
</ul>
</div>
<div class="use-case-category">
<h4>🔗 <?php esc_html_e('API Integrations', 'wp-queue-demo'); ?></h4>
<ul>
<li><?php esc_html_e('CRM synchronization (Salesforce, HubSpot)', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Payment gateway webhooks', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Social media posting', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Analytics data export', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Third-party API rate limiting', 'wp-queue-demo'); ?></li>
</ul>
</div>
<div class="use-case-category">
<h4>🧹 <?php esc_html_e('Maintenance Tasks', 'wp-queue-demo'); ?></h4>
<ul>
<li><?php esc_html_e('Database cleanup and optimization', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Log rotation and archiving', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Cache warming after deployment', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Sitemap regeneration', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Expired content cleanup', 'wp-queue-demo'); ?></li>
</ul>
</div>
<div class="use-case-category">
<h4>📊 <?php esc_html_e('Reports & Analytics', 'wp-queue-demo'); ?></h4>
<ul>
<li><?php esc_html_e('Daily/weekly sales reports', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('User activity summaries', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('SEO audit reports', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Performance monitoring alerts', 'wp-queue-demo'); ?></li>
<li><?php esc_html_e('Inventory level warnings', 'wp-queue-demo'); ?></li>
</ul>
</div>
</div>
<h3><?php esc_html_e('Why WP-Queue is Better', 'wp-queue-demo'); ?></h3>
<table class="wp-queue-comparison-table">
<thead>
<tr>
<th><?php esc_html_e('Feature', 'wp-queue-demo'); ?></th>
<th><?php esc_html_e('WP-Queue', 'wp-queue-demo'); ?></th>
<th><?php esc_html_e('WP-Cron Only', 'wp-queue-demo'); ?></th>
<th><?php esc_html_e('Action Scheduler', 'wp-queue-demo'); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td><?php esc_html_e('Modern PHP (8.3+)', 'wp-queue-demo'); ?></td>
<td>✅</td>
<td>✅</td>
<td>❌ <?php esc_html_e('PHP 7.0+', 'wp-queue-demo'); ?></td>
</tr>
<tr>
<td><?php esc_html_e('PHP Attributes', 'wp-queue-demo'); ?></td>
<td>✅ #[Schedule], #[Queue]</td>
<td>❌</td>
<td>❌</td>
</tr>
<tr>
<td><?php esc_html_e('Typed Properties', 'wp-queue-demo'); ?></td>
<td>✅</td>
<td>❌</td>
<td>❌</td>
</tr>
<tr>
<td><?php esc_html_e('Job Chaining', 'wp-queue-demo'); ?></td>
<td>✅</td>
<td>❌</td>
<td>⚠️ <?php esc_html_e('Manual', 'wp-queue-demo'); ?></td>
</tr>
<tr>
<td><?php esc_html_e('Exponential Backoff', 'wp-queue-demo'); ?></td>
<td>✅</td>
<td>❌</td>
<td>⚠️ <?php esc_html_e('Limited', 'wp-queue-demo'); ?></td>
</tr>
<tr>
<td><?php esc_html_e('Multiple Queues', 'wp-queue-demo'); ?></td>
<td>✅</td>
<td>❌</td>
<td>✅</td>
</tr>
<tr>
<td><?php esc_html_e('Laravel-like API', 'wp-queue-demo'); ?></td>
<td>✅</td>
<td>❌</td>
<td>❌</td>
</tr>
<tr>
<td><?php esc_html_e('Admin Dashboard', 'wp-queue-demo'); ?></td>
<td>✅</td>
<td>❌</td>
<td>✅</td>
</tr>
<tr>
<td><?php esc_html_e('WP-CLI Support', 'wp-queue-demo'); ?></td>
<td>✅</td>
<td>❌</td>
<td>✅</td>
</tr>
</tbody>
</table>
<div class="wp-queue-code-example">
<h3><?php esc_html_e('Quick Start Example', 'wp-queue-demo'); ?></h3>
<pre><code><?php
// 1. <?php esc_html_e('Create a Job class', 'wp-queue-demo'); ?>
use WPQueue\Jobs\Job;
use WPQueue\Attributes\Queue;
use WPQueue\Attributes\Retries;
#[Queue('emails')]
#[Retries(3)]
class SendWelcomeEmail extends Job
{
public function __construct(
private int $userId,
private string $email
) {
parent::__construct();
}
public function handle(): void
{
wp_mail($this->email, 'Welcome!', 'Thanks for joining!');
}
}
// 2. <?php esc_html_e('Dispatch the job', 'wp-queue-demo'); ?>
WPQueue::dispatch(new SendWelcomeEmail($user_id, $email));
// <?php esc_html_e('Or with delay', 'wp-queue-demo'); ?>:
WPQueue::dispatch(new SendWelcomeEmail($user_id, $email))->delay(60);</code></pre>
</div>
</div>
</div>
<!-- Hidden templates -->
<script type="text/template" id="status-template">
<span class="status-indicator <%= status %>"><%= statusText %></span>
</script>
<script type="text/template" id="cron-status-template">
<span class="status-indicator <%= status %>">
<%= statusText %>
<% if (nextRun) { %>
<span class="next-run">Next: <%= nextRun %></span>
<% } %>
</span>
</script>
<?php
}