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 ) |
||
84 | |||
85 | /** |
||
86 | * Internally used to register metaboxes. |
||
87 | */ |
||
88 | public function add_meta_boxes() |
||
102 | |||
103 | /** |
||
104 | * Save metaboxes data for a given page. |
||
105 | * |
||
106 | * @param number $post_id |
||
107 | */ |
||
108 | public function save_meta_boxes( $post_id ) |
||
140 | |||
141 | /** |
||
142 | * Save the data of a single metabox. |
||
143 | * |
||
144 | * @param number $post_id |
||
145 | * @param string $id |
||
146 | * @param array $metabox |
||
147 | */ |
||
148 | public function save_meta_box( $post_id, $id, $metabox ) |
||
162 | |||
163 | /** |
||
164 | * Get the value of the given field. |
||
165 | * |
||
166 | * @param string $metabox_id |
||
167 | * @param string $name |
||
168 | * @param number $post_id |
||
169 | * @return mix |
||
170 | */ |
||
171 | public function get_meta_box_value( $metabox_id, $name, $post_id ) |
||
183 | |||
184 | /** |
||
185 | * Print custom metabox style. |
||
186 | */ |
||
187 | public function print_style() |
||
202 | |||
203 | /** |
||
204 | * Print all errors stored in a transient for a given post ID. |
||
205 | * |
||
206 | * @param number $post_id |
||
207 | * @param array $metabox |
||
208 | */ |
||
209 | public function print_errors( $post_id, $metabox ) |
||
224 | |||
225 | /** |
||
226 | * Initiate the metaboxes by adding action hooks for printing and saving. |
||
227 | */ |
||
228 | private function init() |
||
234 | |||
235 | /** |
||
236 | * Update the form data for the given given metabox. If the $new_instance |
||
237 | * contains new data, it will be saved into the db and if there are any |
||
238 | * validation errors they will be printed. |
||
239 | * |
||
240 | * @param array $metabox |
||
241 | * @param number $post_id |
||
242 | * @param array $new_instance |
||
243 | */ |
||
244 | private function update_form( $metabox, $post_id, array $new_instance = array() ) |
||
262 | |||
263 | /** |
||
264 | * Update post meta for the given post id |
||
265 | * |
||
266 | * @param type $final_instance |
||
267 | * @param type $post_id |
||
268 | */ |
||
269 | private function update_post_meta( $final_instance, $post_id ) |
||
276 | |||
277 | /** |
||
278 | * Get existing meta values from the database. |
||
279 | * |
||
280 | * @param array $metabox |
||
281 | * @param number $post_id |
||
282 | * @return array |
||
283 | */ |
||
284 | private function get_old_instance( $metabox, $post_id ) |
||
298 | |||
299 | /** |
||
300 | * Default arguments for the add() method. |
||
301 | * |
||
302 | * @return array |
||
303 | */ |
||
304 | private function default_args() |
||
314 | } |
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: