advanced-custom-fields
Last commit date
assets
5 years ago
includes
5 years ago
lang
5 years ago
README.md
5 years ago
acf.php
5 years ago
readme.txt
5 years ago
acf.php
658 lines
| 1 | <?php |
| 2 | /* |
| 3 | Plugin Name: Advanced Custom Fields |
| 4 | Plugin URI: https://www.advancedcustomfields.com |
| 5 | Description: Customize WordPress with powerful, professional and intuitive fields. |
| 6 | Version: 5.9.2 |
| 7 | Author: Elliot Condon |
| 8 | Author URI: https://www.advancedcustomfields.com |
| 9 | Text Domain: acf |
| 10 | Domain Path: /lang |
| 11 | */ |
| 12 | |
| 13 | if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 14 | |
| 15 | if( ! class_exists('ACF') ) : |
| 16 | |
| 17 | class ACF { |
| 18 | |
| 19 | /** @var string The plugin version number. */ |
| 20 | var $version = '5.9.2'; |
| 21 | |
| 22 | /** @var array The plugin settings array. */ |
| 23 | var $settings = array(); |
| 24 | |
| 25 | /** @var array The plugin data array. */ |
| 26 | var $data = array(); |
| 27 | |
| 28 | /** @var array Storage for class instances. */ |
| 29 | var $instances = array(); |
| 30 | |
| 31 | /** |
| 32 | * __construct |
| 33 | * |
| 34 | * A dummy constructor to ensure ACF is only setup once. |
| 35 | * |
| 36 | * @date 23/06/12 |
| 37 | * @since 5.0.0 |
| 38 | * |
| 39 | * @param void |
| 40 | * @return void |
| 41 | */ |
| 42 | function __construct() { |
| 43 | // Do nothing. |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * initialize |
| 48 | * |
| 49 | * Sets up the ACF plugin. |
| 50 | * |
| 51 | * @date 28/09/13 |
| 52 | * @since 5.0.0 |
| 53 | * |
| 54 | * @param void |
| 55 | * @return void |
| 56 | */ |
| 57 | function initialize() { |
| 58 | |
| 59 | // Define constants. |
| 60 | $this->define( 'ACF', true ); |
| 61 | $this->define( 'ACF_PATH', plugin_dir_path( __FILE__ ) ); |
| 62 | $this->define( 'ACF_BASENAME', plugin_basename( __FILE__ ) ); |
| 63 | $this->define( 'ACF_VERSION', $this->version ); |
| 64 | $this->define( 'ACF_MAJOR_VERSION', 5 ); |
| 65 | |
| 66 | // Define settings. |
| 67 | $this->settings = array( |
| 68 | 'name' => __('Advanced Custom Fields', 'acf'), |
| 69 | 'slug' => dirname( ACF_BASENAME ), |
| 70 | 'version' => ACF_VERSION, |
| 71 | 'basename' => ACF_BASENAME, |
| 72 | 'path' => ACF_PATH, |
| 73 | 'file' => __FILE__, |
| 74 | 'url' => plugin_dir_url( __FILE__ ), |
| 75 | 'show_admin' => true, |
| 76 | 'show_updates' => true, |
| 77 | 'stripslashes' => false, |
| 78 | 'local' => true, |
| 79 | 'json' => true, |
| 80 | 'save_json' => '', |
| 81 | 'load_json' => array(), |
| 82 | 'default_language' => '', |
| 83 | 'current_language' => '', |
| 84 | 'capability' => 'manage_options', |
| 85 | 'uploader' => 'wp', |
| 86 | 'autoload' => false, |
| 87 | 'l10n' => true, |
| 88 | 'l10n_textdomain' => '', |
| 89 | 'google_api_key' => '', |
| 90 | 'google_api_client' => '', |
| 91 | 'enqueue_google_maps' => true, |
| 92 | 'enqueue_select2' => true, |
| 93 | 'enqueue_datepicker' => true, |
| 94 | 'enqueue_datetimepicker' => true, |
| 95 | 'select2_version' => 4, |
| 96 | 'row_index_offset' => 1, |
| 97 | 'remove_wp_meta_box' => true |
| 98 | ); |
| 99 | |
| 100 | // Include utility functions. |
| 101 | include_once( ACF_PATH . 'includes/acf-utility-functions.php'); |
| 102 | |
| 103 | // Include previous API functions. |
| 104 | acf_include('includes/api/api-helpers.php'); |
| 105 | acf_include('includes/api/api-template.php'); |
| 106 | acf_include('includes/api/api-term.php'); |
| 107 | |
| 108 | // Include classes. |
| 109 | acf_include('includes/class-acf-data.php'); |
| 110 | acf_include('includes/fields/class-acf-field.php'); |
| 111 | acf_include('includes/locations/abstract-acf-legacy-location.php'); |
| 112 | acf_include('includes/locations/abstract-acf-location.php'); |
| 113 | |
| 114 | // Include functions. |
| 115 | acf_include('includes/acf-helper-functions.php'); |
| 116 | acf_include('includes/acf-hook-functions.php'); |
| 117 | acf_include('includes/acf-field-functions.php'); |
| 118 | acf_include('includes/acf-field-group-functions.php'); |
| 119 | acf_include('includes/acf-form-functions.php'); |
| 120 | acf_include('includes/acf-meta-functions.php'); |
| 121 | acf_include('includes/acf-post-functions.php'); |
| 122 | acf_include('includes/acf-user-functions.php'); |
| 123 | acf_include('includes/acf-value-functions.php'); |
| 124 | acf_include('includes/acf-input-functions.php'); |
| 125 | acf_include('includes/acf-wp-functions.php'); |
| 126 | |
| 127 | // Include core. |
| 128 | acf_include('includes/fields.php'); |
| 129 | acf_include('includes/locations.php'); |
| 130 | acf_include('includes/assets.php'); |
| 131 | acf_include('includes/compatibility.php'); |
| 132 | acf_include('includes/deprecated.php'); |
| 133 | acf_include('includes/l10n.php'); |
| 134 | acf_include('includes/local-fields.php'); |
| 135 | acf_include('includes/local-meta.php'); |
| 136 | acf_include('includes/local-json.php'); |
| 137 | acf_include('includes/loop.php'); |
| 138 | acf_include('includes/media.php'); |
| 139 | acf_include('includes/revisions.php'); |
| 140 | acf_include('includes/updates.php'); |
| 141 | acf_include('includes/upgrades.php'); |
| 142 | acf_include('includes/validation.php'); |
| 143 | |
| 144 | // Include ajax. |
| 145 | acf_include('includes/ajax/class-acf-ajax.php'); |
| 146 | acf_include('includes/ajax/class-acf-ajax-check-screen.php'); |
| 147 | acf_include('includes/ajax/class-acf-ajax-user-setting.php'); |
| 148 | acf_include('includes/ajax/class-acf-ajax-upgrade.php'); |
| 149 | acf_include('includes/ajax/class-acf-ajax-query.php'); |
| 150 | acf_include('includes/ajax/class-acf-ajax-query-users.php'); |
| 151 | acf_include('includes/ajax/class-acf-ajax-local-json-diff.php'); |
| 152 | |
| 153 | // Include forms. |
| 154 | acf_include('includes/forms/form-attachment.php'); |
| 155 | acf_include('includes/forms/form-comment.php'); |
| 156 | acf_include('includes/forms/form-customizer.php'); |
| 157 | acf_include('includes/forms/form-front.php'); |
| 158 | acf_include('includes/forms/form-nav-menu.php'); |
| 159 | acf_include('includes/forms/form-post.php'); |
| 160 | acf_include('includes/forms/form-gutenberg.php'); |
| 161 | acf_include('includes/forms/form-taxonomy.php'); |
| 162 | acf_include('includes/forms/form-user.php'); |
| 163 | acf_include('includes/forms/form-widget.php'); |
| 164 | |
| 165 | // Include admin. |
| 166 | if( is_admin() ) { |
| 167 | acf_include('includes/admin/admin.php'); |
| 168 | acf_include('includes/admin/admin-field-group.php'); |
| 169 | acf_include('includes/admin/admin-field-groups.php'); |
| 170 | acf_include('includes/admin/admin-notices.php'); |
| 171 | acf_include('includes/admin/admin-tools.php'); |
| 172 | acf_include('includes/admin/admin-upgrade.php'); |
| 173 | } |
| 174 | |
| 175 | // Include legacy. |
| 176 | acf_include('includes/legacy/legacy-locations.php'); |
| 177 | |
| 178 | // Include PRO. |
| 179 | acf_include('pro/acf-pro.php'); |
| 180 | |
| 181 | // Include tests. |
| 182 | if( defined('ACF_DEV') && ACF_DEV ) { |
| 183 | acf_include('tests/tests.php'); |
| 184 | } |
| 185 | |
| 186 | // Add actions. |
| 187 | add_action( 'init', array($this, 'init'), 5 ); |
| 188 | add_action( 'init', array($this, 'register_post_types'), 5 ); |
| 189 | add_action( 'init', array($this, 'register_post_status'), 5 ); |
| 190 | |
| 191 | // Add filters. |
| 192 | add_filter( 'posts_where', array($this, 'posts_where'), 10, 2 ); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * init |
| 197 | * |
| 198 | * Completes the setup process on "init" of earlier. |
| 199 | * |
| 200 | * @date 28/09/13 |
| 201 | * @since 5.0.0 |
| 202 | * |
| 203 | * @param void |
| 204 | * @return void |
| 205 | */ |
| 206 | function init() { |
| 207 | |
| 208 | // Bail early if called directly from functions.php or plugin file. |
| 209 | if( !did_action('plugins_loaded') ) { |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | // This function may be called directly from template functions. Bail early if already did this. |
| 214 | if( acf_did('init') ) { |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | // Update url setting. Allows other plugins to modify the URL (force SSL). |
| 219 | acf_update_setting( 'url', plugin_dir_url( __FILE__ ) ); |
| 220 | |
| 221 | // Load textdomain file. |
| 222 | acf_load_textdomain(); |
| 223 | |
| 224 | // Include 3rd party compatiblity. |
| 225 | acf_include('includes/third-party.php'); |
| 226 | |
| 227 | // Include wpml support. |
| 228 | if( defined('ICL_SITEPRESS_VERSION') ) { |
| 229 | acf_include('includes/wpml.php'); |
| 230 | } |
| 231 | |
| 232 | // Include fields. |
| 233 | acf_include('includes/fields/class-acf-field-text.php'); |
| 234 | acf_include('includes/fields/class-acf-field-textarea.php'); |
| 235 | acf_include('includes/fields/class-acf-field-number.php'); |
| 236 | acf_include('includes/fields/class-acf-field-range.php'); |
| 237 | acf_include('includes/fields/class-acf-field-email.php'); |
| 238 | acf_include('includes/fields/class-acf-field-url.php'); |
| 239 | acf_include('includes/fields/class-acf-field-password.php'); |
| 240 | acf_include('includes/fields/class-acf-field-image.php'); |
| 241 | acf_include('includes/fields/class-acf-field-file.php'); |
| 242 | acf_include('includes/fields/class-acf-field-wysiwyg.php'); |
| 243 | acf_include('includes/fields/class-acf-field-oembed.php'); |
| 244 | acf_include('includes/fields/class-acf-field-select.php'); |
| 245 | acf_include('includes/fields/class-acf-field-checkbox.php'); |
| 246 | acf_include('includes/fields/class-acf-field-radio.php'); |
| 247 | acf_include('includes/fields/class-acf-field-button-group.php'); |
| 248 | acf_include('includes/fields/class-acf-field-true_false.php'); |
| 249 | acf_include('includes/fields/class-acf-field-link.php'); |
| 250 | acf_include('includes/fields/class-acf-field-post_object.php'); |
| 251 | acf_include('includes/fields/class-acf-field-page_link.php'); |
| 252 | acf_include('includes/fields/class-acf-field-relationship.php'); |
| 253 | acf_include('includes/fields/class-acf-field-taxonomy.php'); |
| 254 | acf_include('includes/fields/class-acf-field-user.php'); |
| 255 | acf_include('includes/fields/class-acf-field-google-map.php'); |
| 256 | acf_include('includes/fields/class-acf-field-date_picker.php'); |
| 257 | acf_include('includes/fields/class-acf-field-date_time_picker.php'); |
| 258 | acf_include('includes/fields/class-acf-field-time_picker.php'); |
| 259 | acf_include('includes/fields/class-acf-field-color_picker.php'); |
| 260 | acf_include('includes/fields/class-acf-field-message.php'); |
| 261 | acf_include('includes/fields/class-acf-field-accordion.php'); |
| 262 | acf_include('includes/fields/class-acf-field-tab.php'); |
| 263 | acf_include('includes/fields/class-acf-field-group.php'); |
| 264 | |
| 265 | /** |
| 266 | * Fires after field types have been included. |
| 267 | * |
| 268 | * @date 28/09/13 |
| 269 | * @since 5.0.0 |
| 270 | * |
| 271 | * @param int $major_version The major version of ACF. |
| 272 | */ |
| 273 | do_action( 'acf/include_field_types', ACF_MAJOR_VERSION ); |
| 274 | |
| 275 | // Include locations. |
| 276 | acf_include('includes/locations/class-acf-location-post-type.php'); |
| 277 | acf_include('includes/locations/class-acf-location-post-template.php'); |
| 278 | acf_include('includes/locations/class-acf-location-post-status.php'); |
| 279 | acf_include('includes/locations/class-acf-location-post-format.php'); |
| 280 | acf_include('includes/locations/class-acf-location-post-category.php'); |
| 281 | acf_include('includes/locations/class-acf-location-post-taxonomy.php'); |
| 282 | acf_include('includes/locations/class-acf-location-post.php'); |
| 283 | acf_include('includes/locations/class-acf-location-page-template.php'); |
| 284 | acf_include('includes/locations/class-acf-location-page-type.php'); |
| 285 | acf_include('includes/locations/class-acf-location-page-parent.php'); |
| 286 | acf_include('includes/locations/class-acf-location-page.php'); |
| 287 | acf_include('includes/locations/class-acf-location-current-user.php'); |
| 288 | acf_include('includes/locations/class-acf-location-current-user-role.php'); |
| 289 | acf_include('includes/locations/class-acf-location-user-form.php'); |
| 290 | acf_include('includes/locations/class-acf-location-user-role.php'); |
| 291 | acf_include('includes/locations/class-acf-location-taxonomy.php'); |
| 292 | acf_include('includes/locations/class-acf-location-attachment.php'); |
| 293 | acf_include('includes/locations/class-acf-location-comment.php'); |
| 294 | acf_include('includes/locations/class-acf-location-widget.php'); |
| 295 | acf_include('includes/locations/class-acf-location-nav-menu.php'); |
| 296 | acf_include('includes/locations/class-acf-location-nav-menu-item.php'); |
| 297 | |
| 298 | /** |
| 299 | * Fires after location types have been included. |
| 300 | * |
| 301 | * @date 28/09/13 |
| 302 | * @since 5.0.0 |
| 303 | * |
| 304 | * @param int $major_version The major version of ACF. |
| 305 | */ |
| 306 | do_action( 'acf/include_location_rules', ACF_MAJOR_VERSION ); |
| 307 | |
| 308 | /** |
| 309 | * Fires during initialization. Used to add local fields. |
| 310 | * |
| 311 | * @date 28/09/13 |
| 312 | * @since 5.0.0 |
| 313 | * |
| 314 | * @param int $major_version The major version of ACF. |
| 315 | */ |
| 316 | do_action( 'acf/include_fields', ACF_MAJOR_VERSION ); |
| 317 | |
| 318 | /** |
| 319 | * Fires after ACF is completely "initialized". |
| 320 | * |
| 321 | * @date 28/09/13 |
| 322 | * @since 5.0.0 |
| 323 | * |
| 324 | * @param int $major_version The major version of ACF. |
| 325 | */ |
| 326 | do_action( 'acf/init', ACF_MAJOR_VERSION ); |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * register_post_types |
| 331 | * |
| 332 | * Registers the ACF post types. |
| 333 | * |
| 334 | * @date 22/10/2015 |
| 335 | * @since 5.3.2 |
| 336 | * |
| 337 | * @param void |
| 338 | * @return void |
| 339 | */ |
| 340 | function register_post_types() { |
| 341 | |
| 342 | // Vars. |
| 343 | $cap = acf_get_setting('capability'); |
| 344 | |
| 345 | // Register the Field Group post type. |
| 346 | register_post_type('acf-field-group', array( |
| 347 | 'labels' => array( |
| 348 | 'name' => __( 'Field Groups', 'acf' ), |
| 349 | 'singular_name' => __( 'Field Group', 'acf' ), |
| 350 | 'add_new' => __( 'Add New' , 'acf' ), |
| 351 | 'add_new_item' => __( 'Add New Field Group' , 'acf' ), |
| 352 | 'edit_item' => __( 'Edit Field Group' , 'acf' ), |
| 353 | 'new_item' => __( 'New Field Group' , 'acf' ), |
| 354 | 'view_item' => __( 'View Field Group', 'acf' ), |
| 355 | 'search_items' => __( 'Search Field Groups', 'acf' ), |
| 356 | 'not_found' => __( 'No Field Groups found', 'acf' ), |
| 357 | 'not_found_in_trash' => __( 'No Field Groups found in Trash', 'acf' ), |
| 358 | ), |
| 359 | 'public' => false, |
| 360 | 'hierarchical' => true, |
| 361 | 'show_ui' => true, |
| 362 | 'show_in_menu' => false, |
| 363 | '_builtin' => false, |
| 364 | 'capability_type' => 'post', |
| 365 | 'capabilities' => array( |
| 366 | 'edit_post' => $cap, |
| 367 | 'delete_post' => $cap, |
| 368 | 'edit_posts' => $cap, |
| 369 | 'delete_posts' => $cap, |
| 370 | ), |
| 371 | 'supports' => array('title'), |
| 372 | 'rewrite' => false, |
| 373 | 'query_var' => false, |
| 374 | )); |
| 375 | |
| 376 | |
| 377 | // Register the Field post type. |
| 378 | register_post_type('acf-field', array( |
| 379 | 'labels' => array( |
| 380 | 'name' => __( 'Fields', 'acf' ), |
| 381 | 'singular_name' => __( 'Field', 'acf' ), |
| 382 | 'add_new' => __( 'Add New' , 'acf' ), |
| 383 | 'add_new_item' => __( 'Add New Field' , 'acf' ), |
| 384 | 'edit_item' => __( 'Edit Field' , 'acf' ), |
| 385 | 'new_item' => __( 'New Field' , 'acf' ), |
| 386 | 'view_item' => __( 'View Field', 'acf' ), |
| 387 | 'search_items' => __( 'Search Fields', 'acf' ), |
| 388 | 'not_found' => __( 'No Fields found', 'acf' ), |
| 389 | 'not_found_in_trash' => __( 'No Fields found in Trash', 'acf' ), |
| 390 | ), |
| 391 | 'public' => false, |
| 392 | 'hierarchical' => true, |
| 393 | 'show_ui' => false, |
| 394 | 'show_in_menu' => false, |
| 395 | '_builtin' => false, |
| 396 | 'capability_type' => 'post', |
| 397 | 'capabilities' => array( |
| 398 | 'edit_post' => $cap, |
| 399 | 'delete_post' => $cap, |
| 400 | 'edit_posts' => $cap, |
| 401 | 'delete_posts' => $cap, |
| 402 | ), |
| 403 | 'supports' => array('title'), |
| 404 | 'rewrite' => false, |
| 405 | 'query_var' => false, |
| 406 | )); |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * register_post_status |
| 411 | * |
| 412 | * Registers the ACF post statuses. |
| 413 | * |
| 414 | * @date 22/10/2015 |
| 415 | * @since 5.3.2 |
| 416 | * |
| 417 | * @param void |
| 418 | * @return void |
| 419 | */ |
| 420 | function register_post_status() { |
| 421 | |
| 422 | // Register the Disabled post status. |
| 423 | register_post_status('acf-disabled', array( |
| 424 | 'label' => _x( 'Disabled', 'post status', 'acf' ), |
| 425 | 'public' => true, |
| 426 | 'exclude_from_search' => false, |
| 427 | 'show_in_admin_all_list' => true, |
| 428 | 'show_in_admin_status_list' => true, |
| 429 | 'label_count' => _n_noop( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', 'acf' ), |
| 430 | )); |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * posts_where |
| 435 | * |
| 436 | * Filters the $where clause allowing for custom WP_Query args. |
| 437 | * |
| 438 | * @date 31/8/19 |
| 439 | * @since 5.8.1 |
| 440 | * |
| 441 | * @param string $where The WHERE clause. |
| 442 | * @return WP_Query $wp_query The query object. |
| 443 | */ |
| 444 | function posts_where( $where, $wp_query ) { |
| 445 | global $wpdb; |
| 446 | |
| 447 | // Add custom "acf_field_key" arg. |
| 448 | if( $field_key = $wp_query->get('acf_field_key') ) { |
| 449 | $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_name = %s", $field_key ); |
| 450 | } |
| 451 | |
| 452 | // Add custom "acf_field_name" arg. |
| 453 | if( $field_name = $wp_query->get('acf_field_name') ) { |
| 454 | $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_excerpt = %s", $field_name ); |
| 455 | } |
| 456 | |
| 457 | // Add custom "acf_group_key" arg. |
| 458 | if( $group_key = $wp_query->get('acf_group_key') ) { |
| 459 | $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_name = %s", $group_key ); |
| 460 | } |
| 461 | |
| 462 | // Return. |
| 463 | return $where; |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * define |
| 468 | * |
| 469 | * Defines a constant if doesnt already exist. |
| 470 | * |
| 471 | * @date 3/5/17 |
| 472 | * @since 5.5.13 |
| 473 | * |
| 474 | * @param string $name The constant name. |
| 475 | * @param mixed $value The constant value. |
| 476 | * @return void |
| 477 | */ |
| 478 | function define( $name, $value = true ) { |
| 479 | if( !defined($name) ) { |
| 480 | define( $name, $value ); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * has_setting |
| 486 | * |
| 487 | * Returns true if a setting exists for this name. |
| 488 | * |
| 489 | * @date 2/2/18 |
| 490 | * @since 5.6.5 |
| 491 | * |
| 492 | * @param string $name The setting name. |
| 493 | * @return boolean |
| 494 | */ |
| 495 | function has_setting( $name ) { |
| 496 | return isset($this->settings[ $name ]); |
| 497 | } |
| 498 | |
| 499 | /** |
| 500 | * get_setting |
| 501 | * |
| 502 | * Returns a setting or null if doesn't exist. |
| 503 | * |
| 504 | * @date 28/09/13 |
| 505 | * @since 5.0.0 |
| 506 | * |
| 507 | * @param string $name The setting name. |
| 508 | * @return mixed |
| 509 | */ |
| 510 | function get_setting( $name ) { |
| 511 | return isset($this->settings[ $name ]) ? $this->settings[ $name ] : null; |
| 512 | } |
| 513 | |
| 514 | /** |
| 515 | * update_setting |
| 516 | * |
| 517 | * Updates a setting for the given name and value. |
| 518 | * |
| 519 | * @date 28/09/13 |
| 520 | * @since 5.0.0 |
| 521 | * |
| 522 | * @param string $name The setting name. |
| 523 | * @param mixed $value The setting value. |
| 524 | * @return true |
| 525 | */ |
| 526 | function update_setting( $name, $value ) { |
| 527 | $this->settings[ $name ] = $value; |
| 528 | return true; |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * get_data |
| 533 | * |
| 534 | * Returns data or null if doesn't exist. |
| 535 | * |
| 536 | * @date 28/09/13 |
| 537 | * @since 5.0.0 |
| 538 | * |
| 539 | * @param string $name The data name. |
| 540 | * @return mixed |
| 541 | */ |
| 542 | function get_data( $name ) { |
| 543 | return isset($this->data[ $name ]) ? $this->data[ $name ] : null; |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * set_data |
| 548 | * |
| 549 | * Sets data for the given name and value. |
| 550 | * |
| 551 | * @date 28/09/13 |
| 552 | * @since 5.0.0 |
| 553 | * |
| 554 | * @param string $name The data name. |
| 555 | * @param mixed $value The data value. |
| 556 | * @return void |
| 557 | */ |
| 558 | function set_data( $name, $value ) { |
| 559 | $this->data[ $name ] = $value; |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * get_instance |
| 564 | * |
| 565 | * Returns an instance or null if doesn't exist. |
| 566 | * |
| 567 | * @date 13/2/18 |
| 568 | * @since 5.6.9 |
| 569 | * |
| 570 | * @param string $class The instance class name. |
| 571 | * @return object |
| 572 | */ |
| 573 | function get_instance( $class ) { |
| 574 | $name = strtolower($class); |
| 575 | return isset($this->instances[ $name ]) ? $this->instances[ $name ] : null; |
| 576 | } |
| 577 | |
| 578 | /** |
| 579 | * new_instance |
| 580 | * |
| 581 | * Creates and stores an instance of the given class. |
| 582 | * |
| 583 | * @date 13/2/18 |
| 584 | * @since 5.6.9 |
| 585 | * |
| 586 | * @param string $class The instance class name. |
| 587 | * @return object |
| 588 | */ |
| 589 | function new_instance( $class ) { |
| 590 | $instance = new $class(); |
| 591 | $name = strtolower($class); |
| 592 | $this->instances[ $name ] = $instance; |
| 593 | return $instance; |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * Magic __isset method for backwards compatibility. |
| 598 | * |
| 599 | * @date 24/4/20 |
| 600 | * @since 5.9.0 |
| 601 | * |
| 602 | * @param string $key Key name. |
| 603 | * @return bool |
| 604 | */ |
| 605 | public function __isset( $key ) { |
| 606 | return in_array( $key, array( 'locations', 'json' ) ); |
| 607 | } |
| 608 | |
| 609 | /** |
| 610 | * Magic __get method for backwards compatibility. |
| 611 | * |
| 612 | * @date 24/4/20 |
| 613 | * @since 5.9.0 |
| 614 | * |
| 615 | * @param string $key Key name. |
| 616 | * @return mixed |
| 617 | */ |
| 618 | public function __get( $key ) { |
| 619 | switch ( $key ) { |
| 620 | case 'locations': |
| 621 | return acf_get_instance( 'ACF_Legacy_Locations' ); |
| 622 | case 'json': |
| 623 | return acf_get_instance( 'ACF_Local_JSON' ); |
| 624 | } |
| 625 | return null; |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | /* |
| 630 | * acf |
| 631 | * |
| 632 | * The main function responsible for returning the one true acf Instance to functions everywhere. |
| 633 | * Use this function like you would a global variable, except without needing to declare the global. |
| 634 | * |
| 635 | * Example: <?php $acf = acf(); ?> |
| 636 | * |
| 637 | * @date 4/09/13 |
| 638 | * @since 4.3.0 |
| 639 | * |
| 640 | * @param void |
| 641 | * @return ACF |
| 642 | */ |
| 643 | function acf() { |
| 644 | global $acf; |
| 645 | |
| 646 | // Instantiate only once. |
| 647 | if( !isset($acf) ) { |
| 648 | $acf = new ACF(); |
| 649 | $acf->initialize(); |
| 650 | } |
| 651 | return $acf; |
| 652 | } |
| 653 | |
| 654 | // Instantiate. |
| 655 | acf(); |
| 656 | |
| 657 | endif; // class_exists check |
| 658 |