Passed
Push — 671-feature/add-mutisite-suppo... ( 54d18b...7c9bd5 )
by
unknown
05:52
created

BulkDelete::__wakeup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace BulkWP\BulkDelete\Core;
4
5
use BulkWP\BulkDelete\Core\Addon\Upseller;
6
use BulkWP\BulkDelete\Core\Base\BasePage;
7
use BulkWP\BulkDelete\Core\Comments\DeleteCommentsPage;
8
use BulkWP\BulkDelete\Core\Comments\Modules\DeleteCommentsByAuthorModule;
9
use BulkWP\BulkDelete\Core\Comments\Modules\DeleteCommentsByIPModule;
10
use BulkWP\BulkDelete\Core\Cron\CronListPage;
11
use BulkWP\BulkDelete\Core\Metas\DeleteMetasPage;
12
use BulkWP\BulkDelete\Core\Metas\Modules\DeleteCommentMetaModule;
13
use BulkWP\BulkDelete\Core\Metas\Modules\DeletePostMetaModule;
14
use BulkWP\BulkDelete\Core\Metas\Modules\DeleteUserMetaModule;
15
use BulkWP\BulkDelete\Core\Pages\DeletePagesPage;
16
use BulkWP\BulkDelete\Core\Pages\Modules\DeletePagesByStatusModule;
17
use BulkWP\BulkDelete\Core\Posts\DeletePostsPage;
18
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByCategoryModule;
19
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByCommentsModule;
20
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByPostTypeModule;
21
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByRevisionModule;
22
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByStatusModule;
23
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByStickyPostModule;
24
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByTagModule;
25
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByTaxonomyModule;
26
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByURLModule;
27
use BulkWP\BulkDelete\Core\SystemInfo\SystemInfoPage;
28
use BulkWP\BulkDelete\Core\Terms\DeleteTermsPage;
29
use BulkWP\BulkDelete\Core\Terms\Modules\DeleteTermsByNameModule;
30
use BulkWP\BulkDelete\Core\Terms\Modules\DeleteTermsByPostCountModule;
31
use BulkWP\BulkDelete\Core\Users\DeleteUsersPage;
32
use BulkWP\BulkDelete\Core\Users\Modules\DeleteUsersByUserMetaModule;
33
use BulkWP\BulkDelete\Core\Users\Modules\DeleteUsersByUserRoleModule;
34
35 1
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
36
37
/**
38
 * Main Plugin class.
39
 *
40
 * @since 5.0 Converted to Singleton
41
 * @since 6.0.0 Renamed to BulkDelete and added namespace.
42
 */
43
final class BulkDelete {
44
	/**
45
	 * The one true BulkDelete instance.
46
	 *
47
	 * @var BulkDelete
48
	 *
49
	 * @since 5.0
50
	 */
51
	private static $instance;
52
53
	/**
54
	 * Path to the main plugin file.
55
	 *
56
	 * @var string
57
	 */
58
	private $plugin_file;
59
60
	/**
61
	 * Path where translations are stored.
62
	 *
63
	 * @var string
64
	 */
65
	private $translations_path;
66
67
	/**
68
	 * Has the plugin loaded?
69
	 *
70
	 * @since 6.0.0
71
	 *
72
	 * @var bool
73
	 */
74
	private $loaded = false;
75
76
	/**
77
	 * Controller that handles all requests and nonce checks.
78
	 *
79
	 * @var \BulkWP\BulkDelete\Core\Controller
80
	 */
81
	private $controller;
82
83
	/**
84
	 * Upseller responsible for upselling add-ons.
85
	 *
86
	 * @since 6.0.0
87
	 *
88
	 * @var \BulkWP\BulkDelete\Core\Addon\Upseller
89
	 */
90
	private $upseller;
91
92
	/**
93
	 * Bulk Delete Autoloader.
94
	 *
95
	 * Will be used by add-ons to extend the namespace.
96
	 *
97
	 * @var \BulkWP\BulkDelete\BulkDeleteAutoloader
98
	 */
99
	private $loader;
100
101
	/**
102
	 * List of Primary Admin pages.
103
	 *
104
	 * @var \BulkWP\BulkDelete\Core\Base\BaseDeletePage[]
105
	 *
106
	 * @since 6.0.0
107
	 */
108
	private $primary_pages = array();
109
110
	/**
111
	 * List of Primary Network Admin pages.
112
	 *
113
	 * @var \BulkWP\BulkDelete\Core\Base\BaseDeletePage[]
114
	 *
115
	 * @since 6.1.0
116
	 */
117
	private $network_primary_pages = array();
118
119
	/**
120
	 * List of Secondary Admin pages.
121
	 *
122
	 * @var BasePage[]
123
	 *
124
	 * @since 6.0.0
125
	 */
126
	private $secondary_pages = array();
127
128
	/**
129
	 * Plugin version.
130
	 */
131
	const VERSION = '6.0.2';
132
133
	/**
134
	 * Set the BulkDelete constructor as private.
135
	 *
136
	 * An instance should be created by calling the `get_instance` method.
137
	 *
138
	 * @see BulkDelete::get_instance()
139
	 */
140
	private function __construct() {}
141
142
	/**
143
	 * Main BulkDelete Instance.
144
	 *
145
	 * Insures that only one instance of BulkDelete exists in memory at any one
146
	 * time. Also prevents needing to define globals all over the place.
147
	 *
148
	 * @since     5.0
149
	 * @static
150
	 * @staticvar array $instance
151
	 *
152
	 * @return BulkDelete The one true instance of BulkDelete.
153
	 */
154 4
	public static function get_instance() {
155 4
		if ( ! isset( self::$instance ) && ! ( self::$instance instanceof BulkDelete ) ) {
156 1
			self::$instance = new BulkDelete();
157
		}
158
159 4
		return self::$instance;
160
	}
161
162
	/**
163
	 * Load the plugin if it is not loaded.
164
	 * The plugin will be loaded only it is an admin request or a cron request.
165
	 *
166
	 * This function will be invoked in the `plugins_loaded` hook.
167
	 */
168
	public function load() {
169
		if ( $this->loaded ) {
170
			return;
171
		}
172
173
		if ( ! $this->is_admin_or_cron() ) {
174
			return;
175
		}
176
177
		$this->load_dependencies();
178
		$this->setup_actions();
179
180
		$this->loaded = true;
181
182
		/**
183
		 * Bulk Delete plugin loaded.
184
		 *
185
		 * @since 6.0.0
186
		 *
187
		 * @param string Plugin main file.
188
		 */
189
		do_action( 'bd_loaded', $this->get_plugin_file() );
190
191
		$this->load_primary_pages();
192
	}
193
194
	/**
195
	 * Throw error on object clone.
196
	 *
197
	 * The whole idea of the singleton design pattern is that there is a single
198
	 * object therefore, we don't want the object to be cloned.
199
	 *
200
	 * @since  5.0
201
	 * @access protected
202
	 *
203
	 * @return void
204
	 */
205 1
	public function __clone() {
206 1
		_doing_it_wrong( __FUNCTION__, __( "This class can't be cloned. Use `get_instance()` method to get an instance.", 'bulk-delete' ), '5.0' );
207
	}
208
209
	/**
210
	 * Disable unserializing of the class.
211
	 *
212
	 * @since  5.0
213
	 * @access protected
214
	 *
215
	 * @return void
216
	 */
217 1
	public function __wakeup() {
218 1
		_doing_it_wrong( __FUNCTION__, __( "This class can't be serialized. Use `get_instance()` method to get an instance.", 'bulk-delete' ), '5.0' );
219
	}
220
221
	/**
222
	 * Load all dependencies.
223
	 *
224
	 * @since 6.0.0
225
	 */
226
	private function load_dependencies() {
227
		$this->controller = new Controller();
228
		$this->controller->load();
229
230
		$this->upseller = new Upseller();
231
		$this->upseller->load();
232
	}
233
234
	/**
235
	 * Loads the plugin's actions and hooks.
236
	 *
237
	 * @access private
238
	 *
239
	 * @since  5.0
240
	 *
241
	 * @return void
242
	 */
243
	private function setup_actions() {
244
		add_action( 'init', array( $this, 'on_init' ) );
245
246
		if ( is_multisite() ) {
247
			add_action( 'network_admin_menu', array( $this, 'on_network_admin_menu' ) );
248
		}
249
		add_action( 'admin_menu', array( $this, 'on_admin_menu' ) );
250
	}
251
252
	/**
253
	 * Triggered when the `init` hook is fired.
254
	 *
255
	 * @since 6.0.0
256
	 */
257 1
	public function on_init() {
258 1
		$this->load_textdomain();
259
	}
260
261
	/**
262
	 * Loads the plugin language files.
263
	 *
264
	 * @since  5.0
265
	 */
266 1
	private function load_textdomain() {
267 1
		load_plugin_textdomain( 'bulk-delete', false, $this->get_translations_path() );
268
	}
269
270
	/**
271
	 * Triggered when the `admin_menu` hook is fired.
272
	 *
273
	 * Register all admin pages.
274
	 *
275
	 * @since 6.0.0
276
	 */
277
	public function on_admin_menu() {
278
		foreach ( $this->get_primary_pages() as $page ) {
279
			$page->register();
280
		}
281
282
		\Bulk_Delete_Misc::add_menu();
283
284
		/**
285
		 * Runs just after adding all *delete* menu items to Bulk WP main menu.
286
		 *
287
		 * This action is primarily for adding extra *delete* menu items to the Bulk WP main menu.
288
		 *
289
		 * @since 5.3
290
		 */
291
		do_action( 'bd_after_primary_menus' );
292
293
		/**
294
		 * Runs just before adding non-action menu items to Bulk WP main menu.
295
		 *
296
		 * This action is primarily for adding extra menu items before non-action menu items to the Bulk WP main menu.
297
		 *
298
		 * @since 5.3
299
		 */
300
		do_action( 'bd_before_secondary_menus' );
301
302
		foreach ( $this->get_secondary_pages() as $page ) {
303
			$page->register();
304
		}
305
306
		$this->addon_page = add_submenu_page(
0 ignored issues
show
Bug Best Practice introduced by
The property addon_page does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
307
			\Bulk_Delete::POSTS_PAGE_SLUG,
308
			__( 'Addon Licenses', 'bulk-delete' ),
309
			__( 'Addon Licenses', 'bulk-delete' ),
310
			'activate_plugins',
311
			\Bulk_Delete::ADDON_PAGE_SLUG,
312
			array( 'BD_License', 'display_addon_page' )
313
		);
314
315
		/**
316
		 * Runs just after adding all menu items to Bulk WP main menu.
317
		 *
318
		 * This action is primarily for adding extra menu items to the Bulk WP main menu.
319
		 *
320
		 * @since 5.3
321
		 */
322
		do_action( 'bd_after_all_menus' );
323
	}
324
325
	/**
326
	 * Triggered when the `network_admin_menu` hook is fired.
327
	 *
328
	 * Register all admin pages.
329
	 *
330
	 * @since 6.1.0
331
	 */
332
	public function on_network_admin_menu() {
333
		foreach ( $this->get_network_primary_pages() as $page ) {
334
			$page->register();
335
		}
336
337
		\Bulk_Delete_Misc::add_menu();
338
339
		/**
340
		 * Runs just after adding all *delete* menu items to Bulk WP main menu.
341
		 *
342
		 * This action is primarily for adding extra *delete* menu items to the Bulk WP main menu.
343
		 *
344
		 * @since 5.3
345
		 */
346
		do_action( 'bd_after_primary_menus' );
347
348
		/**
349
		 * Runs just before adding non-action menu items to Bulk WP main menu.
350
		 *
351
		 * This action is primarily for adding extra menu items before non-action menu items to the Bulk WP main menu.
352
		 *
353
		 * @since 5.3
354
		 */
355
		do_action( 'bd_before_secondary_menus' );
356
357
		foreach ( $this->get_secondary_pages() as $page ) {
358
			$page->register();
359
		}
360
361
		$this->addon_page = add_submenu_page(
0 ignored issues
show
Bug Best Practice introduced by
The property addon_page does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
362
			\Bulk_Delete::POSTS_PAGE_SLUG,
363
			__( 'Addon Licenses', 'bulk-delete' ),
364
			__( 'Addon Licenses', 'bulk-delete' ),
365
			'activate_plugins',
366
			\Bulk_Delete::ADDON_PAGE_SLUG,
367
			array( 'BD_License', 'display_addon_page' )
368
		);
369
370
		/**
371
		 * Runs just after adding all menu items to Bulk WP main menu.
372
		 *
373
		 * This action is primarily for adding extra menu items to the Bulk WP main menu.
374
		 *
375
		 * @since 5.3
376
		 */
377
		do_action( 'bd_after_all_menus' );
378
	}
379
380
	/**
381
	 * Get the list of registered admin pages.
382
	 *
383
	 * @since 6.0.0
384
	 *
385
	 * @return \BulkWP\BulkDelete\Core\Base\BaseDeletePage[] List of Primary Admin pages.
386
	 */
387
	private function get_primary_pages() {
388
		if ( empty( $this->primary_pages ) ) {
389
			$this->load_primary_pages();
390
		}
391
392
		return $this->primary_pages;
393
	}
394
395
	/**
396
	 * Get the list of registered network admin pages.
397
	 *
398
	 * @since 6.1.0
399
	 *
400
	 * @return \BulkWP\BulkDelete\Core\Base\BaseDeletePage[] List of Primary Admin pages.
401
	 */
402
	private function get_network_primary_pages() {
403
		if ( empty( $this->network_primary_pages ) ) {
404
			$this->load_network_primary_pages();
405
		}
406
407
		return $this->network_primary_pages;
408
	}
409
410
	/**
411
	 * Load Primary admin pages.
412
	 *
413
	 * The pages need to be loaded in `init` hook, since the association between page and modules is needed in cron requests.
414
	 */
415
	private function load_primary_pages() {
416
		$posts_page    = $this->get_delete_posts_admin_page();
417
		$pages_page    = $this->get_delete_pages_admin_page();
418
		$users_page    = $this->get_delete_users_admin_page();
419
		$comments_page = $this->get_delete_comments_admin_page();
420
		$metas_page    = $this->get_delete_metas_admin_page();
421
		$terms_page    = $this->get_delete_terms_admin_page();
422
423
		$this->primary_pages[ $posts_page->get_page_slug() ]    = $posts_page;
424
		$this->primary_pages[ $pages_page->get_page_slug() ]    = $pages_page;
425
		$this->primary_pages[ $users_page->get_page_slug() ]    = $users_page;
426
		$this->primary_pages[ $comments_page->get_page_slug() ] = $comments_page;
427
		$this->primary_pages[ $metas_page->get_page_slug() ]    = $metas_page;
428
		$this->primary_pages[ $terms_page->get_page_slug() ]    = $terms_page;
429
430
		/**
431
		 * List of primary admin pages.
432
		 *
433
		 * @since 6.0.0
434
		 *
435
		 * @param \BulkWP\BulkDelete\Core\Base\BaseDeletePage[] List of Admin pages.
436
		 */
437
		$this->primary_pages = apply_filters( 'bd_primary_pages', $this->primary_pages );
438
	}
439
440
	/**
441
	 * Load Primary network admin pages.
442
	 *
443
	 * The pages need to be loaded in `init` hook, since the association between page and modules is needed in cron requests.
444
	 */
445
	private function load_network_primary_pages() {
446
		$posts_page = $this->get_delete_posts_admin_page();
447
		$users_page = $this->get_delete_users_admin_page();
448
449
		$this->network_primary_pages[ $posts_page->get_page_slug() ] = $posts_page;
450
		$this->network_primary_pages[ $users_page->get_page_slug() ] = $users_page;
451
452
		/**
453
		 * List of primary network admin pages.
454
		 *
455
		 * @since 6.1.0
456
		 *
457
		 * @param \BulkWP\BulkDelete\Core\Base\BaseDeletePage[] List of Admin pages.
458
		 */
459
		$this->network_primary_pages = apply_filters( 'bd_primary_pages', $this->network_primary_pages );
460
	}
461
462
	/**
463
	 * Get Bulk Delete Posts admin page.
464
	 *
465
	 * @return \BulkWP\BulkDelete\Core\Posts\DeletePostsPage
466
	 */
467
	private function get_delete_posts_admin_page() {
468
		$posts_page = new DeletePostsPage( $this->get_plugin_file() );
469
470
		$posts_page->add_module( new DeletePostsByStatusModule() );
471
		$posts_page->add_module( new DeletePostsByCategoryModule() );
472
		$posts_page->add_module( new DeletePostsByTagModule() );
473
		$posts_page->add_module( new DeletePostsByTaxonomyModule() );
474
		$posts_page->add_module( new DeletePostsByPostTypeModule() );
475
		$posts_page->add_module( new DeletePostsByCommentsModule() );
476
		$posts_page->add_module( new DeletePostsByURLModule() );
477
		$posts_page->add_module( new DeletePostsByRevisionModule() );
478
		$posts_page->add_module( new DeletePostsByStickyPostModule() );
479
480
		/**
481
		 * After the modules are registered in the delete posts page.
482
		 *
483
		 * @since 6.0.0
484
		 *
485
		 * @param DeletePostsPage $posts_page The page in which the modules are registered.
486
		 */
487
		do_action( "bd_after_modules_{$posts_page->get_page_slug()}", $posts_page );
488
489
		/**
490
		 * After the modules are registered in a delete page.
491
		 *
492
		 * @since 6.0.0
493
		 *
494
		 * @param BasePage $posts_page The page in which the modules are registered.
495
		 */
496
		do_action( 'bd_after_modules', $posts_page );
497
498
		return $posts_page;
499
	}
500
501
	/**
502
	 * Get Bulk Delete Pages admin page.
503
	 *
504
	 * @since 6.0.0
505
	 *
506
	 * @return \BulkWP\BulkDelete\Core\Pages\DeletePagesPage
507
	 */
508
	private function get_delete_pages_admin_page() {
509
		$pages_page = new DeletePagesPage( $this->get_plugin_file() );
510
511
		$pages_page->add_module( new DeletePagesByStatusModule() );
512
513
		/**
514
		 * After the modules are registered in the delete pages page.
515
		 *
516
		 * @since 6.0.0
517
		 *
518
		 * @param DeletePagesPage $pages_page The page in which the modules are registered.
519
		 */
520
		do_action( "bd_after_modules_{$pages_page->get_page_slug()}", $pages_page );
521
522
		/**
523
		 * After the modules are registered in a delete page.
524
		 *
525
		 * @since 6.0.0
526
		 *
527
		 * @param BasePage $pages_page The page in which the modules are registered.
528
		 */
529
		do_action( 'bd_after_modules', $pages_page );
530
531
		return $pages_page;
532
	}
533
534
	/**
535
	 * Get Bulk Delete Comments admin page.
536
	 *
537
	 * @since 6.1.0
538
	 *
539
	 * @return \BulkWP\BulkDelete\Core\Comments\DeleteCommentsPage
540
	 */
541
	private function get_delete_comments_admin_page() {
542
		$comments_page = new DeleteCommentsPage( $this->get_plugin_file() );
543
544
		$comments_page->add_module( new DeleteCommentsByAuthorModule() );
545
		$comments_page->add_module( new DeleteCommentsByIPModule() );
546
547
		/**
548
		 * After the modules are registered in the delete comments page.
549
		 *
550
		 * @since 6.0.0
551
		 *
552
		 * @param DeleteCommentsPage $comments_page The page in which the modules are registered.
553
		 */
554
		do_action( "bd_after_modules_{$comments_page->get_page_slug()}", $comments_page );
555
556
		/**
557
		 * After the modules are registered in a delete comments page.
558
		 *
559
		 * @since 6.0.0
560
		 *
561
		 * @param BasePage $comments_page The page in which the modules are registered.
562
		 */
563
		do_action( 'bd_after_modules', $comments_page );
564
565
		return $comments_page;
566
	}
567
568
	/**
569
	 * Get Bulk Delete Users admin page.
570
	 *
571
	 * @since 6.0.0
572
	 *
573
	 * @return \BulkWP\BulkDelete\Core\Users\DeleteUsersPage
574
	 */
575
	private function get_delete_users_admin_page() {
576
		$users_page = new DeleteUsersPage( $this->get_plugin_file() );
577
578
		$users_page->add_module( new DeleteUsersByUserRoleModule() );
579
		$users_page->add_module( new DeleteUsersByUserMetaModule() );
580
581
		/**
582
		 * After the modules are registered in the delete users page.
583
		 *
584
		 * @since 6.0.0
585
		 *
586
		 * @param DeleteUsersPage $users_page The page in which the modules are registered.
587
		 */
588
		do_action( "bd_after_modules_{$users_page->get_page_slug()}", $users_page );
589
590
		/**
591
		 * After the modules are registered in a delete page.
592
		 *
593
		 * @since 6.0.0
594
		 *
595
		 * @param BasePage $users_page The page in which the modules are registered.
596
		 */
597
		do_action( 'bd_after_modules', $users_page );
598
599
		return $users_page;
600
	}
601
602
	/**
603
	 * Get Bulk Delete Metas admin page.
604
	 *
605
	 * @since 6.0.0
606
	 *
607
	 * @return \BulkWP\BulkDelete\Core\Metas\DeleteMetasPage
608
	 */
609
	private function get_delete_metas_admin_page() {
610
		$metas_page = new DeleteMetasPage( $this->get_plugin_file() );
611
612
		$metas_page->add_module( new DeletePostMetaModule() );
613
		$metas_page->add_module( new DeleteUserMetaModule() );
614
		$metas_page->add_module( new DeleteCommentMetaModule() );
615
616
		/**
617
		 * After the modules are registered in the delete metas page.
618
		 *
619
		 * @since 6.0.0
620
		 *
621
		 * @param DeleteMetasPage $metas_page The page in which the modules are registered.
622
		 */
623
		do_action( "bd_after_modules_{$metas_page->get_page_slug()}", $metas_page );
624
625
		/**
626
		 * After the modules are registered in a delete page.
627
		 *
628
		 * @since 6.0.0
629
		 *
630
		 * @param BasePage $metas_page The page in which the modules are registered.
631
		 */
632
		do_action( 'bd_after_modules', $metas_page );
633
634
		return $metas_page;
635
	}
636
637
	/**
638
	 * Get Bulk Delete Terms admin page.
639
	 *
640
	 * @since 6.0.0
641
	 *
642
	 * @return \BulkWP\BulkDelete\Core\Terms\DeleteTermsPage
643
	 */
644
	private function get_delete_terms_admin_page() {
645
		$terms_page = new DeleteTermsPage( $this->get_plugin_file() );
646
647
		$terms_page->add_module( new DeleteTermsByNameModule() );
648
		$terms_page->add_module( new DeleteTermsByPostCountModule() );
649
650
		/**
651
		 * After the modules are registered in the delete terms page.
652
		 *
653
		 * @since 6.0.0
654
		 *
655
		 * @param DeleteTermsPage $terms_page The page in which the modules are registered.
656
		 */
657
		do_action( "bd_after_modules_{$terms_page->get_page_slug()}", $terms_page );
658
659
		/**
660
		 * After the modules are registered in a delete page.
661
		 *
662
		 * @since 6.0.0
663
		 *
664
		 * @param BasePage $terms_page The page in which the modules are registered.
665
		 */
666
		do_action( 'bd_after_modules', $terms_page );
667
668
		return $terms_page;
669
	}
670
671
	/**
672
	 * Get the Cron List admin page.
673
	 *
674
	 * @since 6.0.0
675
	 *
676
	 * @return \BulkWP\BulkDelete\Core\Cron\CronListPage
677
	 */
678
	private function get_cron_list_admin_page() {
679
		$cron_list_page = new CronListPage( $this->get_plugin_file() );
680
681
		return $cron_list_page;
682
	}
683
684
	/**
685
	 * Get the System Info page.
686
	 *
687
	 * @since 6.0.0
688
	 *
689
	 * @return \BulkWP\BulkDelete\Core\SystemInfo\SystemInfoPage
690
	 */
691
	private function get_system_info_page() {
692
		$system_info_page = new SystemInfoPage( $this->get_plugin_file() );
693
694
		return $system_info_page;
695
	}
696
697
	/**
698
	 * Get the list of secondary pages.
699
	 *
700
	 * @return BasePage[] Secondary Pages.
701
	 */
702
	private function get_secondary_pages() {
703
		if ( empty( $this->secondary_pages ) ) {
704
			$cron_list_page   = $this->get_cron_list_admin_page();
705
			$system_info_page = $this->get_system_info_page();
706
707
			$this->secondary_pages[ $cron_list_page->get_page_slug() ]   = $cron_list_page;
708
			$this->secondary_pages[ $system_info_page->get_page_slug() ] = $system_info_page;
709
		}
710
711
		/**
712
		 * List of secondary admin pages.
713
		 *
714
		 * @since 6.0.0
715
		 *
716
		 * @param BasePage[] List of Admin pages.
717
		 */
718
		return apply_filters( 'bd_secondary_pages', $this->secondary_pages );
719
	}
720
721
	/**
722
	 * Get path to main plugin file.
723
	 *
724
	 * @return string Plugin file.
725
	 */
726 1
	public function get_plugin_file() {
727 1
		return $this->plugin_file;
728
	}
729
730
	/**
731
	 * Set path to main plugin file.
732
	 *
733
	 * @param string $plugin_file Path to main plugin file.
734
	 */
735 1
	public function set_plugin_file( $plugin_file ) {
736 1
		$this->plugin_file       = $plugin_file;
737 1
		$this->translations_path = dirname( plugin_basename( $this->get_plugin_file() ) ) . '/languages/';
738
	}
739
740
	/**
741
	 * Get path to translations.
742
	 *
743
	 * @return string Translations path.
744
	 */
745 1
	public function get_translations_path() {
746 1
		return $this->translations_path;
747
	}
748
749
	/**
750
	 * Get the hook suffix of a page.
751
	 *
752
	 * @param string $page_slug Page slug.
753
	 *
754
	 * @return string|null Hook suffix if found, null otherwise.
755
	 */
756
	public function get_page_hook_suffix( $page_slug ) {
757
		$admin_page = '';
758
759
		if ( array_key_exists( $page_slug, $this->get_primary_pages() ) ) {
760
			$admin_page = $this->primary_pages[ $page_slug ];
761
		}
762
763
		if ( array_key_exists( $page_slug, $this->get_secondary_pages() ) ) {
764
			$admin_page = $this->secondary_pages[ $page_slug ];
765
		}
766
767
		if ( $admin_page instanceof BasePage ) {
768
			return $admin_page->get_hook_suffix();
769
		}
770
771
		return null;
772
	}
773
774
	/**
775
	 * Register Add-on Namespace.
776
	 *
777
	 * @param \BulkWP\BulkDelete\Core\Addon\AddonInfo $addon_info Add-on Info.
778
	 */
779
	public function register_addon_namespace( $addon_info ) {
780
		$this->loader->add_namespace( 'BulkWP\BulkDelete', $addon_info->get_addon_directory() . 'includes' );
781
	}
782
783
	/**
784
	 * Setter for Autoloader.
785
	 *
786
	 * @param \BulkWP\BulkDelete\BulkDeleteAutoloader $loader Autoloader.
787
	 */
788
	public function set_loader( $loader ) {
789
		$this->loader = $loader;
790
	}
791
792
	/**
793
	 * Get the module object instance by page slug and module class name.
794
	 *
795
	 * @param string $page_slug         Page Slug.
796
	 * @param string $module_class_name Module class name.
797
	 *
798
	 * @return \BulkWP\BulkDelete\Core\Base\BaseModule|null Module object instance or null if no match found.
799
	 */
800
	public function get_module( $page_slug, $module_class_name ) {
801
		$page = $this->get_page( $page_slug );
802
803
		if ( is_null( $page ) ) {
804
			return null;
805
		}
806
807
		return $page->get_module( $module_class_name );
808
	}
809
810
	/**
811
	 * Get the page object instance by page slug.
812
	 *
813
	 * @param string $page_slug Page slug.
814
	 *
815
	 * @return \BulkWP\BulkDelete\Core\Base\BaseDeletePage|null Page object instance or null if no match found.
816
	 */
817
	public function get_page( $page_slug ) {
818
		$pages = $this->get_primary_pages();
819
820
		if ( ! isset( $pages[ $page_slug ] ) ) {
821
			return null;
822
		}
823
824
		return $pages[ $page_slug ];
825
	}
826
827
	/**
828
	 * Used for getting modules for multisite network admin.
829
	 * Get the module object instance by page slug and module class name.
830
	 *
831
	 * @param string $page_slug         Page Slug.
832
	 * @param string $module_class_name Module class name.
833
	 *
834
	 * @return \BulkWP\BulkDelete\Core\Base\BaseModule|null Module object instance or null if no match found.
835
	 */
836
	public function get_network_module( $page_slug, $module_class_name ) {
837
		$page = $this->get_network_page( $page_slug );
838
839
		if ( is_null( $page ) ) {
840
			return null;
841
		}
842
error_log( var_export( $page->get_module( $module_class_name ), true ) );
843
		return $page->get_module( $module_class_name );
844
	}
845
846
	/**
847
	 * Used for multisite network admin dashboard.
848
	 * Get the page object instance by page slug.
849
	 *
850
	 * @param string $page_slug Page slug.
851
	 *
852
	 * @return \BulkWP\BulkDelete\Core\Base\BaseDeletePage|null Page object instance or null if no match found.
853
	 */
854
	public function get_network_page( $page_slug ) {
855
		$pages = $this->get_network_primary_pages();
856
857
		if ( ! isset( $pages[ $page_slug ] ) ) {
858
			return null;
859
		}
860
861
		return $pages[ $page_slug ];
862
	}
863
864
	/**
865
	 * Is the current request an admin or cron request?
866
	 *
867
	 * @return bool True, if yes, False otherwise.
868
	 */
869
	private function is_admin_or_cron() {
870
		return is_admin() || defined( 'DOING_CRON' ) || isset( $_GET['doing_wp_cron'] );
871
	}
872
}
873