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