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