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