/var/www/html_uk/wp-content/plugins/automatewoo/includes/Jobs/CheckGmtOffsetChange.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

namespace AutomateWoo\Jobs;

use 
AutomateWoo\Time_Helper;

defined'ABSPATH' ) || exit;

/**
 * Checks if the Site timezone offset changed in the site.
 * This check is needed to re-schedule the Custom Day Time based hooks using the new timezone.
 *
 * @since 6.0.0
 */
class CheckGmtOffsetChange extends AbstractRecurringOneTimeActionSchedulerJob {

    
/**
     * Get the name of the job.
     *
     * @return string
     */
    
public function get_name() {
        return 
'check_for_gmt_offset_change';
    }


    
/**
     * Check if the new site timezone offset matches with the existing one. If it doesn't match, it updates `automatewoo_gmt_offset`
     * with the new site timezone offset and triggers `automatewoo/gmt_offset_changed` action.
     *
     * @param array $item Not being used for this action.
     */
    
protected function process_item( array $item ) {
        
$new_offset      Time_Helper::get_timezone_offset();
        
$existing_offset get_option'automatewoo_gmt_offset' );

        if ( 
$existing_offset === false ) {
            
update_option'automatewoo_gmt_offset'$new_offsetfalse );
            return;
        }

        if ( (float) 
$existing_offset !== (float) $new_offset ) {
            
do_action'automatewoo/gmt_offset_changed'$new_offset$existing_offset );
            
update_option'automatewoo_gmt_offset'$new_offsetfalse );
        }
    }

    
/**
     * Return the recurring job's interval in seconds.
     *
     * @return int The interval for this action
     */
    
public function get_interval() {
        return 
JobService::FIVE_MINUTE_INTERVAL;
    }
}