|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* The abstract class used to create Page Groups within WP-Admin |
|
7
|
|
|
* |
|
8
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
9
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
10
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
11
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
12
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
13
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
14
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
15
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
16
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
17
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
18
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Glynn Quelch <[email protected]> |
|
21
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
|
22
|
|
|
* @package PinkCrab\Perique_Admin_Menu |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace PinkCrab\Perique_Admin_Menu\Group; |
|
26
|
|
|
|
|
27
|
|
|
use PinkCrab\Perique_Admin_Menu\Exception\Group_Exception; |
|
28
|
|
|
use PinkCrab\Perique_Admin_Menu\Page\Page; |
|
29
|
|
|
|
|
30
|
|
|
use PinkCrab\Perique_Admin_Menu\Page\Menu_Page; |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
abstract class Abstract_Group { |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The group title. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
* @required |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $group_title; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The minimum capabilities to show menu group |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
* @default 'manage_options' |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $capability = 'manage_options'; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* The icon to display, either url or dashicon |
|
54
|
|
|
* |
|
55
|
|
|
* @var string |
|
56
|
|
|
* @default 'dashicons-admin-generic' |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $icon = 'dashicons-admin-generic'; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* The primary page |
|
62
|
|
|
* |
|
63
|
|
|
* @var string |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $primary_page; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Array of classnames, of all the pages. |
|
69
|
|
|
* |
|
70
|
|
|
* @var string[] |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $pages; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Holds the groups menu position. |
|
76
|
|
|
* |
|
77
|
|
|
* @var int |
|
78
|
|
|
*/ |
|
79
|
|
|
protected $position = 65; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Get the group title. |
|
83
|
|
|
* |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
|
|
public function get_group_title(): string { |
|
87
|
|
|
if ( $this->group_title === null ) { |
|
88
|
|
|
throw Group_Exception::group_title_undefined( $this ); |
|
89
|
|
|
} |
|
90
|
|
|
return $this->group_title; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Get the minimum capabilities to show menu group |
|
95
|
|
|
* |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function get_capability(): string { |
|
99
|
|
|
return $this->capability; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Get the icon to display, either url or dashicon |
|
104
|
|
|
* |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
|
|
public function get_icon(): string { |
|
108
|
|
|
return $this->icon; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Get the primary page |
|
113
|
|
|
* |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
public function get_primary_page(): string { |
|
117
|
|
|
if ( $this->primary_page === null ) { |
|
118
|
|
|
throw Group_Exception::primary_page_undefined( $this ); |
|
119
|
|
|
} |
|
120
|
|
|
return $this->primary_page; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Get array of classnames, of all the pages. |
|
125
|
|
|
* |
|
126
|
|
|
* @return string[] |
|
127
|
|
|
*/ |
|
128
|
|
|
public function get_pages(): array { |
|
129
|
|
|
return $this->pages; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Set holds the groups menu position. |
|
134
|
|
|
* |
|
135
|
|
|
* @return int |
|
136
|
|
|
*/ |
|
137
|
|
|
public function get_position(): int { |
|
138
|
|
|
return $this->position; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Callback for enqueuing scripts and styles at a group level. |
|
143
|
|
|
* |
|
144
|
|
|
* @param Abstract_Group $group |
|
145
|
|
|
* @param Page $page |
|
146
|
|
|
* @return void |
|
147
|
|
|
* @codeCoverageIgnore This can't be tested as it does nothing and is extended only |
|
148
|
|
|
*/ |
|
149
|
|
|
public function enqueue( Abstract_Group $group, Page $page ): void { |
|
|
|
|
|
|
150
|
|
|
// Do nothing by default. |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Callback for triggering pre load actions for the groups page (at group level) |
|
155
|
|
|
* |
|
156
|
|
|
* @param Abstract_Group $group |
|
157
|
|
|
* @param Page $page |
|
158
|
|
|
* @return void |
|
159
|
|
|
* @codeCoverageIgnore This can't be tested as it does nothing and is extended only |
|
160
|
|
|
*/ |
|
161
|
|
|
public function load( Abstract_Group $group, Page $page ): void { |
|
|
|
|
|
|
162
|
|
|
// Do nothing by default. |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.