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

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