-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron-jobs.php
35 lines (31 loc) · 1.25 KB
/
cron-jobs.php
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
<?php
// Runs autoresponse check daily
function schedule_deshi_autoresponse_cron() {
// Check if the environment is production
if (defined('WP_ENV') && WP_ENV === 'production') {
// Check if the event is already scheduled
if (!wp_next_scheduled('deshi_autoresponse_event')) {
// Schedule the event to run daily
wp_schedule_event(time(), 'daily', 'deshi_autoresponse_event');
}
}
}
add_action('deshi_autoresponse_event', 'execute_deshi_autoresponse_command');
function execute_deshi_autoresponse_command() {
// Execute the WP-CLI command
$output = shell_exec('/usr/bin/wp bonsai deshi autoresponse');
// Log the output for debugging
error_log("Output of the WP-CLI command: " . print_r($output, true));
}
function deshi_autoresponse_activation() {
if (! wp_next_scheduled('deshi_autoresponse_event')) {
wp_schedule_event(time(), 'daily', 'deshi_autoresponse_event');
}
}
function deshi_autoresponse_deactivation() {
wp_clear_scheduled_hook('deshi_autoresponse_event');
}
function setup_deshi_autoresponse_hooks($main_file) {
register_activation_hook($main_file, 'deshi_autoresponse_activation');
register_deactivation_hook($main_file, 'deshi_autoresponse_deactivation');
}