Completed
Pull Request — fix/706-generic-operators-logi... (#715)
by
unknown
74:28 queued 71:13
created

BulkDelete::get_system_info_page()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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