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