1 | <?php |
||
18 | abstract class BD_Base_Page { |
||
19 | /** |
||
20 | * @var string Page Slug. |
||
21 | */ |
||
22 | protected $page_slug; |
||
23 | |||
24 | /** |
||
25 | * @var string Menu action. |
||
26 | */ |
||
27 | protected $menu_action = 'bd_after_primary_menus'; |
||
28 | |||
29 | /** |
||
30 | * @var string Minimum capability needed for viewing this page. |
||
31 | */ |
||
32 | protected $capability = 'manage_options'; |
||
33 | |||
34 | /** |
||
35 | * @var bool Whether sidebar is needed or not. |
||
36 | */ |
||
37 | protected $render_sidebar = true; |
||
38 | |||
39 | /** |
||
40 | * @var string The screen variable for this page. |
||
41 | */ |
||
42 | protected $screen; |
||
43 | |||
44 | /** |
||
45 | * @var array Labels used in this page. |
||
46 | */ |
||
47 | protected $label = array(); |
||
48 | |||
49 | /** |
||
50 | * @var array Messages shown to the user. |
||
51 | */ |
||
52 | protected $messages = array(); |
||
53 | |||
54 | /** |
||
55 | * @var array Actions used in this page. |
||
56 | */ |
||
57 | protected $actions = array(); |
||
58 | |||
59 | /** |
||
60 | * Initialize and setup variables. |
||
61 | * |
||
62 | * @since 5.5.4 |
||
63 | * @abstract |
||
64 | * @return void |
||
65 | */ |
||
66 | abstract protected function initialize(); |
||
67 | |||
68 | /** |
||
69 | * Render body content. |
||
70 | * |
||
71 | * @since 5.5.4 |
||
72 | * @abstract |
||
73 | */ |
||
74 | abstract protected function render_body(); |
||
75 | |||
76 | /** |
||
77 | * Use `factory()` method to create instance of this class. |
||
78 | * Don't create instances directly |
||
79 | * |
||
80 | * @since 5.5.4 |
||
81 | * |
||
82 | * @see factory() |
||
83 | */ |
||
84 | public function __construct() { |
||
87 | |||
88 | /** |
||
89 | * Setup the module. |
||
90 | * |
||
91 | * @since 5.5.4 |
||
92 | */ |
||
93 | protected function setup() { |
||
97 | |||
98 | /** |
||
99 | * Setup hooks. |
||
100 | * |
||
101 | * @since 5.5.4 |
||
102 | */ |
||
103 | protected function setup_hooks() { |
||
110 | |||
111 | /** |
||
112 | * Add menu. |
||
113 | * |
||
114 | * @since 5.5.4 |
||
115 | */ |
||
116 | public function add_menu() { |
||
128 | |||
129 | /** |
||
130 | * Check for nonce before executing the action. |
||
131 | * |
||
132 | * @since 5.5.4 |
||
133 | * @param bool $result The current result. |
||
134 | * @param string $action Action name. |
||
135 | */ |
||
136 | public function nonce_check( $result, $action ) { |
||
145 | |||
146 | /** |
||
147 | * Modify help tabs for the current page. |
||
148 | * |
||
149 | * @since 5.5.4 |
||
150 | * @param array $help_tabs Current list of help tabs. |
||
151 | * @param string $screen Current screen name. |
||
152 | * @return array Modified list of help tabs. |
||
153 | */ |
||
154 | public function render_help_tab( $help_tabs, $screen ) { |
||
161 | |||
162 | /** |
||
163 | * Add help tabs. |
||
164 | * Help tabs can be added by overriding this function in the child class. |
||
165 | * |
||
166 | * @since 5.5.4 |
||
167 | * @param array $help_tabs Current list of help tabs. |
||
168 | * @return array List of help tabs. |
||
169 | */ |
||
170 | protected function add_help_tab( $help_tabs ) { |
||
173 | |||
174 | /** |
||
175 | * Render the page. |
||
176 | * |
||
177 | * @since 5.5.4 |
||
178 | */ |
||
179 | public function render_page() { |
||
204 | |||
205 | /** |
||
206 | * Print nonce fields. |
||
207 | * |
||
208 | * @since 5.5.4 |
||
209 | */ |
||
210 | protected function render_nonce_fields() { |
||
213 | |||
214 | /** |
||
215 | * Render header for the page. |
||
216 | * |
||
217 | * If sidebar is enabled, then it is rendered as well. |
||
218 | * |
||
219 | * @since 5.5.4 |
||
220 | */ |
||
221 | protected function render_header() { |
||
231 | |||
232 | /** |
||
233 | * Render footer. |
||
234 | * |
||
235 | * @since 5.5.4 |
||
236 | */ |
||
237 | protected function render_footer() { |
||
247 | |||
248 | /** |
||
249 | * Modify admin footer in Bulk Delete plugin pages. |
||
250 | */ |
||
251 | public function modify_admin_footer() { |
||
254 | |||
255 | /** |
||
256 | * Getter for screen. |
||
257 | * |
||
258 | * @return string Current value of screen |
||
259 | */ |
||
260 | public function get_screen() { |
||
263 | |||
264 | /** |
||
265 | * Getter for page_slug. |
||
266 | * |
||
267 | * @return string Current value of page_slug |
||
268 | */ |
||
269 | public function get_page_slug() { |
||
272 | } |
||
273 | ?> |
||
274 |
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@return
doc comment to communicate to implementors of these methods what they are expected to return.