PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.5.0
Secure Custom Fields v6.5.0
6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / fields.php
secure-custom-fields / includes Last commit date
Blocks 1 year ago Meta 1 year ago admin 1 year ago ajax 1 year ago api 1 year ago fields 1 year ago forms 1 year ago legacy 1 year ago locations 1 year ago post-types 1 year ago rest-api 1 year ago walkers 1 year ago acf-bidirectional-functions.php 1 year ago acf-field-functions.php 1 year ago acf-field-group-functions.php 1 year ago acf-form-functions.php 1 year ago acf-helper-functions.php 1 year ago acf-hook-functions.php 1 year ago acf-input-functions.php 1 year ago acf-internal-post-type-functions.php 1 year ago acf-meta-functions.php 1 year ago acf-post-functions.php 1 year ago acf-post-type-functions.php 1 year ago acf-taxonomy-functions.php 1 year ago acf-user-functions.php 1 year ago acf-utility-functions.php 1 year ago acf-value-functions.php 1 year ago acf-wp-functions.php 1 year ago assets.php 1 year ago blocks.php 1 year ago class-acf-data.php 1 year ago class-acf-internal-post-type.php 1 year ago class-acf-options-page.php 1 year ago class-acf-site-health.php 1 year ago compatibility.php 1 year ago deprecated.php 1 year ago fields.php 1 year ago index.php 1 year ago l10n.php 1 year ago local-fields.php 1 year ago local-json.php 1 year ago local-meta.php 1 year ago locations.php 1 year ago loop.php 1 year ago media.php 1 year ago rest-api.php 1 year ago revisions.php 1 year ago scf-ui-options-page-functions.php 1 year ago third-party.php 1 year ago upgrades.php 1 year ago validation.php 1 year ago wpml.php 1 year ago
fields.php
456 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 if ( ! class_exists( 'acf_fields' ) ) :
8 #[AllowDynamicProperties]
9 class acf_fields {
10
11 /** @var array Contains an array of field type instances */
12 var $types = array();
13
14
15 /**
16 * This function will setup the class functionality
17 *
18 * @type function
19 * @date 5/03/2014
20 * @since ACF 5.4.0
21 *
22 * @param n/a
23 * @return n/a
24 */
25 function __construct() {
26 /* do nothing */
27 }
28
29 /**
30 * This function will register a field type instance based on a class name or instance.
31 * It will return the instance for further use.
32 *
33 * @since ACF 5.4.0
34 *
35 * @param mixed $field_class Either a class name (string) or instance of acf_field.
36 * @return acf_field The instance of acf_field.
37 */
38 public function register_field_type( $field_class ) {
39 // Allow registering an instance.
40 if ( $field_class instanceof acf_field ) {
41 $this->types[ $field_class->name ] = $field_class;
42 return $field_class;
43 }
44
45 // Allow registering a loaded class name.
46 $instance = new $field_class();
47 $this->types[ $instance->name ] = $instance;
48 return $instance;
49 }
50
51 /**
52 * This function will return a field type instance
53 *
54 * @type function
55 * @date 6/07/2016
56 * @since ACF 5.4.0
57 *
58 * @param $name (string)
59 * @return (mixed)
60 */
61 function get_field_type( $name ) {
62 return isset( $this->types[ $name ] ) ? $this->types[ $name ] : null;
63 }
64
65
66 /**
67 * This function will return true if a field type exists
68 *
69 * @type function
70 * @date 6/07/2016
71 * @since ACF 5.4.0
72 *
73 * @param $name (string)
74 * @return (mixed)
75 */
76 function is_field_type( $name ) {
77 return isset( $this->types[ $name ] );
78 }
79
80
81 /**
82 * This function will store a basic array of info about the field type
83 * to later be overridden by the above register_field_type function
84 *
85 * @type function
86 * @date 29/5/17
87 * @since ACF 5.6.0
88 *
89 * @param $info (array)
90 * @return n/a
91 */
92 function register_field_type_info( $info ) {
93
94 // convert to object
95 $instance = (object) $info;
96 $this->types[ $instance->name ] = $instance;
97 }
98
99
100 /**
101 * This function will return an array of all field types
102 *
103 * @type function
104 * @date 6/07/2016
105 * @since ACF 5.4.0
106 *
107 * @param $name (string)
108 * @return (mixed)
109 */
110 function get_field_types() {
111 return $this->types;
112 }
113 }
114
115
116 // initialize
117 acf()->fields = new acf_fields();
118 endif; // class_exists check
119
120
121 /**
122 * alias of acf()->fields->register_field_type()
123 *
124 * @type function
125 * @date 31/5/17
126 * @since ACF 5.6.0
127 *
128 * @param n/a
129 * @return n/a
130 */
131 function acf_register_field_type( $class ) {
132 return acf()->fields->register_field_type( $class );
133 }
134
135
136 /**
137 * alias of acf()->fields->register_field_type_info()
138 *
139 * @type function
140 * @date 31/5/17
141 * @since ACF 5.6.0
142 *
143 * @param n/a
144 * @return n/a
145 */
146 function acf_register_field_type_info( $info ) {
147 return acf()->fields->register_field_type_info( $info );
148 }
149
150
151 /**
152 * alias of acf()->fields->get_field_type()
153 *
154 * @type function
155 * @date 31/5/17
156 * @since ACF 5.6.0
157 *
158 * @param n/a
159 * @return n/a
160 */
161 function acf_get_field_type( $name ) {
162 return acf()->fields->get_field_type( $name );
163 }
164
165
166 /**
167 * alias of acf()->fields->get_field_types()
168 *
169 * @type function
170 * @date 31/5/17
171 * @since ACF 5.6.0
172 *
173 * @param n/a
174 * @return n/a
175 */
176 function acf_get_field_types( $args = array() ) {
177
178 // default
179 $args = wp_parse_args(
180 $args,
181 array(
182 'public' => true, // true, false
183 )
184 );
185
186 // get field types
187 $field_types = acf()->fields->get_field_types();
188
189 // filter
190 return wp_filter_object_list( $field_types, $args );
191 }
192
193
194 /**
195 * acf_get_field_types_info
196 *
197 * Returns an array containing information about each field type
198 *
199 * @date 18/6/18
200 * @since ACF 5.6.9
201 *
202 * @param type $var Description. Default.
203 * @return type Description.
204 */
205 function acf_get_field_types_info( $args = array() ) {
206
207 // vars
208 $data = array();
209 $field_types = acf_get_field_types();
210
211 // loop
212 foreach ( $field_types as $type ) {
213 $data[ $type->name ] = array_filter(
214 array(
215 'label' => $type->label,
216 'name' => $type->name,
217 'description' => $type->description,
218 'category' => $type->category,
219 'public' => $type->public,
220 'doc_url' => $type->doc_url,
221 'tutorial_url' => $type->tutorial_url,
222 'preview_image' => $type->preview_image,
223 'pro' => $type->pro,
224 )
225 );
226 }
227
228 // return
229 return $data;
230 }
231
232
233 /**
234 * alias of acf()->fields->is_field_type()
235 *
236 * @type function
237 * @date 31/5/17
238 * @since ACF 5.6.0
239 *
240 * @param n/a
241 * @return n/a
242 */
243 function acf_is_field_type( $name = '' ) {
244 return acf()->fields->is_field_type( $name );
245 }
246
247
248 /**
249 * This function will return a field type's property
250 *
251 * @type function
252 * @date 1/10/13
253 * @since ACF 5.0.0
254 *
255 * @param n/a
256 * @return (array)
257 */
258 function acf_get_field_type_prop( $name = '', $prop = '' ) {
259 $type = acf_get_field_type( $name );
260 return ( $type && isset( $type->$prop ) ) ? $type->$prop : null;
261 }
262
263
264 /**
265 * This function will return the label of a field type
266 *
267 * @type function
268 * @date 1/10/13
269 * @since ACF 5.0.0
270 *
271 * @param n/a
272 * @return (array)
273 */
274 function acf_get_field_type_label( $name = '' ) {
275 $label = acf_get_field_type_prop( $name, 'label' );
276 return $label ? $label : '<span class="acf-js-tooltip" title="' . __( 'Field type does not exist', 'secure-custom-fields' ) . '">' . __( 'Unknown', 'secure-custom-fields' ) . '</span>';
277 }
278
279 /**
280 * Returns the value of a field type "supports" property.
281 *
282 * @since ACF 6.2.5
283 *
284 * @param string $name The name of the field type.
285 * @param string $prop The name of the supports property.
286 * @param mixed $default The default value if the property is not set.
287 *
288 * @return mixed The value of the supports property which may be false, or $default on failure.
289 */
290 function acf_field_type_supports( $name = '', $prop = '', $default = false ) {
291 $supports = acf_get_field_type_prop( $name, 'supports' );
292 if ( ! is_array( $supports ) ) {
293 return $default;
294 }
295 return isset( $supports[ $prop ] ) ? $supports[ $prop ] : $default;
296 }
297
298
299 /**
300 *
301 * @deprecated
302 * @see acf_is_field_type()
303 *
304 * @type function
305 * @date 1/10/13
306 * @since ACF 5.0.0
307 *
308 * @param $type (string)
309 * @return (boolean)
310 */
311 function acf_field_type_exists( $type = '' ) {
312 return acf_is_field_type( $type );
313 }
314
315 /**
316 * Returns an array of localised field categories.
317 *
318 * @since ACF 6.1
319 *
320 * @return array
321 */
322 function acf_get_field_categories_i18n() {
323
324 $categories_i18n = array(
325 'basic' => __( 'Basic', 'secure-custom-fields' ),
326 'content' => __( 'Content', 'secure-custom-fields' ),
327 'choice' => __( 'Choice', 'secure-custom-fields' ),
328 'relational' => __( 'Relational', 'secure-custom-fields' ),
329 'advanced' => __( 'Advanced', 'secure-custom-fields' ),
330 'layout' => __( 'Layout', 'secure-custom-fields' ),
331 'pro' => __( 'PRO', 'secure-custom-fields' ),
332 );
333
334 return apply_filters( 'acf/localized_field_categories', $categories_i18n );
335 }
336
337
338 /**
339 * Returns an multi-dimensional array of field types "name => label" grouped by category
340 *
341 * @since ACF 5.0.0
342 *
343 * @return array
344 */
345 function acf_get_grouped_field_types() {
346
347 // vars
348 $types = acf_get_field_types();
349 $groups = array();
350 $l10n = acf_get_field_categories_i18n();
351
352 // loop
353 foreach ( $types as $type ) {
354
355 // translate
356 $cat = $type->category;
357 $cat = isset( $l10n[ $cat ] ) ? $l10n[ $cat ] : $cat;
358
359 // append
360 $groups[ $cat ][ $type->name ] = $type->label;
361 }
362
363 // filter
364 $groups = apply_filters( 'acf/get_field_types', $groups );
365
366 // return
367 return $groups;
368 }
369
370 /**
371 * Returns an array of tabs for a field type.
372 * We combine a list of default tabs with filtered tabs.
373 * I.E. Default tabs should be static and should not be changed by the
374 * filtered tabs.
375 *
376 * @since ACF 6.1
377 *
378 * @return array Key/value array of the default settings tabs for field type settings.
379 */
380 function acf_get_combined_field_type_settings_tabs() {
381 $default_field_type_settings_tabs = array(
382 'general' => __( 'General', 'secure-custom-fields' ),
383 'validation' => __( 'Validation', 'secure-custom-fields' ),
384 'presentation' => __( 'Presentation', 'secure-custom-fields' ),
385 'conditional_logic' => __( 'Conditional Logic', 'secure-custom-fields' ),
386 'advanced' => __( 'Advanced', 'secure-custom-fields' ),
387 );
388
389 $field_type_settings_tabs = (array) apply_filters( 'acf/field_group/additional_field_settings_tabs', array() );
390
391 // remove any default tab values from filter tabs.
392 foreach ( $field_type_settings_tabs as $key => $tab ) {
393 if ( isset( $default_field_type_settings_tabs[ $key ] ) ) {
394 unset( $field_type_settings_tabs[ $key ] );
395 }
396 }
397
398 $combined_field_type_settings_tabs = array_merge( $default_field_type_settings_tabs, $field_type_settings_tabs );
399
400 return $combined_field_type_settings_tabs;
401 }
402
403
404
405 /**
406 * Get the PRO only fields and their core metadata.
407 *
408 * @since ACF 6.1
409 *
410 * @return array An array of all the pro field types and their field type selection required meta data.
411 */
412 function acf_get_pro_field_types() {
413 return array(
414 'clone' => array(
415 'name' => 'clone',
416 'label' => _x( 'Clone', 'noun', 'secure-custom-fields' ),
417 'doc_url' => 'https://developer.wordpress.org/secure-custom-fields/features/fields/clone/',
418 'preview_image' => acf_get_url() . '/assets/images/field-type-previews/field-preview-clone.png',
419 'description' => __( 'This allows you to select and display existing fields. It does not duplicate any fields in the database, but loads and displays the selected fields at run-time. The Clone field can either replace itself with the selected fields or display the selected fields as a group of subfields.', 'secure-custom-fields' ),
420 'tutorial_url' => 'https://developer.wordpress.org/secure-custom-fields/features/fields/clone/clone-tutorial/',
421 'category' => 'layout',
422 'pro' => false,
423 ),
424 'flexible_content' => array(
425 'name' => 'flexible_content',
426 'label' => __( 'Flexible Content', 'secure-custom-fields' ),
427 'doc_url' => 'https://developer.wordpress.org/secure-custom-fields/features/fields/flexible-content/',
428 'preview_image' => acf_get_url() . '/assets/images/field-type-previews/field-preview-flexible-content.png',
429 'description' => __( 'This provides a simple, structured, layout-based editor. The Flexible Content field allows you to define, create and manage content with total control by using layouts and subfields to design the available blocks.', 'secure-custom-fields' ),
430 'tutorial_url' => 'https://developer.wordpress.org/secure-custom-fields/features/fields/flexible-content/flexible-content-tutorial/',
431 'category' => 'layout',
432 'pro' => false,
433 ),
434 'gallery' => array(
435 'name' => 'gallery',
436 'label' => __( 'Gallery', 'secure-custom-fields' ),
437 'doc_url' => 'https://developer.wordpress.org/secure-custom-fields/features/fields/gallery/',
438 'preview_image' => acf_get_url() . '/assets/images/field-type-previews/field-preview-gallery.png',
439 'description' => __( 'This provides an interactive interface for managing a collection of attachments. Most settings are similar to the Image field type. Additional settings allow you to specify where new attachments are added in the gallery and the minimum/maximum number of attachments allowed.', 'secure-custom-fields' ),
440 'tutorial_url' => 'https://developer.wordpress.org/secure-custom-fields/features/fields/gallery/gallery-tutorial/',
441 'category' => 'content',
442 'pro' => false,
443 ),
444 'repeater' => array(
445 'name' => 'repeater',
446 'label' => __( 'Repeater', 'secure-custom-fields' ),
447 'doc_url' => 'https://developer.wordpress.org/secure-custom-fields/features/fields/repeater/',
448 'preview_image' => acf_get_url() . '/assets/images/field-type-previews/field-preview-repeater.png',
449 'description' => __( 'This provides a solution for repeating content such as slides, team members, and call-to-action tiles, by acting as a parent to a set of subfields which can be repeated again and again.', 'secure-custom-fields' ),
450 'tutorial_url' => 'https://developer.wordpress.org/secure-custom-fields/features/fields/repeater/repeater-tutorial/',
451 'category' => 'layout',
452 'pro' => false,
453 ),
454 );
455 }
456