Completed
Pull Request — dev/6.1.0 (#445)
by
unknown
05:11
created

BulkDelete   B

Complexity

Total Complexity 45

Size/Duplication

Total Lines 688
Duplicated Lines 0 %

Test Coverage

Coverage 11.95%

Importance

Changes 8
Bugs 0 Features 1
Metric Value
eloc 141
c 8
b 0
f 1
dl 0
loc 688
ccs 19
cts 159
cp 0.1195
rs 8.8
wmc 45

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