1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Base class for all Scheduler Addons. |
4
|
|
|
* |
5
|
|
|
* @since 5.5 |
6
|
|
|
* @deprecated 6.0.0 Use \BulkWP\BulkDelete\Core\Addon\SchedulerAddon instead. |
7
|
|
|
* |
8
|
|
|
* @author Sudar |
9
|
|
|
* |
10
|
|
|
* @package BulkDelete\Addons\Base |
11
|
|
|
*/ |
12
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Base class for Base Addons. |
16
|
|
|
* |
17
|
|
|
* @abstract |
18
|
|
|
* |
19
|
|
|
* @since 5.5 |
20
|
|
|
*/ |
21
|
|
|
abstract class BD_Scheduler_Addon extends BD_Addon { |
22
|
|
|
/** |
23
|
|
|
* @var No base addon for this scheduler addon. |
24
|
|
|
*/ |
25
|
|
|
protected $no_base_addon = false; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var Base addon name. |
29
|
|
|
*/ |
30
|
|
|
protected $base_addon; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var Base addon version. |
34
|
|
|
*/ |
35
|
|
|
protected $base_addon_version; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var Base addon class name. |
39
|
|
|
*/ |
40
|
|
|
protected $base_addon_class_name; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var Base addon object. |
44
|
|
|
*/ |
45
|
|
|
protected $base_addon_obj; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var Cron Hook to run the scheduler on. |
|
|
|
|
49
|
|
|
*/ |
50
|
|
|
protected $cron_hook; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Use `factory()` method to create instance of this class. |
54
|
|
|
* Don't create instances directly. |
55
|
|
|
* |
56
|
|
|
* @since 5.5 |
57
|
|
|
* @see factory() |
58
|
|
|
*/ |
59
|
|
|
public function __construct() { |
60
|
|
|
parent::__construct(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Check if the base addon is available. |
65
|
|
|
* |
66
|
|
|
* @access protected |
67
|
|
|
* |
68
|
|
|
* @since 5.5 |
69
|
|
|
* |
70
|
|
|
* @todo check for version as well |
71
|
|
|
* |
72
|
|
|
* @param string Base Addon class name. Default null. If not specified then it is auto calculated based on addon name. |
73
|
|
|
* @param mixed|null $addon_class_name |
74
|
|
|
* |
75
|
|
|
* @return bool True if base addon is found, False other wise |
76
|
|
|
*/ |
77
|
|
|
protected function check_base_addon( $addon_class_name = null ) { |
78
|
|
|
if ( null == $addon_class_name ) { |
79
|
|
|
$this->base_addon_class_name = bd_get_addon_class_name( $this->base_addon ); |
|
|
|
|
80
|
|
|
} else { |
81
|
|
|
$this->base_addon_class_name = $addon_class_name; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if ( class_exists( $this->base_addon_class_name ) ) { |
85
|
|
|
// Ugly workaround, since we need to support PHP 5.2 |
86
|
|
|
$this->base_addon_obj = call_user_func( array( $this->base_addon_class_name, 'factory' ) ); |
87
|
|
|
|
88
|
|
|
return true; |
89
|
|
|
} else { |
90
|
|
|
add_action( 'admin_notices', array( $this, 'addon_missing_notice' ) ); |
91
|
|
|
|
92
|
|
|
return false; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Show a notice if the base addon is not available. |
98
|
|
|
* |
99
|
|
|
* @since 5.5 |
100
|
|
|
*/ |
101
|
|
|
public function addon_missing_notice() { |
102
|
|
|
$campaign_args = array( |
103
|
|
|
'utm_source' => 'wpadmin', |
104
|
|
|
'utm_campaign' => 'BulkDelete', |
105
|
|
|
'utm_medium' => 'header-notice', |
106
|
|
|
'utm_content' => $this->addon_code, |
107
|
|
|
); |
108
|
|
|
$addon_url = bd_get_addon_url( $this->base_addon, $campaign_args ); |
109
|
|
|
|
110
|
|
|
printf( |
111
|
|
|
'<div class="error"><p>%s</p></div>', |
112
|
|
|
sprintf( __( '"%s" addon requires "<a href="%s" target="_blank">%s</a>" addon to be installed and activated!', 'bulk-delete' ), $this->addon_name, $addon_url , $this->base_addon ) |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Setup hooks. |
118
|
|
|
* |
119
|
|
|
* @since 5.5 |
120
|
|
|
*/ |
121
|
|
|
protected function setup_hooks() { |
122
|
|
|
add_filter( 'bd_javascript_array', array( $this, 'filter_js_array' ) ); |
123
|
|
|
|
124
|
|
|
$cron_hook = $this->get_cron_hook(); |
125
|
|
|
if ( ! empty( $cron_hook ) ) { |
126
|
|
|
add_action( $cron_hook, array( $this, 'do_delete' ), 10, 1 ); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Filter JS Array and add pro hooks. |
132
|
|
|
* |
133
|
|
|
* @since 5.5 |
134
|
|
|
* |
135
|
|
|
* @param array $js_array JavaScript Array |
136
|
|
|
* |
137
|
|
|
* @return array Modified JavaScript Array |
138
|
|
|
*/ |
139
|
|
|
public function filter_js_array( $js_array ) { |
140
|
|
|
$js_array['pro_iterators'][] = $this->get_module()->get_field_slug(); |
141
|
|
|
|
142
|
|
|
return $js_array; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Hook handler. |
147
|
|
|
* |
148
|
|
|
* @since 5.5 |
149
|
|
|
* |
150
|
|
|
* @param array $delete_options |
151
|
|
|
*/ |
152
|
|
|
public function do_delete( $delete_options ) { |
153
|
|
|
do_action( 'bd_before_scheduler', $this->addon_name ); |
154
|
|
|
$count = $this->get_module()->delete( $delete_options ); |
155
|
|
|
do_action( 'bd_after_scheduler', $this->addon_name, $count ); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Get the cron hook. |
160
|
|
|
* |
161
|
|
|
* @access protected |
162
|
|
|
* |
163
|
|
|
* @since 5.5 |
164
|
|
|
* |
165
|
|
|
* @return string Cron hook. |
166
|
|
|
*/ |
167
|
|
|
protected function get_cron_hook() { |
168
|
|
|
$cron_hook = ''; |
169
|
|
|
if ( null != $this->base_addon_obj ) { |
170
|
|
|
$cron_hook = $this->base_addon_obj->get_cron_hook(); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
return $cron_hook; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Get base module. |
178
|
|
|
* |
179
|
|
|
* @access protected |
180
|
|
|
* |
181
|
|
|
* @since 5.5 |
182
|
|
|
* |
183
|
|
|
* @return object Base module object |
184
|
|
|
*/ |
185
|
|
|
protected function get_module() { |
186
|
|
|
if ( $this->no_base_addon ) { |
187
|
|
|
return $this->base_addon_obj; |
188
|
|
|
} else { |
189
|
|
|
return $this->base_addon_obj->get_module(); |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
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