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