PluginProbe
Advanced Custom Fields (ACF®) / 6.1.6
Advanced Custom Fields (ACF®) v6.1.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 in Advanced Custom Fields (ACF®) 6.1.6, at acf.php

775 lines 24.3 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.6
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.6';
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 field group class.
180 acf_include( 'includes/post-types/class-acf-field-group.php' );
181
182 // Include ajax.
183 acf_include( 'includes/ajax/class-acf-ajax.php' );
184 acf_include( 'includes/ajax/class-acf-ajax-check-screen.php' );
185 acf_include( 'includes/ajax/class-acf-ajax-user-setting.php' );
186 acf_include( 'includes/ajax/class-acf-ajax-upgrade.php' );
187 acf_include( 'includes/ajax/class-acf-ajax-query.php' );
188 acf_include( 'includes/ajax/class-acf-ajax-query-users.php' );
189 acf_include( 'includes/ajax/class-acf-ajax-local-json-diff.php' );
190
191 // Include forms.
192 acf_include( 'includes/forms/form-attachment.php' );
193 acf_include( 'includes/forms/form-comment.php' );
194 acf_include( 'includes/forms/form-customizer.php' );
195 acf_include( 'includes/forms/form-front.php' );
196 acf_include( 'includes/forms/form-nav-menu.php' );
197 acf_include( 'includes/forms/form-post.php' );
198 acf_include( 'includes/forms/form-gutenberg.php' );
199 acf_include( 'includes/forms/form-taxonomy.php' );
200 acf_include( 'includes/forms/form-user.php' );
201 acf_include( 'includes/forms/form-widget.php' );
202
203 // Include admin.
204 if ( is_admin() ) {
205 acf_include( 'includes/admin/admin.php' );
206 acf_include( 'includes/admin/admin-internal-post-type-list.php' );
207 acf_include( 'includes/admin/admin-internal-post-type.php' );
208 acf_include( 'includes/admin/admin-notices.php' );
209 acf_include( 'includes/admin/admin-tools.php' );
210 acf_include( 'includes/admin/admin-upgrade.php' );
211 }
212
213 // Include polyfill for < PHP7 unserialize.
214 if ( PHP_VERSION_ID < 70000 ) {
215 acf_include( 'vendor/polyfill-unserialize/src/Unserialize.php' );
216 acf_include( 'vendor/polyfill-unserialize/src/DisallowedClassesSubstitutor.php' );
217 }
218
219 // Include legacy.
220 acf_include( 'includes/legacy/legacy-locations.php' );
221
222 // Include PRO.
223 acf_include( 'pro/acf-pro.php' );
224
225 // Add actions.
226 add_action( 'init', array( $this, 'register_post_status' ), 4 );
227 add_action( 'init', array( $this, 'init' ), 5 );
228 add_action( 'init', array( $this, 'register_post_types' ), 5 );
229 add_action( 'activated_plugin', array( $this, 'deactivate_other_instances' ) );
230 add_action( 'pre_current_active_plugins', array( $this, 'plugin_deactivated_notice' ) );
231
232 // Add filters.
233 add_filter( 'posts_where', array( $this, 'posts_where' ), 10, 2 );
234 }
235
236 /**
237 * Completes the setup process on "init" of earlier.
238 *
239 * @date 28/09/13
240 * @since 5.0.0
241 *
242 * @return void
243 */
244 public function init() {
245
246 // Bail early if called directly from functions.php or plugin file.
247 if ( ! did_action( 'plugins_loaded' ) ) {
248 return;
249 }
250
251 // This function may be called directly from template functions. Bail early if already did this.
252 if ( acf_did( 'init' ) ) {
253 return;
254 }
255
256 // Update url setting. Allows other plugins to modify the URL (force SSL).
257 acf_update_setting( 'url', plugin_dir_url( __FILE__ ) );
258
259 // Load textdomain file.
260 acf_load_textdomain();
261
262 // Include 3rd party compatiblity.
263 acf_include( 'includes/third-party.php' );
264
265 // Include wpml support.
266 if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
267 acf_include( 'includes/wpml.php' );
268 }
269
270 // Add post types and taxonomies.
271 if ( acf_get_setting( 'enable_post_types' ) ) {
272 acf_include( 'includes/post-types/class-acf-post-type.php' );
273 acf_include( 'includes/post-types/class-acf-taxonomy.php' );
274 }
275
276 // Include fields.
277 acf_include( 'includes/fields/class-acf-field-text.php' );
278 acf_include( 'includes/fields/class-acf-field-textarea.php' );
279 acf_include( 'includes/fields/class-acf-field-number.php' );
280 acf_include( 'includes/fields/class-acf-field-range.php' );
281 acf_include( 'includes/fields/class-acf-field-email.php' );
282 acf_include( 'includes/fields/class-acf-field-url.php' );
283 acf_include( 'includes/fields/class-acf-field-password.php' );
284 acf_include( 'includes/fields/class-acf-field-image.php' );
285 acf_include( 'includes/fields/class-acf-field-file.php' );
286 acf_include( 'includes/fields/class-acf-field-wysiwyg.php' );
287 acf_include( 'includes/fields/class-acf-field-oembed.php' );
288 acf_include( 'includes/fields/class-acf-field-select.php' );
289 acf_include( 'includes/fields/class-acf-field-checkbox.php' );
290 acf_include( 'includes/fields/class-acf-field-radio.php' );
291 acf_include( 'includes/fields/class-acf-field-button-group.php' );
292 acf_include( 'includes/fields/class-acf-field-true_false.php' );
293 acf_include( 'includes/fields/class-acf-field-link.php' );
294 acf_include( 'includes/fields/class-acf-field-post_object.php' );
295 acf_include( 'includes/fields/class-acf-field-page_link.php' );
296 acf_include( 'includes/fields/class-acf-field-relationship.php' );
297 acf_include( 'includes/fields/class-acf-field-taxonomy.php' );
298 acf_include( 'includes/fields/class-acf-field-user.php' );
299 acf_include( 'includes/fields/class-acf-field-google-map.php' );
300 acf_include( 'includes/fields/class-acf-field-date_picker.php' );
301 acf_include( 'includes/fields/class-acf-field-date_time_picker.php' );
302 acf_include( 'includes/fields/class-acf-field-time_picker.php' );
303 acf_include( 'includes/fields/class-acf-field-color_picker.php' );
304 acf_include( 'includes/fields/class-acf-field-message.php' );
305 acf_include( 'includes/fields/class-acf-field-accordion.php' );
306 acf_include( 'includes/fields/class-acf-field-tab.php' );
307 acf_include( 'includes/fields/class-acf-field-group.php' );
308
309 /**
310 * Fires after field types have been included.
311 *
312 * @date 28/09/13
313 * @since 5.0.0
314 *
315 * @param int ACF_FIELD_API_VERSION The field API version.
316 */
317 do_action( 'acf/include_field_types', ACF_FIELD_API_VERSION );
318
319 // Include locations.
320 acf_include( 'includes/locations/class-acf-location-post-type.php' );
321 acf_include( 'includes/locations/class-acf-location-post-template.php' );
322 acf_include( 'includes/locations/class-acf-location-post-status.php' );
323 acf_include( 'includes/locations/class-acf-location-post-format.php' );
324 acf_include( 'includes/locations/class-acf-location-post-category.php' );
325 acf_include( 'includes/locations/class-acf-location-post-taxonomy.php' );
326 acf_include( 'includes/locations/class-acf-location-post.php' );
327 acf_include( 'includes/locations/class-acf-location-page-template.php' );
328 acf_include( 'includes/locations/class-acf-location-page-type.php' );
329 acf_include( 'includes/locations/class-acf-location-page-parent.php' );
330 acf_include( 'includes/locations/class-acf-location-page.php' );
331 acf_include( 'includes/locations/class-acf-location-current-user.php' );
332 acf_include( 'includes/locations/class-acf-location-current-user-role.php' );
333 acf_include( 'includes/locations/class-acf-location-user-form.php' );
334 acf_include( 'includes/locations/class-acf-location-user-role.php' );
335 acf_include( 'includes/locations/class-acf-location-taxonomy.php' );
336 acf_include( 'includes/locations/class-acf-location-attachment.php' );
337 acf_include( 'includes/locations/class-acf-location-comment.php' );
338 acf_include( 'includes/locations/class-acf-location-widget.php' );
339 acf_include( 'includes/locations/class-acf-location-nav-menu.php' );
340 acf_include( 'includes/locations/class-acf-location-nav-menu-item.php' );
341
342 /**
343 * Fires after location types have been included.
344 *
345 * @date 28/09/13
346 * @since 5.0.0
347 *
348 * @param int ACF_FIELD_API_VERSION The field API version.
349 */
350 do_action( 'acf/include_location_rules', ACF_FIELD_API_VERSION );
351
352 /**
353 * Fires during initialization. Used to add local fields.
354 *
355 * @date 28/09/13
356 * @since 5.0.0
357 *
358 * @param int ACF_FIELD_API_VERSION The field API version.
359 */
360 do_action( 'acf/include_fields', ACF_FIELD_API_VERSION );
361
362 /**
363 * Fires during initialization. Used to add local post types.
364 *
365 * @since 6.1
366 *
367 * @param int ACF_MAJOR_VERSION The major version of ACF.
368 */
369 do_action( 'acf/include_post_types', ACF_MAJOR_VERSION );
370
371 /**
372 * Fires during initialization. Used to add local taxonomies.
373 *
374 * @since 6.1
375 *
376 * @param int ACF_MAJOR_VERSION The major version of ACF.
377 */
378 do_action( 'acf/include_taxonomies', ACF_MAJOR_VERSION );
379
380 /**
381 * Fires after ACF is completely "initialized".
382 *
383 * @date 28/09/13
384 * @since 5.0.0
385 *
386 * @param int ACF_MAJOR_VERSION The major version of ACF.
387 */
388 do_action( 'acf/init', ACF_MAJOR_VERSION );
389 }
390
391 /**
392 * Registers the ACF post types.
393 *
394 * @date 22/10/2015
395 * @since 5.3.2
396 *
397 * @return void
398 */
399 public function register_post_types() {
400 $cap = acf_get_setting( 'capability' );
401
402 // Register the Field Group post type.
403 register_post_type(
404 'acf-field-group',
405 array(
406 'labels' => array(
407 'name' => __( 'Field Groups', 'acf' ),
408 'singular_name' => __( 'Field Group', 'acf' ),
409 'add_new' => __( 'Add New', 'acf' ),
410 'add_new_item' => __( 'Add New Field Group', 'acf' ),
411 'edit_item' => __( 'Edit Field Group', 'acf' ),
412 'new_item' => __( 'New Field Group', 'acf' ),
413 'view_item' => __( 'View Field Group', 'acf' ),
414 'search_items' => __( 'Search Field Groups', 'acf' ),
415 'not_found' => __( 'No Field Groups found', 'acf' ),
416 'not_found_in_trash' => __( 'No Field Groups found in Trash', 'acf' ),
417 ),
418 'public' => false,
419 'hierarchical' => true,
420 'show_ui' => true,
421 'show_in_menu' => false,
422 '_builtin' => false,
423 'capability_type' => 'post',
424 'capabilities' => array(
425 'edit_post' => $cap,
426 'delete_post' => $cap,
427 'edit_posts' => $cap,
428 'delete_posts' => $cap,
429 ),
430 'supports' => false,
431 'rewrite' => false,
432 'query_var' => false,
433 )
434 );
435
436 // Register the Field post type.
437 register_post_type(
438 'acf-field',
439 array(
440 'labels' => array(
441 'name' => __( 'Fields', 'acf' ),
442 'singular_name' => __( 'Field', 'acf' ),
443 'add_new' => __( 'Add New', 'acf' ),
444 'add_new_item' => __( 'Add New Field', 'acf' ),
445 'edit_item' => __( 'Edit Field', 'acf' ),
446 'new_item' => __( 'New Field', 'acf' ),
447 'view_item' => __( 'View Field', 'acf' ),
448 'search_items' => __( 'Search Fields', 'acf' ),
449 'not_found' => __( 'No Fields found', 'acf' ),
450 'not_found_in_trash' => __( 'No Fields found in Trash', 'acf' ),
451 ),
452 'public' => false,
453 'hierarchical' => true,
454 'show_ui' => false,
455 'show_in_menu' => false,
456 '_builtin' => false,
457 'capability_type' => 'post',
458 'capabilities' => array(
459 'edit_post' => $cap,
460 'delete_post' => $cap,
461 'edit_posts' => $cap,
462 'delete_posts' => $cap,
463 ),
464 'supports' => array( 'title' ),
465 'rewrite' => false,
466 'query_var' => false,
467 )
468 );
469 }
470
471 /**
472 * Registers the ACF post statuses.
473 *
474 * @date 22/10/2015
475 * @since 5.3.2
476 *
477 * @return void
478 */
479 public function register_post_status() {
480
481 // Register the Inactive post status.
482 register_post_status(
483 'acf-disabled',
484 array(
485 'label' => _x( 'Inactive', 'post status', 'acf' ),
486 'public' => true,
487 'exclude_from_search' => false,
488 'show_in_admin_all_list' => true,
489 'show_in_admin_status_list' => true,
490 /* translators: counts for inactive field groups */
491 'label_count' => _n_noop( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', 'acf' ),
492 )
493 );
494 }
495
496 /**
497 * Checks if another version of ACF/ACF PRO is active and deactivates it.
498 * Hooked on `activated_plugin` so other plugin is deactivated when current plugin is activated.
499 *
500 * @param string $plugin The plugin being activated.
501 */
502 public function deactivate_other_instances( $plugin ) {
503 if ( ! in_array( $plugin, array( 'advanced-custom-fields/acf.php', 'advanced-custom-fields-pro/acf.php' ), true ) ) {
504 return;
505 }
506
507 $plugin_to_deactivate = 'advanced-custom-fields/acf.php';
508 $deactivated_notice_id = '1';
509
510 // If we just activated the free version, deactivate the pro version.
511 if ( $plugin === $plugin_to_deactivate ) {
512 $plugin_to_deactivate = 'advanced-custom-fields-pro/acf.php';
513 $deactivated_notice_id = '2';
514 }
515
516 if ( is_multisite() && is_network_admin() ) {
517 $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
518 $active_plugins = array_keys( $active_plugins );
519 } else {
520 $active_plugins = (array) get_option( 'active_plugins', array() );
521 }
522
523 foreach ( $active_plugins as $plugin_basename ) {
524 if ( $plugin_to_deactivate === $plugin_basename ) {
525 set_transient( 'acf_deactivated_notice_id', $deactivated_notice_id, 1 * HOUR_IN_SECONDS );
526 deactivate_plugins( $plugin_basename );
527 return;
528 }
529 }
530 }
531
532 /**
533 * Displays a notice when either ACF or ACF PRO is automatically deactivated.
534 */
535 public function plugin_deactivated_notice() {
536 $deactivated_notice_id = (int) get_transient( 'acf_deactivated_notice_id' );
537 if ( ! in_array( $deactivated_notice_id, array( 1, 2 ), true ) ) {
538 return;
539 }
540
541 $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' );
542 if ( 2 === $deactivated_notice_id ) {
543 $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' );
544 }
545
546 ?>
547 <div class="updated" style="border-left: 4px solid #ffba00;">
548 <p><?php echo esc_html( $message ); ?></p>
549 </div>
550 <?php
551
552 delete_transient( 'acf_deactivated_notice_id' );
553 }
554
555 /**
556 * Filters the $where clause allowing for custom WP_Query args.
557 *
558 * @date 31/8/19
559 * @since 5.8.1
560 *
561 * @param string $where The WHERE clause.
562 * @param WP_Query $wp_query The query object.
563 * @return string
564 */
565 public function posts_where( $where, $wp_query ) {
566 global $wpdb;
567
568 $field_key = $wp_query->get( 'acf_field_key' );
569 $field_name = $wp_query->get( 'acf_field_name' );
570 $group_key = $wp_query->get( 'acf_group_key' );
571 $post_type_key = $wp_query->get( 'acf_post_type_key' );
572 $taxonomy_key = $wp_query->get( 'acf_taxonomy_key' );
573
574 // Add custom "acf_field_key" arg.
575 if ( $field_key ) {
576 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $field_key );
577 }
578
579 // Add custom "acf_field_name" arg.
580 if ( $field_name ) {
581 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_excerpt = %s", $field_name );
582 }
583
584 // Add custom "acf_group_key" arg.
585 if ( $group_key ) {
586 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $group_key );
587 }
588
589 // Add custom "acf_post_type_key" arg.
590 if ( $post_type_key ) {
591 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $post_type_key );
592 }
593
594 // Add custom "acf_taxonomy_key" arg.
595 if ( $taxonomy_key ) {
596 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $taxonomy_key );
597 }
598
599 return $where;
600 }
601
602 /**
603 * Defines a constant if doesnt already exist.
604 *
605 * @date 3/5/17
606 * @since 5.5.13
607 *
608 * @param string $name The constant name.
609 * @param mixed $value The constant value.
610 * @return void
611 */
612 public function define( $name, $value = true ) {
613 if ( ! defined( $name ) ) {
614 define( $name, $value );
615 }
616 }
617
618 /**
619 * Returns true if a setting exists for this name.
620 *
621 * @date 2/2/18
622 * @since 5.6.5
623 *
624 * @param string $name The setting name.
625 * @return boolean
626 */
627 public function has_setting( $name ) {
628 return isset( $this->settings[ $name ] );
629 }
630
631 /**
632 * Returns a setting or null if doesn't exist.
633 *
634 * @date 28/09/13
635 * @since 5.0.0
636 *
637 * @param string $name The setting name.
638 * @return mixed
639 */
640 public function get_setting( $name ) {
641 return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : null;
642 }
643
644 /**
645 * Updates a setting for the given name and value.
646 *
647 * @date 28/09/13
648 * @since 5.0.0
649 *
650 * @param string $name The setting name.
651 * @param mixed $value The setting value.
652 * @return true
653 */
654 public function update_setting( $name, $value ) {
655 $this->settings[ $name ] = $value;
656 return true;
657 }
658
659 /**
660 * Returns data or null if doesn't exist.
661 *
662 * @date 28/09/13
663 * @since 5.0.0
664 *
665 * @param string $name The data name.
666 * @return mixed
667 */
668 public function get_data( $name ) {
669 return isset( $this->data[ $name ] ) ? $this->data[ $name ] : null;
670 }
671
672 /**
673 * Sets data for the given name and value.
674 *
675 * @date 28/09/13
676 * @since 5.0.0
677 *
678 * @param string $name The data name.
679 * @param mixed $value The data value.
680 * @return void
681 */
682 public function set_data( $name, $value ) {
683 $this->data[ $name ] = $value;
684 }
685
686 /**
687 * Returns an instance or null if doesn't exist.
688 *
689 * @date 13/2/18
690 * @since 5.6.9
691 *
692 * @param string $class The instance class name.
693 * @return object
694 */
695 public function get_instance( $class ) {
696 $name = strtolower( $class );
697 return isset( $this->instances[ $name ] ) ? $this->instances[ $name ] : null;
698 }
699
700 /**
701 * Creates and stores an instance of the given class.
702 *
703 * @date 13/2/18
704 * @since 5.6.9
705 *
706 * @param string $class The instance class name.
707 * @return object
708 */
709 public function new_instance( $class ) {
710 $instance = new $class();
711 $name = strtolower( $class );
712 $this->instances[ $name ] = $instance;
713 return $instance;
714 }
715
716 /**
717 * Magic __isset method for backwards compatibility.
718 *
719 * @date 24/4/20
720 * @since 5.9.0
721 *
722 * @param string $key Key name.
723 * @return bool
724 */
725 public function __isset( $key ) {
726 return in_array( $key, array( 'locations', 'json' ), true );
727 }
728
729 /**
730 * Magic __get method for backwards compatibility.
731 *
732 * @date 24/4/20
733 * @since 5.9.0
734 *
735 * @param string $key Key name.
736 * @return mixed
737 */
738 public function __get( $key ) {
739 switch ( $key ) {
740 case 'locations':
741 return acf_get_instance( 'ACF_Legacy_Locations' );
742 case 'json':
743 return acf_get_instance( 'ACF_Local_JSON' );
744 }
745 return null;
746 }
747 }
748
749 /**
750 * The main function responsible for returning the one true acf Instance to functions everywhere.
751 * Use this function like you would a global variable, except without needing to declare the global.
752 *
753 * Example: <?php $acf = acf(); ?>
754 *
755 * @date 4/09/13
756 * @since 4.3.0
757 *
758 * @return ACF
759 */
760 function acf() {
761 global $acf;
762
763 // Instantiate only once.
764 if ( ! isset( $acf ) ) {
765 $acf = new ACF();
766 $acf->initialize();
767 }
768 return $acf;
769 }
770
771 // Instantiate.
772 acf();
773
774 } // class_exists check
775