1 | <?php |
||
8 | class Manager |
||
9 | { |
||
10 | /** |
||
11 | * @var Singleton The reference to *Singleton* instance of this class |
||
12 | */ |
||
13 | private static $instance; |
||
14 | |||
15 | /** |
||
16 | * @var Array Stores all the registered metaboxes |
||
17 | */ |
||
18 | private $metaboxes = array(); |
||
19 | |||
20 | /** |
||
21 | * Security nonce action |
||
22 | */ |
||
23 | const NONCE_ACTION = 'amarkal_metabox'; |
||
24 | |||
25 | /** |
||
26 | * Returns the *Singleton* instance of this class. |
||
27 | * |
||
28 | * @return Singleton The *Singleton* instance. |
||
29 | */ |
||
30 | public static function get_instance() |
||
38 | |||
39 | /** |
||
40 | * Private constructor to prevent instantiation |
||
41 | */ |
||
42 | private function __construct() |
||
46 | |||
47 | /** |
||
48 | * Add a metabox. |
||
49 | * |
||
50 | * @param string $id |
||
51 | * @param array $args |
||
52 | * @throws \RuntimeException if the given metabox id has already been registered |
||
53 | */ |
||
54 | public function add( $id, array $args ) |
||
63 | |||
64 | /** |
||
65 | * Render a metabox. |
||
66 | * |
||
67 | * @param WP_Post $post |
||
68 | * @param array $args |
||
69 | */ |
||
70 | public function render( $post, $args ) |
||
90 | |||
91 | /** |
||
92 | * Internally used to register metaboxes. |
||
93 | */ |
||
94 | public function add_meta_boxes() |
||
108 | |||
109 | /** |
||
110 | * Save metaboxes data for a given page. |
||
111 | * |
||
112 | * @param number $post_id |
||
113 | */ |
||
114 | public function save_meta_boxes( $post_id ) |
||
150 | |||
151 | /** |
||
152 | * Save the data of a single metabox. |
||
153 | * |
||
154 | * @param number $post_id |
||
155 | * @param string $id |
||
156 | * @param array $metabox |
||
157 | */ |
||
158 | public function save_meta_box( $post_id, $id, $metabox ) |
||
172 | |||
173 | /** |
||
174 | * Print custom metabox style. |
||
175 | */ |
||
176 | public function print_style() |
||
191 | |||
192 | /** |
||
193 | * Print all errors stored in a transient for a given post ID. |
||
194 | * |
||
195 | * @param number $post_id |
||
196 | * @param array $metabox |
||
197 | */ |
||
198 | public function print_errors( $post_id, $metabox ) |
||
213 | |||
214 | /** |
||
215 | * Initiate the metaboxes by adding action hooks for printing and saving. |
||
216 | */ |
||
217 | private function init() |
||
223 | |||
224 | /** |
||
225 | * Update the form data for the given given metabox. If the $new_instance |
||
226 | * contains new data, it will be saved into the db and if there are any |
||
227 | * validation errors they will be printed. |
||
228 | * |
||
229 | * @param array $metabox |
||
230 | * @param number $post_id |
||
231 | * @param array $new_instance |
||
232 | */ |
||
233 | private function update_form( $metabox, $post_id, array $new_instance = array() ) |
||
251 | |||
252 | /** |
||
253 | * Update post meta for the given post id |
||
254 | * |
||
255 | * @param type $final_instance |
||
256 | * @param type $post_id |
||
257 | */ |
||
258 | private function update_post_meta( $final_instance, $post_id ) |
||
265 | |||
266 | /** |
||
267 | * Get existing meta values from the database. |
||
268 | * |
||
269 | * @param array $metabox |
||
270 | * @param number $post_id |
||
271 | * @return array |
||
272 | */ |
||
273 | private function get_old_instance( $metabox, $post_id ) |
||
287 | |||
288 | /** |
||
289 | * Default arguments for the add() method. |
||
290 | * |
||
291 | * @return array |
||
292 | */ |
||
293 | private function default_args() |
||
303 | } |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: