Completed
Push — 677-feature/add-wp-cli-support ( 54d18b...8a68ba )
by
unknown
04:51
created

BulkDelete::is_cli_running()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 6
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\CLI\CLI;
8
use BulkWP\BulkDelete\Core\Comments\DeleteCommentsPage;
9
use BulkWP\BulkDelete\Core\Comments\Modules\DeleteCommentsByAuthorModule;
10
use BulkWP\BulkDelete\Core\Comments\Modules\DeleteCommentsByIPModule;
11
use BulkWP\BulkDelete\Core\Cron\CronListPage;
12
use BulkWP\BulkDelete\Core\Metas\DeleteMetasPage;
13
use BulkWP\BulkDelete\Core\Metas\Modules\DeleteCommentMetaModule;
14
use BulkWP\BulkDelete\Core\Metas\Modules\DeletePostMetaModule;
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\DeleteUsersByUserMetaModule;
34
use BulkWP\BulkDelete\Core\Users\Modules\DeleteUsersByUserRoleModule;
35
36 1
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
37
38
/**
39
 * Main Plugin class.
40
 *
41
 * @since 5.0 Converted to Singleton
42
 * @since 6.0.0 Renamed to BulkDelete and added namespace.
43
 */
44
final class BulkDelete {
45
	/**
46
	 * The one true BulkDelete instance.
47
	 *
48
	 * @var BulkDelete
49
	 *
50
	 * @since 5.0
51
	 */
52
	private static $instance;
53
54
	/**
55
	 * Path to the main plugin file.
56
	 *
57
	 * @var string
58
	 */
59
	private $plugin_file;
60
61
	/**
62
	 * Path where translations are stored.
63
	 *
64
	 * @var string
65
	 */
66
	private $translations_path;
67
68
	/**
69
	 * Has the plugin loaded?
70
	 *
71
	 * @since 6.0.0
72
	 *
73
	 * @var bool
74
	 */
75
	private $loaded = false;
76
77
	/**
78
	 * Controller that handles all requests and nonce checks.
79
	 *
80
	 * @var \BulkWP\BulkDelete\Core\Controller
81
	 */
82
	private $controller;
83
84
	/**
85
	 * Upseller responsible for upselling add-ons.
86
	 *
87
	 * @since 6.0.0
88
	 *
89
	 * @var \BulkWP\BulkDelete\Core\Addon\Upseller
90
	 */
91
	private $upseller;
92
93
	/**
94
	 * Bulk Delete Autoloader.
95
	 *
96
	 * Will be used by add-ons to extend the namespace.
97
	 *
98
	 * @var \BulkWP\BulkDelete\BulkDeleteAutoloader
99
	 */
100
	private $loader;
101
102
	/**
103
	 * List of Primary Admin pages.
104
	 *
105
	 * @var \BulkWP\BulkDelete\Core\Base\BaseDeletePage[]
106
	 *
107
	 * @since 6.0.0
108
	 */
109
	private $primary_pages = array();
110
111
	/**
112
	 * List of Secondary Admin pages.
113
	 *
114
	 * @var BasePage[]
115
	 *
116
	 * @since 6.0.0
117
	 */
118
	private $secondary_pages = array();
119
120
	/**
121
	 * Plugin version.
122
	 */
123
	const VERSION = '6.0.2';
124
125
	/**
126
	 * Set the BulkDelete constructor as private.
127
	 *
128
	 * An instance should be created by calling the `get_instance` method.
129
	 *
130
	 * @see BulkDelete::get_instance()
131
	 */
132
	private function __construct() {}
133
134
	/**
135
	 * Main BulkDelete Instance.
136
	 *
137
	 * Insures that only one instance of BulkDelete exists in memory at any one
138
	 * time. Also prevents needing to define globals all over the place.
139
	 *
140
	 * @since     5.0
141
	 * @static
142
	 * @staticvar array $instance
143
	 *
144
	 * @return BulkDelete The one true instance of BulkDelete.
145
	 */
146 4
	public static function get_instance() {
147 4
		if ( ! isset( self::$instance ) && ! ( self::$instance instanceof BulkDelete ) ) {
148 1
			self::$instance = new BulkDelete();
149
		}
150
151 4
		return self::$instance;
152
	}
153
154
	/**
155
	 * Load the plugin if it is not loaded.
156
	 * The plugin will be loaded only it is an admin request or a cron request.
157
	 *
158
	 * This function will be invoked in the `plugins_loaded` hook.
159
	 */
160
	public function load() {
161
		if ( $this->loaded ) {
162
			return;
163
		}
164
165
		if ( ! $this->is_admin_or_cron() ) {
166
			return;
167
		}
168
169
		$this->load_dependencies();
170
		$this->setup_actions();
171
172
		$this->loaded = true;
173
174
		/**
175
		 * Bulk Delete plugin loaded.
176
		 *
177
		 * @since 6.0.0
178
		 *
179
		 * @param string Plugin main file.
180
		 */
181
		do_action( 'bd_loaded', $this->get_plugin_file() );
182
183
		$this->load_primary_pages();
184
	}
185
186
	/**
187
	 * Throw error on object clone.
188
	 *
189
	 * The whole idea of the singleton design pattern is that there is a single
190
	 * object therefore, we don't want the object to be cloned.
191
	 *
192
	 * @since  5.0
193
	 * @access protected
194
	 *
195
	 * @return void
196
	 */
197 1
	public function __clone() {
198 1
		_doing_it_wrong( __FUNCTION__, __( "This class can't be cloned. Use `get_instance()` method to get an instance.", 'bulk-delete' ), '5.0' );
199
	}
200
201
	/**
202
	 * Disable unserializing of the class.
203
	 *
204
	 * @since  5.0
205
	 * @access protected
206
	 *
207
	 * @return void
208
	 */
209 1
	public function __wakeup() {
210 1
		_doing_it_wrong( __FUNCTION__, __( "This class can't be serialized. Use `get_instance()` method to get an instance.", 'bulk-delete' ), '5.0' );
211
	}
212
213
	/**
214
	 * Load all dependencies.
215
	 *
216
	 * @since 6.0.0
217
	 */
218
	private function load_dependencies() {
219
		$this->controller = new Controller();
220
		$this->controller->load();
221
222
		$this->upseller = new Upseller();
223
		$this->upseller->load();
224
225
		if ( $this->is_cli_running() ) {
226
			$cli = new CLI();
227
			$cli->load();
228
		}
229
	}
230
231
	/**
232
	 * Loads the plugin's actions and hooks.
233
	 *
234
	 * @access private
235
	 *
236
	 * @since  5.0
237
	 *
238
	 * @return void
239
	 */
240
	private function setup_actions() {
241
		add_action( 'init', array( $this, 'on_init' ) );
242
243
		add_action( 'admin_menu', array( $this, 'on_admin_menu' ) );
244
	}
245
246
	/**
247
	 * Triggered when the `init` hook is fired.
248
	 *
249
	 * @since 6.0.0
250
	 */
251 1
	public function on_init() {
252 1
		$this->load_textdomain();
253
	}
254
255
	/**
256
	 * Loads the plugin language files.
257
	 *
258
	 * @since  5.0
259
	 */
260 1
	private function load_textdomain() {
261 1
		load_plugin_textdomain( 'bulk-delete', false, $this->get_translations_path() );
262
	}
263
264
	/**
265
	 * Triggered when the `admin_menu` hook is fired.
266
	 *
267
	 * Register all admin pages.
268
	 *
269
	 * @since 6.0.0
270
	 */
271
	public function on_admin_menu() {
272
		foreach ( $this->get_primary_pages() as $page ) {
273
			$page->register();
274
		}
275
276
		\Bulk_Delete_Misc::add_menu();
277
278
		/**
279
		 * Runs just after adding all *delete* menu items to Bulk WP main menu.
280
		 *
281
		 * This action is primarily for adding extra *delete* menu items to the Bulk WP main menu.
282
		 *
283
		 * @since 5.3
284
		 */
285
		do_action( 'bd_after_primary_menus' );
286
287
		/**
288
		 * Runs just before adding non-action menu items to Bulk WP main menu.
289
		 *
290
		 * This action is primarily for adding extra menu items before non-action menu items to the Bulk WP main menu.
291
		 *
292
		 * @since 5.3
293
		 */
294
		do_action( 'bd_before_secondary_menus' );
295
296
		foreach ( $this->get_secondary_pages() as $page ) {
297
			$page->register();
298
		}
299
300
		$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...
301
			\Bulk_Delete::POSTS_PAGE_SLUG,
302
			__( 'Addon Licenses', 'bulk-delete' ),
303
			__( 'Addon Licenses', 'bulk-delete' ),
304
			'activate_plugins',
305
			\Bulk_Delete::ADDON_PAGE_SLUG,
306
			array( 'BD_License', 'display_addon_page' )
307
		);
308
309
		/**
310
		 * Runs just after adding all menu items to Bulk WP main menu.
311
		 *
312
		 * This action is primarily for adding extra menu items to the Bulk WP main menu.
313
		 *
314
		 * @since 5.3
315
		 */
316
		do_action( 'bd_after_all_menus' );
317
	}
318
319
	/**
320
	 * Get the list of registered admin pages.
321
	 *
322
	 * @since 6.0.0
323
	 *
324
	 * @return \BulkWP\BulkDelete\Core\Base\BaseDeletePage[] List of Primary Admin pages.
325
	 */
326
	private function get_primary_pages() {
327
		if ( empty( $this->primary_pages ) ) {
328
			$this->load_primary_pages();
329
		}
330
331
		return $this->primary_pages;
332
	}
333
334
	/**
335
	 * Load Primary admin pages.
336
	 *
337
	 * The pages need to be loaded in `init` hook, since the association between page and modules is needed in cron requests.
338
	 */
339
	private function load_primary_pages() {
340
		$posts_page    = $this->get_delete_posts_admin_page();
341
		$pages_page    = $this->get_delete_pages_admin_page();
342
		$users_page    = $this->get_delete_users_admin_page();
343
		$comments_page = $this->get_delete_comments_admin_page();
344
		$metas_page    = $this->get_delete_metas_admin_page();
345
		$terms_page    = $this->get_delete_terms_admin_page();
346
347
		$this->primary_pages[ $posts_page->get_page_slug() ]    = $posts_page;
348
		$this->primary_pages[ $pages_page->get_page_slug() ]    = $pages_page;
349
		$this->primary_pages[ $users_page->get_page_slug() ]    = $users_page;
350
		$this->primary_pages[ $comments_page->get_page_slug() ] = $comments_page;
351
		$this->primary_pages[ $metas_page->get_page_slug() ]    = $metas_page;
352
		$this->primary_pages[ $terms_page->get_page_slug() ]    = $terms_page;
353
354
		/**
355
		 * List of primary admin pages.
356
		 *
357
		 * @since 6.0.0
358
		 *
359
		 * @param \BulkWP\BulkDelete\Core\Base\BaseDeletePage[] List of Admin pages.
360
		 */
361
		$this->primary_pages = apply_filters( 'bd_primary_pages', $this->primary_pages );
362
	}
363
364
	/**
365
	 * Get Bulk Delete Posts admin page.
366
	 *
367
	 * @return \BulkWP\BulkDelete\Core\Posts\DeletePostsPage
368
	 */
369
	private function get_delete_posts_admin_page() {
370
		$posts_page = new DeletePostsPage( $this->get_plugin_file() );
371
372
		$posts_page->add_module( new DeletePostsByStatusModule() );
373
		$posts_page->add_module( new DeletePostsByCategoryModule() );
374
		$posts_page->add_module( new DeletePostsByTagModule() );
375
		$posts_page->add_module( new DeletePostsByTaxonomyModule() );
376
		$posts_page->add_module( new DeletePostsByPostTypeModule() );
377
		$posts_page->add_module( new DeletePostsByCommentsModule() );
378
		$posts_page->add_module( new DeletePostsByURLModule() );
379
		$posts_page->add_module( new DeletePostsByRevisionModule() );
380
		$posts_page->add_module( new DeletePostsByStickyPostModule() );
381
382
		/**
383
		 * After the modules are registered in the delete posts page.
384
		 *
385
		 * @since 6.0.0
386
		 *
387
		 * @param DeletePostsPage $posts_page The page in which the modules are registered.
388
		 */
389
		do_action( "bd_after_modules_{$posts_page->get_page_slug()}", $posts_page );
390
391
		/**
392
		 * After the modules are registered in a delete page.
393
		 *
394
		 * @since 6.0.0
395
		 *
396
		 * @param BasePage $posts_page The page in which the modules are registered.
397
		 */
398
		do_action( 'bd_after_modules', $posts_page );
399
400
		return $posts_page;
401
	}
402
403
	/**
404
	 * Get Bulk Delete Pages admin page.
405
	 *
406
	 * @since 6.0.0
407
	 *
408
	 * @return \BulkWP\BulkDelete\Core\Pages\DeletePagesPage
409
	 */
410
	private function get_delete_pages_admin_page() {
411
		$pages_page = new DeletePagesPage( $this->get_plugin_file() );
412
413
		$pages_page->add_module( new DeletePagesByStatusModule() );
414
415
		/**
416
		 * After the modules are registered in the delete pages page.
417
		 *
418
		 * @since 6.0.0
419
		 *
420
		 * @param DeletePagesPage $pages_page The page in which the modules are registered.
421
		 */
422
		do_action( "bd_after_modules_{$pages_page->get_page_slug()}", $pages_page );
423
424
		/**
425
		 * After the modules are registered in a delete page.
426
		 *
427
		 * @since 6.0.0
428
		 *
429
		 * @param BasePage $pages_page The page in which the modules are registered.
430
		 */
431
		do_action( 'bd_after_modules', $pages_page );
432
433
		return $pages_page;
434
	}
435
436
	/**
437
	 * Get Bulk Delete Comments admin page.
438
	 *
439
	 * @since 6.1.0
440
	 *
441
	 * @return \BulkWP\BulkDelete\Core\Comments\DeleteCommentsPage
442
	 */
443
	private function get_delete_comments_admin_page() {
444
		$comments_page = new DeleteCommentsPage( $this->get_plugin_file() );
445
446
		$comments_page->add_module( new DeleteCommentsByAuthorModule() );
447
		$comments_page->add_module( new DeleteCommentsByIPModule() );
448
449
		/**
450
		 * After the modules are registered in the delete comments page.
451
		 *
452
		 * @since 6.0.0
453
		 *
454
		 * @param DeleteCommentsPage $comments_page The page in which the modules are registered.
455
		 */
456
		do_action( "bd_after_modules_{$comments_page->get_page_slug()}", $comments_page );
457
458
		/**
459
		 * After the modules are registered in a delete comments page.
460
		 *
461
		 * @since 6.0.0
462
		 *
463
		 * @param BasePage $comments_page The page in which the modules are registered.
464
		 */
465
		do_action( 'bd_after_modules', $comments_page );
466
467
		return $comments_page;
468
	}
469
470
	/**
471
	 * Get Bulk Delete Users admin page.
472
	 *
473
	 * @since 6.0.0
474
	 *
475
	 * @return \BulkWP\BulkDelete\Core\Users\DeleteUsersPage
476
	 */
477
	private function get_delete_users_admin_page() {
478
		$users_page = new DeleteUsersPage( $this->get_plugin_file() );
479
480
		$users_page->add_module( new DeleteUsersByUserRoleModule() );
481
		$users_page->add_module( new DeleteUsersByUserMetaModule() );
482
483
		/**
484
		 * After the modules are registered in the delete users page.
485
		 *
486
		 * @since 6.0.0
487
		 *
488
		 * @param DeleteUsersPage $users_page The page in which the modules are registered.
489
		 */
490
		do_action( "bd_after_modules_{$users_page->get_page_slug()}", $users_page );
491
492
		/**
493
		 * After the modules are registered in a delete page.
494
		 *
495
		 * @since 6.0.0
496
		 *
497
		 * @param BasePage $users_page The page in which the modules are registered.
498
		 */
499
		do_action( 'bd_after_modules', $users_page );
500
501
		return $users_page;
502
	}
503
504
	/**
505
	 * Get Bulk Delete Metas admin page.
506
	 *
507
	 * @since 6.0.0
508
	 *
509
	 * @return \BulkWP\BulkDelete\Core\Metas\DeleteMetasPage
510
	 */
511
	private function get_delete_metas_admin_page() {
512
		$metas_page = new DeleteMetasPage( $this->get_plugin_file() );
513
514
		$metas_page->add_module( new DeletePostMetaModule() );
515
		$metas_page->add_module( new DeleteUserMetaModule() );
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
	/**
739
	 * Returns TRUE if CLI is running. Otherwise FALSE.
740
	 *
741
	 * @since 6.1.0
742
	 */
743
	public function is_cli_running() {
744
		return defined( 'WP_CLI' ) && WP_CLI;
0 ignored issues
show
Bug introduced by
The constant BulkWP\BulkDelete\Core\WP_CLI was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
745
	}
746
}
747