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