Passed
Pull Request — dev/6.1.0 (#654)
by Sudar
04:47
created

BulkDelete::load_dependencies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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