PluginProbe
Advanced Custom Fields (ACF®) / 6.0.0
Advanced Custom Fields (ACF®) v6.0.0
6.8.9 6.8.8 6.8.7 6.8.6 6.8.5 6.8.4 6.8.3 6.8.2 6.8.1 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.2 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 All 230 releases
advanced-custom-fields / includes / fields.php
fields.php
381 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 if ( ! class_exists( 'acf_fields' ) ) :
8
9 class acf_fields {
10
11 /** @var array Contains an array of field type instances */
12 var $types = array();
13
14
15 /*
16 * __construct
17 *
18 * This function will setup the class functionality
19 *
20 * @type function
21 * @date 5/03/2014
22 * @since 5.4.0
23 *
24 * @param n/a
25 * @return n/a
26 */
27
28 function __construct() {
29 /* do nothing */
30 }
31
32
33 /*
34 * register_field_type
35 *
36 * This function will register a field type instance
37 *
38 * @type function
39 * @date 6/07/2016
40 * @since 5.4.0
41 *
42 * @param $class (string)
43 * @return n/a
44 */
45
46 function register_field_type( $class ) {
47
48 // allow instance
49 if ( $class instanceof acf_field ) {
50 $this->types[ $class->name ] = $class;
51
52 // allow class name
53 } else {
54 $instance = new $class();
55 $this->types[ $instance->name ] = $instance;
56 }
57 }
58
59
60 /*
61 * get_field_type
62 *
63 * This function will return a field type instance
64 *
65 * @type function
66 * @date 6/07/2016
67 * @since 5.4.0
68 *
69 * @param $name (string)
70 * @return (mixed)
71 */
72
73 function get_field_type( $name ) {
74 return isset( $this->types[ $name ] ) ? $this->types[ $name ] : null;
75 }
76
77
78 /*
79 * is_field_type
80 *
81 * This function will return true if a field type exists
82 *
83 * @type function
84 * @date 6/07/2016
85 * @since 5.4.0
86 *
87 * @param $name (string)
88 * @return (mixed)
89 */
90
91 function is_field_type( $name ) {
92 return isset( $this->types[ $name ] );
93 }
94
95
96 /*
97 * register_field_type_info
98 *
99 * This function will store a basic array of info about the field type
100 * to later be overriden by the above register_field_type function
101 *
102 * @type function
103 * @date 29/5/17
104 * @since 5.6.0
105 *
106 * @param $info (array)
107 * @return n/a
108 */
109
110 function register_field_type_info( $info ) {
111
112 // convert to object
113 $instance = (object) $info;
114 $this->types[ $instance->name ] = $instance;
115 }
116
117
118 /*
119 * get_field_types
120 *
121 * This function will return an array of all field types
122 *
123 * @type function
124 * @date 6/07/2016
125 * @since 5.4.0
126 *
127 * @param $name (string)
128 * @return (mixed)
129 */
130
131 function get_field_types() {
132 return $this->types;
133 }
134 }
135
136
137 // initialize
138 acf()->fields = new acf_fields();
139
140 endif; // class_exists check
141
142
143 /*
144 * acf_register_field_type
145 *
146 * alias of acf()->fields->register_field_type()
147 *
148 * @type function
149 * @date 31/5/17
150 * @since 5.6.0
151 *
152 * @param n/a
153 * @return n/a
154 */
155
156 function acf_register_field_type( $class ) {
157 return acf()->fields->register_field_type( $class );
158 }
159
160
161 /*
162 * acf_register_field_type_info
163 *
164 * alias of acf()->fields->register_field_type_info()
165 *
166 * @type function
167 * @date 31/5/17
168 * @since 5.6.0
169 *
170 * @param n/a
171 * @return n/a
172 */
173
174 function acf_register_field_type_info( $info ) {
175 return acf()->fields->register_field_type_info( $info );
176 }
177
178
179 /*
180 * acf_get_field_type
181 *
182 * alias of acf()->fields->get_field_type()
183 *
184 * @type function
185 * @date 31/5/17
186 * @since 5.6.0
187 *
188 * @param n/a
189 * @return n/a
190 */
191
192 function acf_get_field_type( $name ) {
193 return acf()->fields->get_field_type( $name );
194 }
195
196
197 /*
198 * acf_get_field_types
199 *
200 * alias of acf()->fields->get_field_types()
201 *
202 * @type function
203 * @date 31/5/17
204 * @since 5.6.0
205 *
206 * @param n/a
207 * @return n/a
208 */
209
210 function acf_get_field_types( $args = array() ) {
211
212 // default
213 $args = wp_parse_args(
214 $args,
215 array(
216 'public' => true, // true, false
217 )
218 );
219
220 // get field types
221 $field_types = acf()->fields->get_field_types();
222
223 // filter
224 return wp_filter_object_list( $field_types, $args );
225 }
226
227
228 /**
229 * acf_get_field_types_info
230 *
231 * Returns an array containing information about each field type
232 *
233 * @date 18/6/18
234 * @since 5.6.9
235 *
236 * @param type $var Description. Default.
237 * @return type Description.
238 */
239
240 function acf_get_field_types_info( $args = array() ) {
241
242 // vars
243 $data = array();
244 $field_types = acf_get_field_types();
245
246 // loop
247 foreach ( $field_types as $type ) {
248 $data[ $type->name ] = array(
249 'label' => $type->label,
250 'name' => $type->name,
251 'category' => $type->category,
252 'public' => $type->public,
253 );
254 }
255
256 // return
257 return $data;
258 }
259
260
261 /*
262 * acf_is_field_type
263 *
264 * alias of acf()->fields->is_field_type()
265 *
266 * @type function
267 * @date 31/5/17
268 * @since 5.6.0
269 *
270 * @param n/a
271 * @return n/a
272 */
273
274 function acf_is_field_type( $name = '' ) {
275 return acf()->fields->is_field_type( $name );
276 }
277
278
279 /*
280 * acf_get_field_type_prop
281 *
282 * This function will return a field type's property
283 *
284 * @type function
285 * @date 1/10/13
286 * @since 5.0.0
287 *
288 * @param n/a
289 * @return (array)
290 */
291
292 function acf_get_field_type_prop( $name = '', $prop = '' ) {
293 $type = acf_get_field_type( $name );
294 return ( $type && isset( $type->$prop ) ) ? $type->$prop : null;
295 }
296
297
298 /*
299 * acf_get_field_type_label
300 *
301 * This function will return the label of a field type
302 *
303 * @type function
304 * @date 1/10/13
305 * @since 5.0.0
306 *
307 * @param n/a
308 * @return (array)
309 */
310
311 function acf_get_field_type_label( $name = '' ) {
312 $label = acf_get_field_type_prop( $name, 'label' );
313 return $label ? $label : '<span class="acf-tooltip-js" title="' . __( 'Field type does not exist', 'acf' ) . '">' . __( 'Unknown', 'acf' ) . '</span>';
314 }
315
316
317 /*
318 * acf_field_type_exists (deprecated)
319 *
320 * deprecated in favour of acf_is_field_type()
321 *
322 * @type function
323 * @date 1/10/13
324 * @since 5.0.0
325 *
326 * @param $type (string)
327 * @return (boolean)
328 */
329
330 function acf_field_type_exists( $type = '' ) {
331 return acf_is_field_type( $type );
332 }
333
334
335 /*
336 * acf_get_grouped_field_types
337 *
338 * Returns an multi-dimentional array of field types "name => label" grouped by category
339 *
340 * @type function
341 * @date 1/10/13
342 * @since 5.0.0
343 *
344 * @param n/a
345 * @return (array)
346 */
347
348 function acf_get_grouped_field_types() {
349
350 // vars
351 $types = acf_get_field_types();
352 $groups = array();
353 $l10n = array(
354 'basic' => __( 'Basic', 'acf' ),
355 'content' => __( 'Content', 'acf' ),
356 'choice' => __( 'Choice', 'acf' ),
357 'relational' => __( 'Relational', 'acf' ),
358 'jquery' => __( 'jQuery', 'acf' ),
359 'layout' => __( 'Layout', 'acf' ),
360 );
361
362 // loop
363 foreach ( $types as $type ) {
364
365 // translate
366 $cat = $type->category;
367 $cat = isset( $l10n[ $cat ] ) ? $l10n[ $cat ] : $cat;
368
369 // append
370 $groups[ $cat ][ $type->name ] = $type->label;
371 }
372
373 // filter
374 $groups = apply_filters( 'acf/get_field_types', $groups );
375
376 // return
377 return $groups;
378 }
379
380
381