|
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\BaseAddonPage[] |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $pages = array(); |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* List of assets that should be loaded for pages. |
|
27
|
|
|
* |
|
28
|
|
|
* Typically this is used only for built-in pages. Custom pages might load assets themselves. |
|
29
|
|
|
* |
|
30
|
|
|
* @since 6.0.1 |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $page_assets = array(); |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* List of modules that are registered by this add-on. |
|
38
|
|
|
* |
|
39
|
|
|
* This is an associate array, where the key is the item type and value is the array of modules. |
|
40
|
|
|
* Eg: $modules['item_type'] = array( $module1, $module2 ); |
|
41
|
|
|
* |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $modules = array(); |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* List of schedulers that are registered by this add-on. |
|
48
|
|
|
* |
|
49
|
|
|
* @var \BulkWP\BulkDelete\Core\Base\BaseScheduler[] |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $schedulers = array(); |
|
52
|
|
|
|
|
53
|
|
|
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing |
|
54
|
|
|
public function register() { |
|
55
|
|
|
foreach ( $this->pages as $page ) { |
|
56
|
|
|
$page->for_addon( $this->addon_info ); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if ( ! empty( $this->pages ) ) { |
|
60
|
|
|
add_filter( 'bd_primary_pages', array( $this, 'register_pages' ) ); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
foreach ( array_keys( $this->page_assets ) as $page_slug ) { |
|
64
|
|
|
add_action( "bd_after_enqueue_page_assets_for_{$page_slug}", array( $this, 'register_page_assets' ) ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
foreach ( array_keys( $this->modules ) as $page_slug ) { |
|
68
|
|
|
add_action( "bd_after_modules_{$page_slug}", array( $this, 'register_modules_in_page' ) ); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
foreach ( $this->schedulers as $scheduler ) { |
|
72
|
|
|
$scheduler->register(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
add_filter( 'bd_upsell_addons', array( $this, 'hide_upseller_modules' ) ); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Register pages. |
|
80
|
|
|
* |
|
81
|
|
|
* @param \BulkWP\BulkDelete\Core\Base\BaseDeletePage[] $primary_pages List of registered Primary pages. |
|
82
|
|
|
* |
|
83
|
|
|
* @return \BulkWP\BulkDelete\Core\Base\BaseDeletePage[] Modified list of primary pages. |
|
84
|
|
|
*/ |
|
85
|
|
|
public function register_pages( $primary_pages ) { |
|
86
|
|
|
foreach ( $this->pages as $page ) { |
|
87
|
|
|
/** |
|
88
|
|
|
* After the modules are registered in the delete posts page. |
|
89
|
|
|
* |
|
90
|
|
|
* @since 6.0.0 |
|
91
|
|
|
* |
|
92
|
|
|
* @param \BulkWP\BulkDelete\Core\Base\BaseDeletePage $page The page in which the modules are registered. |
|
93
|
|
|
*/ |
|
94
|
|
|
do_action( "bd_after_modules_{$page->get_page_slug()}", $page ); |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* After the modules are registered in a delete page. |
|
98
|
|
|
* |
|
99
|
|
|
* @since 6.0.0 |
|
100
|
|
|
* |
|
101
|
|
|
* @param BasePage $posts_page The page in which the modules are registered. |
|
102
|
|
|
*/ |
|
103
|
|
|
do_action( 'bd_after_modules', $page ); |
|
104
|
|
|
|
|
105
|
|
|
$primary_pages[ $page->get_page_slug() ] = $page; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
return $primary_pages; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Register page assets. |
|
113
|
|
|
* |
|
114
|
|
|
* @since 6.0.1 |
|
115
|
|
|
* |
|
116
|
|
|
* @param \BulkWP\BulkDelete\Core\Base\BaseDeletePage $page Page. |
|
117
|
|
|
*/ |
|
118
|
|
|
public function register_page_assets( $page ) { |
|
119
|
|
|
$assets = $this->page_assets[ $page->get_page_slug() ]; |
|
120
|
|
|
|
|
121
|
|
|
foreach ( $assets as $asset ) { |
|
122
|
|
|
$this->enqueue_asset( $asset ); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Enqueue page assets. |
|
128
|
|
|
* |
|
129
|
|
|
* @since 6.0.1 |
|
130
|
|
|
* |
|
131
|
|
|
* @param array $asset Asset details. |
|
132
|
|
|
*/ |
|
133
|
|
|
protected function enqueue_asset( $asset ) { |
|
134
|
|
|
if ( 'script' === $asset['type'] ) { |
|
135
|
|
|
$this->enqueue_script( $asset ); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
if ( 'style' === $asset['type'] ) { |
|
139
|
|
|
$this->enqueue_style( $asset ); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Enqueue Script. |
|
145
|
|
|
* |
|
146
|
|
|
* @since 6.0.1 |
|
147
|
|
|
* |
|
148
|
|
|
* @param array $asset Asset details. |
|
149
|
|
|
*/ |
|
150
|
|
|
protected function enqueue_script( $asset ) { |
|
151
|
|
|
wp_enqueue_script( |
|
152
|
|
|
$asset['handle'], |
|
153
|
|
|
$asset['file'], |
|
154
|
|
|
$asset['dependencies'], |
|
155
|
|
|
$this->addon_info->get_version(), |
|
156
|
|
|
true |
|
157
|
|
|
); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Enqueue Style. |
|
162
|
|
|
* |
|
163
|
|
|
* @since 6.0.1 |
|
164
|
|
|
* |
|
165
|
|
|
* @param array $asset Asset details. |
|
166
|
|
|
*/ |
|
167
|
|
|
protected function enqueue_style( $asset ) { |
|
168
|
|
|
wp_enqueue_style( |
|
169
|
|
|
$asset['handle'], |
|
170
|
|
|
$asset['file'], |
|
171
|
|
|
$asset['dependencies'], |
|
172
|
|
|
$this->addon_info->get_version() |
|
173
|
|
|
); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Register modules for a page. |
|
178
|
|
|
* |
|
179
|
|
|
* @param \BulkWP\BulkDelete\Core\Base\BaseDeletePage $page Page. |
|
180
|
|
|
*/ |
|
181
|
|
|
public function register_modules_in_page( $page ) { |
|
182
|
|
|
$modules = $this->modules[ $page->get_page_slug() ]; |
|
183
|
|
|
|
|
184
|
|
|
foreach ( $modules as $module ) { |
|
185
|
|
|
$page->add_module( $module ); |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Hide Upseller messages for the modules provided by this add-on. |
|
191
|
|
|
* |
|
192
|
|
|
* @since 6.0.1 |
|
193
|
|
|
* |
|
194
|
|
|
* @param array $modules Modules. |
|
195
|
|
|
* |
|
196
|
|
|
* @return array Modified list of modules. |
|
197
|
|
|
*/ |
|
198
|
|
|
public function hide_upseller_modules( $modules ) { |
|
199
|
|
|
$addon_slug = $this->get_info()->get_addon_slug(); |
|
200
|
|
|
|
|
201
|
|
|
$modified_module_list = array(); |
|
202
|
|
|
|
|
203
|
|
|
foreach ( $modules as $module ) { |
|
204
|
|
|
if ( $module['slug'] === $addon_slug ) { |
|
205
|
|
|
continue; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
$modified_module_list[] = $module; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
return $modified_module_list; |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|