Passed
Push — 671-feature/add-mutisite-suppo... ( 7c9bd5...e10db6 )
by Sudar
05:24
created

BulkDelete   B

Complexity

Total Complexity 46

Size/Duplication

Total Lines 703
Duplicated Lines 0 %

Test Coverage

Coverage 11.8%

Importance

Changes 9
Bugs 0 Features 1
Metric Value
eloc 144
dl 0
loc 703
ccs 19
cts 161
cp 0.118
rs 8.72
c 9
b 0
f 1
wmc 46

30 Methods

Rating   Name   Duplication   Size   Complexity  
A get_module() 0 8 2
A load_primary_pages() 0 23 1
A __clone() 0 2 1
A get_delete_posts_admin_page() 0 32 1
A setup_actions() 0 4 1
A set_loader() 0 2 1
A set_plugin_file() 0 3 1
A get_delete_metas_admin_page() 0 26 1
A get_delete_terms_admin_page() 0 25 1
A get_system_info_page() 0 4 1
A get_delete_comments_admin_page() 0 25 1
A get_primary_pages() 0 6 2
A __construct() 0 1 1
A load_dependencies() 0 6 1
A load_textdomain() 0 2 1
A __wakeup() 0 2 1
A on_admin_menu() 0 46 3
A get_secondary_pages() 0 17 2
A get_instance() 0 6 3
A register_addon_namespace() 0 2 1
A get_page() 0 8 2
A get_delete_users_admin_page() 0 25 1
A get_cron_list_admin_page() 0 4 1
A get_translations_path() 0 2 1
A load() 0 28 4
A get_plugin_file() 0 2 1
A get_delete_pages_admin_page() 0 24 1
A get_page_hook_suffix() 0 16 4
A on_init() 0 2 1
A is_admin_or_cron() 0 2 3

How to fix   Complexity   

Complex Class

Complex classes like BulkDelete often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use BulkDelete, and based on these observations, apply Extract Interface, too.

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
use BulkWP\BulkDelete\Core\Multisite\MultisiteAdminUIBuilder;
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
	 * UI Builder for Multisite.
104
	 *
105
	 * Will be used only in Multisite
106
	 *
107
	 * @since 6.1.0
108
	 *
109
	 * @var \BulkWP\BulkDelete\Multisite\MultisiteAdminUIBuilder
0 ignored issues
show
Bug introduced by
The type BulkWP\BulkDelete\Multis...MultisiteAdminUIBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
110
	 */
111
	private $multisite_ui_builder;
112
113
	/**
114
	 * List of Primary Admin pages.
115
	 *
116
	 * @var \BulkWP\BulkDelete\Core\Base\BaseDeletePage[]
117
	 *
118
	 * @since 6.0.0
119
	 */
120
	private $primary_pages = array();
121
122
	/**
123
	 * List of Secondary Admin pages.
124
	 *
125
	 * @var BasePage[]
126
	 *
127
	 * @since 6.0.0
128
	 */
129
	private $secondary_pages = array();
130
131
	/**
132
	 * Plugin version.
133
	 */
134
	const VERSION = '6.0.2';
135
136
	/**
137
	 * Set the BulkDelete constructor as private.
138
	 *
139
	 * An instance should be created by calling the `get_instance` method.
140
	 *
141
	 * @see BulkDelete::get_instance()
142
	 */
143
	private function __construct() {}
144
145
	/**
146
	 * Main BulkDelete Instance.
147
	 *
148
	 * Insures that only one instance of BulkDelete exists in memory at any one
149
	 * time. Also prevents needing to define globals all over the place.
150
	 *
151
	 * @since     5.0
152
	 * @static
153
	 * @staticvar array $instance
154
	 *
155
	 * @return BulkDelete The one true instance of BulkDelete.
156
	 */
157 4
	public static function get_instance() {
158 4
		if ( ! isset( self::$instance ) && ! ( self::$instance instanceof BulkDelete ) ) {
159 1
			self::$instance = new BulkDelete();
160
		}
161
162 4
		return self::$instance;
163
	}
164
165
	/**
166
	 * Load the plugin if it is not loaded.
167
	 * The plugin will be loaded only it is an admin request or a cron request.
168
	 *
169
	 * This function will be invoked in the `plugins_loaded` hook.
170
	 */
171
	public function load() {
172
		if ( $this->loaded ) {
173
			return;
174
		}
175
176
		if ( ! $this->is_admin_or_cron() ) {
177
			return;
178
		}
179
180
		$this->load_dependencies();
181
		$this->setup_actions();
182
183
		$this->loaded = true;
184
185
		/**
186
		 * Bulk Delete plugin loaded.
187
		 *
188
		 * @since 6.0.0
189
		 *
190
		 * @param string Plugin main file.
191
		 */
192
		do_action( 'bd_loaded', $this->get_plugin_file() );
193
194
		$this->load_primary_pages();
195
196
		if ( is_multisite() ) {
197
			$this->multisite_ui_builder = new MultisiteAdminUIBuilder( $this->get_plugin_file() );
0 ignored issues
show
Documentation Bug introduced by
It seems like new BulkWP\BulkDelete\Co...his->get_plugin_file()) of type BulkWP\BulkDelete\Core\M...MultisiteAdminUIBuilder is incompatible with the declared type BulkWP\BulkDelete\Multis...MultisiteAdminUIBuilder of property $multisite_ui_builder.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

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