1 | <?php |
||
12 | class Decorator { |
||
13 | |||
14 | /** |
||
15 | * Instance of the Data_Manager class |
||
16 | * |
||
17 | * @var object |
||
18 | */ |
||
19 | public $data_manager; |
||
20 | |||
21 | /** |
||
22 | * All fields that need to be registeres |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | private $fields = array(); |
||
27 | |||
28 | function __construct( $data_manager ) { |
||
32 | |||
33 | /** |
||
34 | * Registers Carbon Fields using |
||
35 | * the register_rest_field() function |
||
36 | */ |
||
37 | public function register_fields() { |
||
59 | |||
60 | /** |
||
61 | * Return all containers that |
||
62 | * should be visible in the REST API responses |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | public function get_containers() { |
||
71 | |||
72 | /** |
||
73 | * Return all fields attached to a container |
||
74 | * that should be included in the REST API response |
||
75 | * |
||
76 | * @param object $container |
||
77 | * @return array |
||
78 | */ |
||
79 | public function filter_fields( $container ) { |
||
82 | |||
83 | /** |
||
84 | * Wrapper method for loading Post Meta values, |
||
85 | * needed to pass the correct $context |
||
86 | * |
||
87 | * @param array $object Details of current object. |
||
88 | * @param string $field_name Name of field. |
||
89 | * @param WP_REST_Request $request Current request |
||
90 | * @return mixed |
||
91 | */ |
||
92 | public function load_post_meta_field_value( $object, $field_name, $request ) { |
||
96 | |||
97 | /** |
||
98 | * Wrapper method for loading Term Meta values, |
||
99 | * needed to pass the correct $context |
||
100 | * |
||
101 | * @param array $object Details of current object. |
||
102 | * @param string $field_name Name of field. |
||
103 | * @param WP_REST_Request $request Current request |
||
104 | * @return mixed |
||
105 | */ |
||
106 | public function load_term_meta_field_value( $object, $field_name, $request ) { |
||
110 | |||
111 | /** |
||
112 | * Wrapper method for loading Comment Meta values, |
||
113 | * needed to pass the correct $context |
||
114 | * |
||
115 | * @param array $object Details of current object. |
||
116 | * @param string $field_name Name of field. |
||
117 | * @param WP_REST_Request $request Current request |
||
118 | * @return mixed |
||
119 | */ |
||
120 | public function load_comment_meta_field_value( $object, $field_name, $request ) { |
||
124 | |||
125 | /** |
||
126 | * Wrapper method for loading User Meta values, |
||
127 | * needed to pass the correct $context |
||
128 | * |
||
129 | * @param array $object Details of current object. |
||
130 | * @param string $field_name Name of field. |
||
131 | * @param WP_REST_Request $request Current request |
||
132 | * @return mixed |
||
133 | */ |
||
134 | public function load_user_meta_field_value( $object, $field_name, $request ) { |
||
138 | |||
139 | /** |
||
140 | * Get the value of the "$field_name" field |
||
141 | * |
||
142 | * @param array $object Details of current object. |
||
143 | * @param string $field_name Name of field. |
||
144 | * @param WP_REST_Request $request Current request |
||
145 | * @param string $context Post_Meta|Term_Meta|User_Meta|Comment_Meta |
||
146 | * @return mixed |
||
147 | */ |
||
148 | public function load_field_value( $object, $field_name, $request, $context ) { |
||
164 | |||
165 | /** |
||
166 | * Wrapper method for updating Post Meta fields, |
||
167 | * need to pass the correct $context |
||
168 | * |
||
169 | * @param mixed $value The value of the field |
||
170 | * @param object $object The object from the request |
||
171 | * @param string $field_name Name of field |
||
172 | */ |
||
173 | public function update_post_meta_field_value( $value, $object, $field_name ) { |
||
177 | |||
178 | /** |
||
179 | * Wrapper method for updating Term Meta fields, |
||
180 | * need to pass the correct $context |
||
181 | * |
||
182 | * @param mixed $value The value of the field |
||
183 | * @param object $object The object from the request |
||
184 | * @param string $field_name Name of field |
||
185 | */ |
||
186 | public function update_term_meta_field_value( $value, $object, $field_name ) { |
||
190 | |||
191 | /** |
||
192 | * Wrapper method for updating Comment Meta fields, |
||
193 | * need to pass the correct $context |
||
194 | * |
||
195 | * @param mixed $value The value of the field |
||
196 | * @param object $object The object from the request |
||
197 | * @param string $field_name Name of field |
||
198 | */ |
||
199 | public function update_comment_meta_field_value( $value, $object, $field_name ) { |
||
203 | |||
204 | /** |
||
205 | * Wrapper method for updating User Meta fields, |
||
206 | * need to pass the correct $context |
||
207 | * |
||
208 | * @param mixed $value The value of the field |
||
209 | * @param object $object The object from the request |
||
210 | * @param string $field_name Name of field |
||
211 | */ |
||
212 | public function update_user_meta_field_value( $value, $object, $field_name ) { |
||
216 | |||
217 | /** |
||
218 | * Handler for updating custom field data. |
||
219 | * |
||
220 | * @param mixed $value The value of the field |
||
221 | * @param object $object The object from the request |
||
222 | * @param string $field_name Name of field |
||
223 | * @param string $context Post_Meta|Term_Meta|User_Meta|Comment_Meta |
||
224 | */ |
||
225 | public function update_field_value( $value, $object, $field_name, $context ) { |
||
250 | |||
251 | /** |
||
252 | * Get the type of a field |
||
253 | * |
||
254 | * @param object $field |
||
255 | * @return string |
||
256 | */ |
||
257 | public function get_field_type( $field ) { |
||
261 | |||
262 | /** |
||
263 | * Get field based on it's name |
||
264 | * @param string $field_name |
||
265 | * @return array |
||
266 | */ |
||
267 | public function get_current_field( $field_name, $context ) { |
||
272 | |||
273 | /** |
||
274 | * Get Post Meta Container visibility settings |
||
275 | * |
||
276 | * @return array |
||
277 | */ |
||
278 | public static function get_post_meta_container_settings( $container ) { |
||
281 | |||
282 | /** |
||
283 | * Get Term Meta Container visibility settings |
||
284 | * |
||
285 | * @return array |
||
286 | */ |
||
287 | public static function get_term_meta_container_settings( $container ) { |
||
290 | |||
291 | /** |
||
292 | * Get User Meta Container visibility settings |
||
293 | * |
||
294 | * @return string |
||
295 | */ |
||
296 | public static function get_user_meta_container_settings( $container ) { |
||
299 | |||
300 | /** |
||
301 | * Get Comment Meta Container visibility settings |
||
302 | * |
||
303 | * @return string |
||
304 | */ |
||
305 | public static function get_comment_meta_container_settings( $container ) { |
||
308 | |||
309 | /** |
||
310 | * Retrieve ID from object |
||
311 | * based on $context |
||
312 | * |
||
313 | * @param object $object |
||
314 | * @param string $context |
||
315 | * @return string |
||
316 | */ |
||
317 | public static function get_object_id( $object, $context ) { |
||
333 | } |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.