|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core; |
|
4
|
|
|
|
|
5
|
|
|
use BulkWP\BulkDelete\Core\Base\BasePage; |
|
6
|
|
|
use BulkWP\BulkDelete\Core\Cron\CronListPage; |
|
7
|
|
|
use BulkWP\BulkDelete\Core\Metas\DeleteMetasPage; |
|
8
|
|
|
use BulkWP\BulkDelete\Core\Metas\Metabox\DeleteCommentMetaMetabox; |
|
9
|
|
|
use BulkWP\BulkDelete\Core\Pages\DeletePagesPage; |
|
10
|
|
|
use BulkWP\BulkDelete\Core\Pages\Metabox\DeletePagesByStatusMetabox; |
|
11
|
|
|
use BulkWP\BulkDelete\Core\Posts\DeletePostsPage; |
|
12
|
|
|
use BulkWP\BulkDelete\Core\Posts\Metabox\DeletePostsByCategoryMetabox; |
|
13
|
|
|
use BulkWP\BulkDelete\Core\Posts\Metabox\DeletePostsByPostTypeMetabox; |
|
14
|
|
|
use BulkWP\BulkDelete\Core\Posts\Metabox\DeletePostsByStatusMetabox; |
|
15
|
|
|
use BulkWP\BulkDelete\Core\Posts\Metabox\DeletePostsByTagMetabox; |
|
16
|
|
|
use BulkWP\BulkDelete\Core\Posts\Metabox\DeletePostsByURLMetabox; |
|
17
|
|
|
|
|
18
|
1 |
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Main Plugin class. |
|
22
|
|
|
* |
|
23
|
|
|
* @since 5.0 Converted to Singleton |
|
24
|
|
|
* @since 6.0.0 Renamed to BulkDelete and added namespace. |
|
25
|
|
|
*/ |
|
26
|
|
|
final class BulkDelete { |
|
27
|
|
|
/** |
|
28
|
|
|
* The one true BulkDelete instance. |
|
29
|
|
|
* |
|
30
|
|
|
* @var BulkDelete |
|
31
|
|
|
* |
|
32
|
|
|
* @since 5.0 |
|
33
|
|
|
*/ |
|
34
|
|
|
private static $instance; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Path to the main plugin file. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
private $plugin_file; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Path where translations are stored. |
|
45
|
|
|
* |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
private $translations_path; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Has the plugin loaded? |
|
52
|
|
|
* |
|
53
|
|
|
* @since 6.0.0 |
|
54
|
|
|
* |
|
55
|
|
|
* @var bool |
|
56
|
|
|
*/ |
|
57
|
|
|
private $loaded = false; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Controller that handles all requests and nonce checks. |
|
61
|
|
|
* |
|
62
|
|
|
* @var \BulkWP\BulkDelete\Core\Controller |
|
63
|
|
|
*/ |
|
64
|
|
|
private $controller; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Bulk Delete Autoloader. |
|
68
|
|
|
* |
|
69
|
|
|
* Will be used by add-ons to extend the namespace. |
|
70
|
|
|
* |
|
71
|
|
|
* @var \BulkWP\BulkDelete\BulkDeleteAutoloader |
|
72
|
|
|
*/ |
|
73
|
|
|
private $loader; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* List of Primary Admin pages. |
|
77
|
|
|
* |
|
78
|
|
|
* @var BasePage[] |
|
79
|
|
|
* |
|
80
|
|
|
* @since 6.0.0 |
|
81
|
|
|
*/ |
|
82
|
|
|
private $primary_pages = array(); |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* List of Secondary Admin pages. |
|
86
|
|
|
* |
|
87
|
|
|
* @var BasePage[] |
|
88
|
|
|
* |
|
89
|
|
|
* @since 6.0.0 |
|
90
|
|
|
*/ |
|
91
|
|
|
private $secondary_pages = array(); |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Plugin version. |
|
95
|
|
|
*/ |
|
96
|
|
|
const VERSION = '5.6.1'; |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Set the BulkDelete constructor as private. |
|
100
|
|
|
* |
|
101
|
|
|
* An instance should be created by calling the `get_instance` method. |
|
102
|
|
|
* |
|
103
|
|
|
* @see BulkDelete::get_instance() |
|
104
|
|
|
*/ |
|
105
|
|
|
private function __construct() {} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Main BulkDelete Instance. |
|
109
|
|
|
* |
|
110
|
|
|
* Insures that only one instance of BulkDelete exists in memory at any one |
|
111
|
|
|
* time. Also prevents needing to define globals all over the place. |
|
112
|
|
|
* |
|
113
|
|
|
* @since 5.0 |
|
114
|
|
|
* @static |
|
115
|
|
|
* @staticvar array $instance |
|
116
|
|
|
* |
|
117
|
|
|
* @return BulkDelete The one true instance of BulkDelete. |
|
118
|
|
|
*/ |
|
119
|
5 |
|
public static function get_instance() { |
|
120
|
5 |
|
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof BulkDelete ) ) { |
|
121
|
1 |
|
self::$instance = new BulkDelete(); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
5 |
|
return self::$instance; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Load the plugin if it is not loaded. |
|
129
|
|
|
* |
|
130
|
|
|
* This function will be invoked in the `plugins_loaded` hook. |
|
131
|
|
|
*/ |
|
132
|
1 |
|
public function load() { |
|
133
|
1 |
|
if ( $this->loaded ) { |
|
134
|
|
|
return; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
1 |
|
$this->load_dependencies(); |
|
138
|
1 |
|
$this->setup_actions(); |
|
139
|
|
|
|
|
140
|
1 |
|
$this->loaded = true; |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Bulk Delete plugin loaded. |
|
144
|
|
|
* |
|
145
|
|
|
* @since 6.0.0 |
|
146
|
|
|
* |
|
147
|
|
|
* @param string Plugin main file. |
|
148
|
|
|
*/ |
|
149
|
1 |
|
do_action( 'bd_loaded', $this->get_plugin_file() ); |
|
150
|
1 |
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Throw error on object clone. |
|
154
|
|
|
* |
|
155
|
|
|
* The whole idea of the singleton design pattern is that there is a single |
|
156
|
|
|
* object therefore, we don't want the object to be cloned. |
|
157
|
|
|
* |
|
158
|
|
|
* @since 5.0 |
|
159
|
|
|
* @access protected |
|
160
|
|
|
* |
|
161
|
|
|
* @return void |
|
162
|
|
|
*/ |
|
163
|
1 |
|
public function __clone() { |
|
164
|
1 |
|
_doing_it_wrong( __FUNCTION__, __( "This class can't be cloned. Use `get_instance()` method to get an instance.", 'bulk-delete' ), '5.0' ); |
|
165
|
1 |
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Disable unserializing of the class. |
|
169
|
|
|
* |
|
170
|
|
|
* @since 5.0 |
|
171
|
|
|
* @access protected |
|
172
|
|
|
* |
|
173
|
|
|
* @return void |
|
174
|
|
|
*/ |
|
175
|
1 |
|
public function __wakeup() { |
|
176
|
1 |
|
_doing_it_wrong( __FUNCTION__, __( "This class can't be serialized. Use `get_instance()` method to get an instance.", 'bulk-delete' ), '5.0' ); |
|
177
|
1 |
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Load all dependencies. |
|
181
|
|
|
* |
|
182
|
|
|
* @since 6.0.0 |
|
183
|
|
|
*/ |
|
184
|
1 |
|
private function load_dependencies() { |
|
185
|
1 |
|
$this->controller = new Controller(); |
|
186
|
1 |
|
$this->controller->load(); |
|
187
|
1 |
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Loads the plugin's actions and hooks. |
|
191
|
|
|
* |
|
192
|
|
|
* @access private |
|
193
|
|
|
* |
|
194
|
|
|
* @since 5.0 |
|
195
|
|
|
* |
|
196
|
|
|
* @return void |
|
197
|
|
|
*/ |
|
198
|
1 |
|
private function setup_actions() { |
|
199
|
1 |
|
add_action( 'init', array( $this, 'on_init' ) ); |
|
200
|
|
|
|
|
201
|
1 |
|
add_action( 'admin_menu', array( $this, 'on_admin_menu' ) ); |
|
202
|
1 |
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Triggered when the `init` hook is fired. |
|
206
|
|
|
* |
|
207
|
|
|
* @since 6.0.0 |
|
208
|
|
|
*/ |
|
209
|
1 |
|
public function on_init() { |
|
210
|
1 |
|
$this->load_textdomain(); |
|
211
|
1 |
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Loads the plugin language files. |
|
215
|
|
|
* |
|
216
|
|
|
* @since 5.0 |
|
217
|
|
|
*/ |
|
218
|
1 |
|
private function load_textdomain() { |
|
219
|
1 |
|
load_plugin_textdomain( 'bulk-delete', false, $this->get_translations_path() ); |
|
|
|
|
|
|
220
|
1 |
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Triggered when the `admin_menu` hook is fired. |
|
224
|
|
|
* |
|
225
|
|
|
* Register all admin pages. |
|
226
|
|
|
* |
|
227
|
|
|
* @since 6.0.0 |
|
228
|
|
|
*/ |
|
229
|
|
|
public function on_admin_menu() { |
|
230
|
|
|
foreach ( $this->get_primary_pages() as $page ) { |
|
231
|
|
|
$page->register(); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
\BD_Users_Page::factory(); |
|
235
|
|
|
\Bulk_Delete_Misc::add_menu(); |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* Runs just after adding all *delete* menu items to Bulk WP main menu. |
|
239
|
|
|
* |
|
240
|
|
|
* This action is primarily for adding extra *delete* menu items to the Bulk WP main menu. |
|
241
|
|
|
* |
|
242
|
|
|
* @since 5.3 |
|
243
|
|
|
*/ |
|
244
|
|
|
do_action( 'bd_after_primary_menus' ); |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* Runs just before adding non-action menu items to Bulk WP main menu. |
|
248
|
|
|
* |
|
249
|
|
|
* This action is primarily for adding extra menu items before non-action menu items to the Bulk WP main menu. |
|
250
|
|
|
* |
|
251
|
|
|
* @since 5.3 |
|
252
|
|
|
*/ |
|
253
|
|
|
do_action( 'bd_before_secondary_menus' ); |
|
254
|
|
|
|
|
255
|
|
|
foreach ( $this->get_secondary_pages() as $page ) { |
|
256
|
|
|
$page->register(); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
$this->addon_page = add_submenu_page( |
|
|
|
|
|
|
260
|
|
|
\Bulk_Delete::POSTS_PAGE_SLUG, |
|
261
|
|
|
__( 'Addon Licenses', 'bulk-delete' ), |
|
262
|
|
|
__( 'Addon Licenses', 'bulk-delete' ), |
|
263
|
|
|
'activate_plugins', |
|
264
|
|
|
\Bulk_Delete::ADDON_PAGE_SLUG, |
|
265
|
|
|
array( 'BD_License', 'display_addon_page' ) |
|
266
|
|
|
); |
|
267
|
|
|
|
|
268
|
|
|
\BD_System_Info_page::factory(); |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* Runs just after adding all menu items to Bulk WP main menu. |
|
272
|
|
|
* |
|
273
|
|
|
* This action is primarily for adding extra menu items to the Bulk WP main menu. |
|
274
|
|
|
* |
|
275
|
|
|
* @since 5.3 |
|
276
|
|
|
*/ |
|
277
|
|
|
do_action( 'bd_after_all_menus' ); |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* Get the list of registered admin pages. |
|
282
|
|
|
* |
|
283
|
|
|
* @since 6.0.0 |
|
284
|
|
|
* |
|
285
|
|
|
* @return \BulkWP\BulkDelete\Core\Base\MetaboxPage[] List of Primary Admin pages. |
|
286
|
|
|
*/ |
|
287
|
|
|
public function get_primary_pages() { |
|
288
|
|
|
if ( empty( $this->primary_pages ) ) { |
|
289
|
|
|
$posts_page = $this->get_delete_posts_admin_page(); |
|
290
|
|
|
$pages_page = $this->get_delete_pages_admin_page(); |
|
291
|
|
|
$metas_page = $this->get_delete_metas_admin_page(); |
|
292
|
|
|
|
|
293
|
|
|
$this->primary_pages[ $posts_page->get_page_slug() ] = $posts_page; |
|
294
|
|
|
$this->primary_pages[ $pages_page->get_page_slug() ] = $pages_page; |
|
295
|
|
|
$this->primary_pages[ $metas_page->get_page_slug() ] = $metas_page; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* List of primary admin pages. |
|
300
|
|
|
* |
|
301
|
|
|
* @since 6.0.0 |
|
302
|
|
|
* |
|
303
|
|
|
* @param \BulkWP\BulkDelete\Core\Base\MetaboxPage[] List of Admin pages. |
|
304
|
|
|
*/ |
|
305
|
|
|
return apply_filters( 'bd_primary_pages', $this->primary_pages ); |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* Get Bulk Delete Posts admin page. |
|
310
|
|
|
* |
|
311
|
|
|
* @return \BulkWP\BulkDelete\Core\Posts\DeletePostsPage |
|
312
|
|
|
*/ |
|
313
|
|
|
private function get_delete_posts_admin_page() { |
|
314
|
|
|
$posts_page = new DeletePostsPage( $this->get_plugin_file() ); |
|
315
|
|
|
|
|
316
|
|
|
$posts_page->add_metabox( new DeletePostsByStatusMetabox() ); |
|
317
|
|
|
$posts_page->add_metabox( new DeletePostsByCategoryMetabox() ); |
|
318
|
|
|
$posts_page->add_metabox( new DeletePostsByTagMetabox() ); |
|
319
|
|
|
$posts_page->add_metabox( new DeletePostsByPostTypeMetabox() ); |
|
320
|
|
|
$posts_page->add_metabox( new DeletePostsByURLMetabox() ); |
|
321
|
|
|
|
|
322
|
|
|
return $posts_page; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
/** |
|
326
|
|
|
* Get Bulk Delete Pages admin page. |
|
327
|
|
|
* |
|
328
|
|
|
* @since 6.0.0 |
|
329
|
|
|
* |
|
330
|
|
|
* @return \BulkWP\BulkDelete\Core\Pages\DeletePagesPage |
|
331
|
|
|
*/ |
|
332
|
|
|
private function get_delete_pages_admin_page() { |
|
333
|
|
|
$pages_page = new DeletePagesPage( $this->get_plugin_file() ); |
|
334
|
|
|
|
|
335
|
|
|
$pages_page->add_metabox( new DeletePagesByStatusMetabox() ); |
|
336
|
|
|
|
|
337
|
|
|
return $pages_page; |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* Get Bulk Delete Metas admin page. |
|
342
|
|
|
* |
|
343
|
|
|
* @since 6.0.0 |
|
344
|
|
|
* |
|
345
|
|
|
* @return \BulkWP\BulkDelete\Core\Metas\DeleteMetasPage |
|
346
|
|
|
*/ |
|
347
|
|
|
private function get_delete_metas_admin_page() { |
|
348
|
|
|
$metas_page = new DeleteMetasPage( $this->get_plugin_file() ); |
|
349
|
|
|
|
|
350
|
|
|
$metas_page->add_metabox( new DeleteCommentMetaMetabox() ); |
|
351
|
|
|
|
|
352
|
|
|
return $metas_page; |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* Get the Cron List admin page. |
|
357
|
|
|
* |
|
358
|
|
|
* @since 6.0.0 |
|
359
|
|
|
* |
|
360
|
|
|
* @return \BulkWP\BulkDelete\Core\Cron\CronListPage |
|
361
|
|
|
*/ |
|
362
|
|
|
private function get_cron_list_admin_page() { |
|
363
|
|
|
$cron_list_page = new CronListPage( $this->get_plugin_file() ); |
|
364
|
|
|
|
|
365
|
|
|
return $cron_list_page; |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
/** |
|
369
|
|
|
* Get the list of secondary pages. |
|
370
|
|
|
* |
|
371
|
|
|
* @return BasePage[] Secondary Pages. |
|
372
|
|
|
*/ |
|
373
|
|
|
private function get_secondary_pages() { |
|
374
|
|
|
if ( empty( $this->secondary_pages ) ) { |
|
375
|
|
|
$cron_list_page = $this->get_cron_list_admin_page(); |
|
376
|
|
|
|
|
377
|
|
|
$this->primary_pages[ $cron_list_page->get_page_slug() ] = $cron_list_page; |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
/** |
|
381
|
|
|
* List of secondary admin pages. |
|
382
|
|
|
* |
|
383
|
|
|
* @since 6.0.0 |
|
384
|
|
|
* |
|
385
|
|
|
* @param BasePage[] List of Admin pages. |
|
386
|
|
|
*/ |
|
387
|
|
|
return apply_filters( 'bd_secondary_pages', $this->secondary_pages ); |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
/** |
|
391
|
|
|
* Get path to main plugin file. |
|
392
|
|
|
* |
|
393
|
|
|
* @return string Plugin file. |
|
394
|
|
|
*/ |
|
395
|
2 |
|
public function get_plugin_file() { |
|
396
|
2 |
|
return $this->plugin_file; |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
/** |
|
400
|
|
|
* Set path to main plugin file. |
|
401
|
|
|
* |
|
402
|
|
|
* @param string $plugin_file Path to main plugin file. |
|
403
|
|
|
*/ |
|
404
|
2 |
|
public function set_plugin_file( $plugin_file ) { |
|
405
|
2 |
|
$this->plugin_file = $plugin_file; |
|
406
|
2 |
|
$this->translations_path = dirname( plugin_basename( $this->get_plugin_file() ) ) . '/languages/'; |
|
407
|
2 |
|
} |
|
408
|
|
|
|
|
409
|
|
|
/** |
|
410
|
|
|
* Get path to translations. |
|
411
|
|
|
* |
|
412
|
|
|
* @return string Translations path. |
|
413
|
|
|
*/ |
|
414
|
1 |
|
public function get_translations_path() { |
|
415
|
1 |
|
return $this->translations_path; |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
/** |
|
419
|
|
|
* Getter for Autoloader. |
|
420
|
|
|
* |
|
421
|
|
|
* @return \BulkWP\BulkDelete\BulkDeleteAutoloader |
|
422
|
|
|
*/ |
|
423
|
|
|
public function get_loader() { |
|
424
|
|
|
return $this->loader; |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
/** |
|
428
|
|
|
* Setter for Autoloader. |
|
429
|
|
|
* |
|
430
|
|
|
* @param \BulkWP\BulkDelete\BulkDeleteAutoloader $loader Autoloader. |
|
431
|
|
|
*/ |
|
432
|
|
|
public function set_loader( $loader ) { |
|
433
|
|
|
$this->loader = $loader; |
|
434
|
|
|
} |
|
435
|
|
|
} |
|
436
|
|
|
|