Completed
Push — 567-fix/refactor-system-info-w... ( 773660...9887b5 )
by Sudar
47:35 queued 41:37
created

FeatureAddon   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 83
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register_pages() 0 24 2
A register() 0 11 4
A register_modules_in_page() 0 5 2
1
<?php
2
3
namespace BulkWP\BulkDelete\Core\Addon;
4
5
use BulkWP\BulkDelete\Core\Base\BasePage;
6
7
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
8
9
/**
10
 * A Feature Add-on.
11
 *
12
 * All Feature Add-ons will extend this class.
13
 * A Feature Add-on contains a bunch of modules and may also have Schedulers.
14
 *
15
 * @since 6.0.0
16
 */
17
abstract class FeatureAddon extends BaseAddon {
18
	/**
19
	 * List of pages that are registered by this add-on.
20
	 *
21
	 * @var \BulkWP\BulkDelete\Core\Base\BaseDeletePage[]
22
	 */
23
	protected $pages = array();
24
25
	/**
26
	 * List of modules that are registered by this add-on.
27
	 *
28
	 * This is an associate array, where the key is the item type and value is the array of modules.
29
	 * Eg: $modules['item_type'] = array( $module1, $module2 );
30
	 *
31
	 * @var array
32
	 */
33
	protected $modules = array();
34
35
	/**
36
	 * List of schedulers that are registered by this add-on.
37
	 *
38
	 * @var \BulkWP\BulkDelete\Core\Base\BaseScheduler[]
39
	 */
40
	protected $schedulers = array();
41
42
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
43
	public function register() {
44
		if ( ! empty( $this->pages ) ) {
45
			add_filter( 'bd_primary_pages', array( $this, 'register_pages' ) );
46
		}
47
48
		foreach ( array_keys( $this->modules ) as $item_type ) {
49
			add_action( "bd_after_{$item_type}_modules", array( $this, 'register_modules_in_page' ) );
50
		}
51
52
		foreach ( $this->schedulers as $scheduler ) {
53
			$scheduler->register();
54
		}
55
	}
56
57
	/**
58
	 * Register pages.
59
	 *
60
	 * @param \BulkWP\BulkDelete\Core\Base\BaseDeletePage[] $primary_pages List of registered Primary pages.
61
	 *
62
	 * @return \BulkWP\BulkDelete\Core\Base\BaseDeletePage[] Modified list of primary pages.
63
	 */
64
	public function register_pages( $primary_pages ) {
65
		foreach ( $this->pages as $page ) {
66
			/**
67
			 * After the modules are registered in the delete posts page.
68
			 *
69
			 * @since 6.0.0
70
			 *
71
			 * @param \BulkWP\BulkDelete\Core\Base\BaseDeletePage $page The page in which the modules are registered.
72
			 */
73
			do_action( "bd_after_{$page->get_item_type()}_modules", $page );
74
75
			/**
76
			 * After the modules are registered in a delete page.
77
			 *
78
			 * @since 6.0.0
79
			 *
80
			 * @param BasePage $posts_page The page in which the modules are registered.
81
			 */
82
			do_action( 'bd_after_modules', $page );
83
84
			$primary_pages[ $page->get_page_slug() ] = $page;
85
		}
86
87
		return $primary_pages;
88
	}
89
90
	/**
91
	 * Register modules for a page.
92
	 *
93
	 * @param \BulkWP\BulkDelete\Core\Base\BaseDeletePage $page Page.
94
	 */
95
	public function register_modules_in_page( $page ) {
96
		$modules = $this->modules[ $page->get_item_type() ];
97
98
		foreach ( $modules as $module ) {
99
			$page->add_module( $module );
100
		}
101
	}
102
}
103