Repository navigation
Expand file tree
/
Copy pathtests.php
More file actions
58 lines (39 loc) · 1.36 KB
/
Copy pathtests.php
File metadata and controls
58 lines (39 loc) · 1.36 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
<?php
defined('ABSPATH') || exit;
/*
* Example of a task that takes a long time to complete. This task will be executed asynchronously in the background.
* Two ways to dispatch the task:
* 1. Using lab_async_dispatch() - this will execute the task immediately in the background
* 2. Using lab_async_queue_dispatch() - this will add the task to a queue
*/
// add_action('async_task_test', function ($data) {
// sleep(15); // simulate a long-running task
// $upload_dir = wp_upload_dir();
// $log_file = $upload_dir['basedir'] . '/email_log.txt';
// file_put_contents($log_file, "Email sent to: {$data['email']}\n", FILE_APPEND);
// }, 10, 1);
add_action('async_queue_task_test', function ($data) {
sleep(15); // simulate a long-running task
$upload_dir = wp_upload_dir();
$log_file = $upload_dir['basedir'] . '/email_log.txt';
file_put_contents(
$log_file,
"Email sent to: {$data['email']}\n",
FILE_APPEND
);
}, 10, 1);
add_action('template_redirect', function () {
if (is_admin()) {
return;
}
$path = trim(wp_parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
if ($path !== 'lightroom') {
return;
}
// async_dispatch('test', [
// 'email' => 'test@example.com',
// ]);
async_queue_dispatch('test', [
'email' => 'test@example.com',
]);
});