1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* The main plugin class. |
4
|
|
|
* |
5
|
|
|
* @package LSX_WETU_Importer |
6
|
|
|
* @author LightSpeed |
7
|
|
|
* @license GPL-2.0+ |
8
|
|
|
* @link |
9
|
|
|
* @copyright 2016 LightSpeed |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace lsx\wetu_importer\classes; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The Main plugin class. |
16
|
|
|
*/ |
17
|
|
|
class Cron { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Holds class instance |
21
|
|
|
* |
22
|
|
|
* @since 1.0.0 |
23
|
|
|
* |
24
|
|
|
* @var object|Module_Template |
|
|
|
|
25
|
|
|
*/ |
26
|
|
|
protected static $instance = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Initialize the plugin by setting localization, filters, and administration functions. |
30
|
|
|
* |
31
|
|
|
* @since 1.0.0 |
32
|
|
|
* |
33
|
|
|
* @access private |
34
|
|
|
*/ |
35
|
|
|
public function __construct() { |
|
|
|
|
36
|
|
|
add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 ); |
37
|
|
|
} |
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Return an instance of this class. |
41
|
|
|
* |
42
|
|
|
* @since 1.0.0 |
43
|
|
|
* |
44
|
|
|
* @return object Cron() A single instance of this class. |
45
|
|
|
*/ |
46
|
|
|
public static function get_instance() { |
47
|
|
|
// If the single instance hasn't been set, set it now. |
48
|
|
|
if ( null === self::$instance ) { |
|
|
|
|
49
|
|
|
self::$instance = new self(); |
50
|
|
|
} |
|
|
|
|
51
|
|
|
return self::$instance; |
52
|
|
|
} |
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Watches for changes in the button triggers. |
56
|
|
|
* |
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
|
|
public function watch_for_trigger() { |
|
|
|
|
60
|
|
|
|
61
|
|
|
if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) { |
|
|
|
|
62
|
|
|
$options = lsx_wetu_get_options(); |
63
|
|
|
|
64
|
|
|
// Check what state the option is in. |
65
|
|
|
$accommodation_cron = 'deactivate'; |
66
|
|
|
if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
|
|
|
67
|
|
|
$accommodation_cron = 'activate'; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// Check what state the cron is in. |
71
|
|
|
$schedule = false; |
72
|
|
|
if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) { |
|
|
|
|
73
|
|
|
$schedule = true; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
// If activate and its not running. |
77
|
|
|
if ( false === $schedule && 'activate' === $accommodation_cron ) { |
|
|
|
|
78
|
|
|
$this->schedule(); |
79
|
|
|
} elseif ( true === $schedule && 'deactivate' === $accommodation_cron ) { |
|
|
|
|
80
|
|
|
$this->deactivate(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
|
|
|
|
86
|
|
|
* Remove our cron from the shedule. |
87
|
|
|
* |
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
|
|
public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) { |
91
|
|
|
wp_clear_scheduled_hook( $task ); |
92
|
|
|
} |
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* This function will schedule the cron event. |
96
|
|
|
* |
97
|
|
|
* @param string $task |
|
|
|
|
98
|
|
|
* @return void |
99
|
|
|
*/ |
100
|
|
|
public function schedule( $task = 'lsx_wetu_accommodation_images_cron' ) { |
101
|
|
|
add_action( $task, array( $this, 'process' ) ); |
102
|
|
|
add_action( $task, 'lsx_wetu_accommodation_images_callback' ); |
103
|
|
|
add_action( 'lsx_wetu_accommodation_images_cron', 'lsx_wetu_accommodation_images_callback' ); |
104
|
|
|
wp_schedule_event( time(), 'daily', 'lsx_wetu_accommodation_images_cron' ); |
105
|
|
|
} |
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* This is the function that will be triggered by the cron event. |
109
|
|
|
* |
110
|
|
|
* @return void |
111
|
|
|
*/ |
112
|
|
|
public function process() { |
113
|
|
|
// do your stuff. |
114
|
|
|
} |
|
|
|
|
115
|
|
|
} |
116
|
|
|
Cron::get_instance(); |
117
|
|
|
|
118
|
|
|
function lsx_wetu_accommodation_images_callback() { |
|
|
|
|
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths