PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields (ACF®) / 6.2.7
Advanced Custom Fields (ACF®) v6.2.7
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 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 6.1.0 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.1.6 6.1.7 6.1.8 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.6.1 6.2.7 6.2.8 6.2.9 6.3.0 6.3.1 6.3.10.2 6.3.11 6.3.12 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.6.1 6.4.0 6.4.0.1 6.4.1 6.4.2 6.4.3 6.5.0 6.5.1 6.6.0 6.6.1 6.6.2 6.7.0 6.7.1 6.7.2 6.8.0 trunk 1.0.0 1.0.2 1.0.3 1.0.5 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.1 2.1.3 2.1.4 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.6 3.0.7 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.8 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.4.10 4.4.11 4.4.12 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 5.10 5.10.1 5.10.2 5.11 5.11.1 5.11.2 5.11.3 5.11.4 5.12 5.12.1 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.6.10 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 5.6.8 5.6.9 5.7.0 5.7.1 5.7.10 5.7.12 5.7.13 5.7.2 5.7.3 5.7.4 5.7.5 5.7.6 5.7.7 5.7.8 5.7.9 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.2 5.8.3 5.8.4
advanced-custom-fields / acf.php
advanced-custom-fields Last commit date
assets 2 years ago includes 2 years ago lang 2 years ago README.md 2 years ago acf.php 2 years ago readme.txt 2 years ago
acf.php
787 lines
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.7
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.7';
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 );
132
133 // Include utility functions.
134 include_once ACF_PATH . 'includes/acf-utility-functions.php';
135
136 // Include previous API functions.
137 acf_include( 'includes/api/api-helpers.php' );
138 acf_include( 'includes/api/api-template.php' );
139 acf_include( 'includes/api/api-term.php' );
140
141 // Include classes.
142 acf_include( 'includes/class-acf-data.php' );
143 acf_include( 'includes/class-acf-internal-post-type.php' );
144 acf_include( 'includes/fields/class-acf-field.php' );
145 acf_include( 'includes/locations/abstract-acf-legacy-location.php' );
146 acf_include( 'includes/locations/abstract-acf-location.php' );
147
148 // Include functions.
149 acf_include( 'includes/acf-helper-functions.php' );
150 acf_include( 'includes/acf-hook-functions.php' );
151 acf_include( 'includes/acf-field-functions.php' );
152 acf_include( 'includes/acf-bidirectional-functions.php' );
153 acf_include( 'includes/acf-internal-post-type-functions.php' );
154 acf_include( 'includes/acf-post-type-functions.php' );
155 acf_include( 'includes/acf-taxonomy-functions.php' );
156 acf_include( 'includes/acf-field-group-functions.php' );
157 acf_include( 'includes/acf-form-functions.php' );
158 acf_include( 'includes/acf-meta-functions.php' );
159 acf_include( 'includes/acf-post-functions.php' );
160 acf_include( 'includes/acf-user-functions.php' );
161 acf_include( 'includes/acf-value-functions.php' );
162 acf_include( 'includes/acf-input-functions.php' );
163 acf_include( 'includes/acf-wp-functions.php' );
164
165 // Include core.
166 acf_include( 'includes/fields.php' );
167 acf_include( 'includes/locations.php' );
168 acf_include( 'includes/assets.php' );
169 acf_include( 'includes/compatibility.php' );
170 acf_include( 'includes/deprecated.php' );
171 acf_include( 'includes/l10n.php' );
172 acf_include( 'includes/local-fields.php' );
173 acf_include( 'includes/local-meta.php' );
174 acf_include( 'includes/local-json.php' );
175 acf_include( 'includes/loop.php' );
176 acf_include( 'includes/media.php' );
177 acf_include( 'includes/revisions.php' );
178 acf_include( 'includes/upgrades.php' );
179 acf_include( 'includes/validation.php' );
180 acf_include( 'includes/rest-api.php' );
181
182 // Include field group class.
183 acf_include( 'includes/post-types/class-acf-field-group.php' );
184
185 // Include ajax.
186 acf_include( 'includes/ajax/class-acf-ajax.php' );
187 acf_include( 'includes/ajax/class-acf-ajax-check-screen.php' );
188 acf_include( 'includes/ajax/class-acf-ajax-user-setting.php' );
189 acf_include( 'includes/ajax/class-acf-ajax-upgrade.php' );
190 acf_include( 'includes/ajax/class-acf-ajax-query.php' );
191 acf_include( 'includes/ajax/class-acf-ajax-query-users.php' );
192 acf_include( 'includes/ajax/class-acf-ajax-local-json-diff.php' );
193
194 // Include forms.
195 acf_include( 'includes/forms/form-attachment.php' );
196 acf_include( 'includes/forms/form-comment.php' );
197 acf_include( 'includes/forms/form-customizer.php' );
198 acf_include( 'includes/forms/form-front.php' );
199 acf_include( 'includes/forms/form-nav-menu.php' );
200 acf_include( 'includes/forms/form-post.php' );
201 acf_include( 'includes/forms/form-gutenberg.php' );
202 acf_include( 'includes/forms/form-taxonomy.php' );
203 acf_include( 'includes/forms/form-user.php' );
204 acf_include( 'includes/forms/form-widget.php' );
205
206 // Include admin.
207 if ( is_admin() ) {
208 acf_include( 'includes/admin/admin.php' );
209 acf_include( 'includes/admin/admin-internal-post-type-list.php' );
210 acf_include( 'includes/admin/admin-internal-post-type.php' );
211 acf_include( 'includes/admin/admin-notices.php' );
212 acf_include( 'includes/admin/admin-tools.php' );
213 acf_include( 'includes/admin/admin-upgrade.php' );
214 }
215
216 // Include legacy.
217 acf_include( 'includes/legacy/legacy-locations.php' );
218
219 // Include PRO.
220 acf_include( 'pro/acf-pro.php' );
221
222 if ( is_admin() && function_exists( 'acf_is_pro' ) && ! acf_is_pro() ) {
223 acf_include( 'includes/admin/admin-options-pages-preview.php' );
224 }
225
226 // Add actions.
227 add_action( 'init', array( $this, 'register_post_status' ), 4 );
228 add_action( 'init', array( $this, 'init' ), 5 );
229 add_action( 'init', array( $this, 'register_post_types' ), 5 );
230 add_action( 'activated_plugin', array( $this, 'deactivate_other_instances' ) );
231 add_action( 'pre_current_active_plugins', array( $this, 'plugin_deactivated_notice' ) );
232
233 // Add filters.
234 add_filter( 'posts_where', array( $this, 'posts_where' ), 10, 2 );
235 }
236
237 /**
238 * Completes the setup process on "init" of earlier.
239 *
240 * @date 28/09/13
241 * @since 5.0.0
242 */
243 public function init() {
244
245 // Bail early if called directly from functions.php or plugin file.
246 if ( ! did_action( 'plugins_loaded' ) ) {
247 return;
248 }
249
250 // This function may be called directly from template functions. Bail early if already did this.
251 if ( acf_did( 'init' ) ) {
252 return;
253 }
254
255 // Update url setting. Allows other plugins to modify the URL (force SSL).
256 acf_update_setting( 'url', plugin_dir_url( __FILE__ ) );
257
258 // Load textdomain file.
259 acf_load_textdomain();
260
261 // Include 3rd party compatiblity.
262 acf_include( 'includes/third-party.php' );
263
264 // Include wpml support.
265 if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
266 acf_include( 'includes/wpml.php' );
267 }
268
269 // Add post types and taxonomies.
270 if ( acf_get_setting( 'enable_post_types' ) ) {
271 acf_include( 'includes/post-types/class-acf-taxonomy.php' );
272 acf_include( 'includes/post-types/class-acf-post-type.php' );
273 }
274
275 // Add other ACF internal post types.
276 do_action( 'acf/init_internal_post_types' );
277
278 // Include fields.
279 acf_include( 'includes/fields/class-acf-field-text.php' );
280 acf_include( 'includes/fields/class-acf-field-textarea.php' );
281 acf_include( 'includes/fields/class-acf-field-number.php' );
282 acf_include( 'includes/fields/class-acf-field-range.php' );
283 acf_include( 'includes/fields/class-acf-field-email.php' );
284 acf_include( 'includes/fields/class-acf-field-url.php' );
285 acf_include( 'includes/fields/class-acf-field-password.php' );
286 acf_include( 'includes/fields/class-acf-field-image.php' );
287 acf_include( 'includes/fields/class-acf-field-file.php' );
288 acf_include( 'includes/fields/class-acf-field-wysiwyg.php' );
289 acf_include( 'includes/fields/class-acf-field-oembed.php' );
290 acf_include( 'includes/fields/class-acf-field-select.php' );
291 acf_include( 'includes/fields/class-acf-field-checkbox.php' );
292 acf_include( 'includes/fields/class-acf-field-radio.php' );
293 acf_include( 'includes/fields/class-acf-field-button-group.php' );
294 acf_include( 'includes/fields/class-acf-field-true_false.php' );
295 acf_include( 'includes/fields/class-acf-field-link.php' );
296 acf_include( 'includes/fields/class-acf-field-post_object.php' );
297 acf_include( 'includes/fields/class-acf-field-page_link.php' );
298 acf_include( 'includes/fields/class-acf-field-relationship.php' );
299 acf_include( 'includes/fields/class-acf-field-taxonomy.php' );
300 acf_include( 'includes/fields/class-acf-field-user.php' );
301 acf_include( 'includes/fields/class-acf-field-google-map.php' );
302 acf_include( 'includes/fields/class-acf-field-date_picker.php' );
303 acf_include( 'includes/fields/class-acf-field-date_time_picker.php' );
304 acf_include( 'includes/fields/class-acf-field-time_picker.php' );
305 acf_include( 'includes/fields/class-acf-field-color_picker.php' );
306 acf_include( 'includes/fields/class-acf-field-message.php' );
307 acf_include( 'includes/fields/class-acf-field-accordion.php' );
308 acf_include( 'includes/fields/class-acf-field-tab.php' );
309 acf_include( 'includes/fields/class-acf-field-group.php' );
310
311 /**
312 * Fires after field types have been included.
313 *
314 * @date 28/09/13
315 * @since 5.0.0
316 *
317 * @param int ACF_FIELD_API_VERSION The field API version.
318 */
319 do_action( 'acf/include_field_types', ACF_FIELD_API_VERSION );
320
321 // Include locations.
322 acf_include( 'includes/locations/class-acf-location-post-type.php' );
323 acf_include( 'includes/locations/class-acf-location-post-template.php' );
324 acf_include( 'includes/locations/class-acf-location-post-status.php' );
325 acf_include( 'includes/locations/class-acf-location-post-format.php' );
326 acf_include( 'includes/locations/class-acf-location-post-category.php' );
327 acf_include( 'includes/locations/class-acf-location-post-taxonomy.php' );
328 acf_include( 'includes/locations/class-acf-location-post.php' );
329 acf_include( 'includes/locations/class-acf-location-page-template.php' );
330 acf_include( 'includes/locations/class-acf-location-page-type.php' );
331 acf_include( 'includes/locations/class-acf-location-page-parent.php' );
332 acf_include( 'includes/locations/class-acf-location-page.php' );
333 acf_include( 'includes/locations/class-acf-location-current-user.php' );
334 acf_include( 'includes/locations/class-acf-location-current-user-role.php' );
335 acf_include( 'includes/locations/class-acf-location-user-form.php' );
336 acf_include( 'includes/locations/class-acf-location-user-role.php' );
337 acf_include( 'includes/locations/class-acf-location-taxonomy.php' );
338 acf_include( 'includes/locations/class-acf-location-attachment.php' );
339 acf_include( 'includes/locations/class-acf-location-comment.php' );
340 acf_include( 'includes/locations/class-acf-location-widget.php' );
341 acf_include( 'includes/locations/class-acf-location-nav-menu.php' );
342 acf_include( 'includes/locations/class-acf-location-nav-menu-item.php' );
343
344 /**
345 * Fires after location types have been included.
346 *
347 * @date 28/09/13
348 * @since 5.0.0
349 *
350 * @param int ACF_FIELD_API_VERSION The field API version.
351 */
352 do_action( 'acf/include_location_rules', ACF_FIELD_API_VERSION );
353
354 /**
355 * Fires during initialization. Used to add local fields.
356 *
357 * @date 28/09/13
358 * @since 5.0.0
359 *
360 * @param int ACF_FIELD_API_VERSION The field API version.
361 */
362 do_action( 'acf/include_fields', ACF_FIELD_API_VERSION );
363
364 /**
365 * Fires during initialization. Used to add local post types.
366 *
367 * @since 6.1
368 *
369 * @param int ACF_MAJOR_VERSION The major version of ACF.
370 */
371 do_action( 'acf/include_post_types', ACF_MAJOR_VERSION );
372
373 /**
374 * Fires during initialization. Used to add local taxonomies.
375 *
376 * @since 6.1
377 *
378 * @param int ACF_MAJOR_VERSION The major version of ACF.
379 */
380 do_action( 'acf/include_taxonomies', ACF_MAJOR_VERSION );
381
382 /**
383 * Fires after ACF is completely "initialized".
384 *
385 * @date 28/09/13
386 * @since 5.0.0
387 *
388 * @param int ACF_MAJOR_VERSION The major version of ACF.
389 */
390 do_action( 'acf/init', ACF_MAJOR_VERSION );
391 }
392
393 /**
394 * Registers the ACF post types.
395 *
396 * @date 22/10/2015
397 * @since 5.3.2
398 */
399 public function register_post_types() {
400 $cap = acf_get_setting( 'capability' );
401
402 // Register the Field Group post type.
403 register_post_type(
404 'acf-field-group',
405 array(
406 'labels' => array(
407 'name' => __( 'Field Groups', 'acf' ),
408 'singular_name' => __( 'Field Group', 'acf' ),
409 'add_new' => __( 'Add New', 'acf' ),
410 'add_new_item' => __( 'Add New Field Group', 'acf' ),
411 'edit_item' => __( 'Edit Field Group', 'acf' ),
412 'new_item' => __( 'New Field Group', 'acf' ),
413 'view_item' => __( 'View Field Group', 'acf' ),
414 'search_items' => __( 'Search Field Groups', 'acf' ),
415 'not_found' => __( 'No Field Groups found', 'acf' ),
416 'not_found_in_trash' => __( 'No Field Groups found in Trash', 'acf' ),
417 ),
418 'public' => false,
419 'hierarchical' => true,
420 'show_ui' => true,
421 'show_in_menu' => false,
422 '_builtin' => false,
423 'capability_type' => 'post',
424 'capabilities' => array(
425 'edit_post' => $cap,
426 'delete_post' => $cap,
427 'edit_posts' => $cap,
428 'delete_posts' => $cap,
429 ),
430 'supports' => false,
431 'rewrite' => false,
432 'query_var' => false,
433 )
434 );
435
436 // Register the Field post type.
437 register_post_type(
438 'acf-field',
439 array(
440 'labels' => array(
441 'name' => __( 'Fields', 'acf' ),
442 'singular_name' => __( 'Field', 'acf' ),
443 'add_new' => __( 'Add New', 'acf' ),
444 'add_new_item' => __( 'Add New Field', 'acf' ),
445 'edit_item' => __( 'Edit Field', 'acf' ),
446 'new_item' => __( 'New Field', 'acf' ),
447 'view_item' => __( 'View Field', 'acf' ),
448 'search_items' => __( 'Search Fields', 'acf' ),
449 'not_found' => __( 'No Fields found', 'acf' ),
450 'not_found_in_trash' => __( 'No Fields found in Trash', 'acf' ),
451 ),
452 'public' => false,
453 'hierarchical' => true,
454 'show_ui' => false,
455 'show_in_menu' => false,
456 '_builtin' => false,
457 'capability_type' => 'post',
458 'capabilities' => array(
459 'edit_post' => $cap,
460 'delete_post' => $cap,
461 'edit_posts' => $cap,
462 'delete_posts' => $cap,
463 ),
464 'supports' => array( 'title' ),
465 'rewrite' => false,
466 'query_var' => false,
467 )
468 );
469 }
470
471 /**
472 * Registers the ACF post statuses.
473 *
474 * @date 22/10/2015
475 * @since 5.3.2
476 */
477 public function register_post_status() {
478
479 // Register the Inactive post status.
480 register_post_status(
481 'acf-disabled',
482 array(
483 'label' => _x( 'Inactive', 'post status', 'acf' ),
484 'public' => true,
485 'exclude_from_search' => false,
486 'show_in_admin_all_list' => true,
487 'show_in_admin_status_list' => true,
488 /* translators: counts for inactive field groups */
489 'label_count' => _n_noop( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', 'acf' ),
490 )
491 );
492 }
493
494 /**
495 * Checks if another version of ACF/ACF PRO is active and deactivates it.
496 * Hooked on `activated_plugin` so other plugin is deactivated when current plugin is activated.
497 *
498 * @param string $plugin The plugin being activated.
499 */
500 public function deactivate_other_instances( $plugin ) {
501 if ( ! in_array( $plugin, array( 'advanced-custom-fields/acf.php', 'advanced-custom-fields-pro/acf.php' ), true ) ) {
502 return;
503 }
504
505 $plugin_to_deactivate = 'advanced-custom-fields/acf.php';
506 $deactivated_notice_id = '1';
507
508 // If we just activated the free version, deactivate the pro version.
509 if ( $plugin === $plugin_to_deactivate ) {
510 $plugin_to_deactivate = 'advanced-custom-fields-pro/acf.php';
511 $deactivated_notice_id = '2';
512 }
513
514 if ( is_multisite() && is_network_admin() ) {
515 $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
516 $active_plugins = array_keys( $active_plugins );
517 } else {
518 $active_plugins = (array) get_option( 'active_plugins', array() );
519 }
520
521 foreach ( $active_plugins as $plugin_basename ) {
522 if ( $plugin_to_deactivate === $plugin_basename ) {
523 set_transient( 'acf_deactivated_notice_id', $deactivated_notice_id, 1 * HOUR_IN_SECONDS );
524 deactivate_plugins( $plugin_basename );
525 return;
526 }
527 }
528 }
529
530 /**
531 * Displays a notice when either ACF or ACF PRO is automatically deactivated.
532 */
533 public function plugin_deactivated_notice() {
534 $deactivated_notice_id = (int) get_transient( 'acf_deactivated_notice_id' );
535 if ( ! in_array( $deactivated_notice_id, array( 1, 2 ), true ) ) {
536 return;
537 }
538
539 $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' );
540 if ( 2 === $deactivated_notice_id ) {
541 $message = __( "Advanced Custom Fields and Advanced Custom Fields PRO should not be active at the same time. We've automatically deactivated Advanced Custom Fields PRO.", 'acf' );
542 }
543
544 ?>
545 <div class="updated" style="border-left: 4px solid #ffba00;">
546 <p><?php echo esc_html( $message ); ?></p>
547 </div>
548 <?php
549
550 delete_transient( 'acf_deactivated_notice_id' );
551 }
552
553 /**
554 * Filters the $where clause allowing for custom WP_Query args.
555 *
556 * @date 31/8/19
557 * @since 5.8.1
558 *
559 * @param string $where The WHERE clause.
560 * @param WP_Query $wp_query The query object.
561 * @return string
562 */
563 public function posts_where( $where, $wp_query ) {
564 global $wpdb;
565
566 $field_key = $wp_query->get( 'acf_field_key' );
567 $field_name = $wp_query->get( 'acf_field_name' );
568 $group_key = $wp_query->get( 'acf_group_key' );
569 $post_type_key = $wp_query->get( 'acf_post_type_key' );
570 $taxonomy_key = $wp_query->get( 'acf_taxonomy_key' );
571
572 // Add custom "acf_field_key" arg.
573 if ( $field_key ) {
574 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $field_key );
575 }
576
577 // Add custom "acf_field_name" arg.
578 if ( $field_name ) {
579 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_excerpt = %s", $field_name );
580 }
581
582 // Add custom "acf_group_key" arg.
583 if ( $group_key ) {
584 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $group_key );
585 }
586
587 // Add custom "acf_post_type_key" arg.
588 if ( $post_type_key ) {
589 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $post_type_key );
590 }
591
592 // Add custom "acf_taxonomy_key" arg.
593 if ( $taxonomy_key ) {
594 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $taxonomy_key );
595 }
596
597 return $where;
598 }
599
600 /**
601 * Defines a constant if doesnt already exist.
602 *
603 * @date 3/5/17
604 * @since 5.5.13
605 *
606 * @param string $name The constant name.
607 * @param mixed $value The constant value.
608 * @return void
609 */
610 public function define( $name, $value = true ) {
611 if ( ! defined( $name ) ) {
612 define( $name, $value );
613 }
614 }
615
616 /**
617 * Returns true if a setting exists for this name.
618 *
619 * @date 2/2/18
620 * @since 5.6.5
621 *
622 * @param string $name The setting name.
623 * @return boolean
624 */
625 public function has_setting( $name ) {
626 return isset( $this->settings[ $name ] );
627 }
628
629 /**
630 * Returns a setting or null if doesn't exist.
631 *
632 * @date 28/09/13
633 * @since 5.0.0
634 *
635 * @param string $name The setting name.
636 * @return mixed
637 */
638 public function get_setting( $name ) {
639 return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : null;
640 }
641
642 /**
643 * Updates a setting for the given name and value.
644 *
645 * @date 28/09/13
646 * @since 5.0.0
647 *
648 * @param string $name The setting name.
649 * @param mixed $value The setting value.
650 * @return true
651 */
652 public function update_setting( $name, $value ) {
653 $this->settings[ $name ] = $value;
654 return true;
655 }
656
657 /**
658 * Returns data or null if doesn't exist.
659 *
660 * @date 28/09/13
661 * @since 5.0.0
662 *
663 * @param string $name The data name.
664 * @return mixed
665 */
666 public function get_data( $name ) {
667 return isset( $this->data[ $name ] ) ? $this->data[ $name ] : null;
668 }
669
670 /**
671 * Sets data for the given name and value.
672 *
673 * @date 28/09/13
674 * @since 5.0.0
675 *
676 * @param string $name The data name.
677 * @param mixed $value The data value.
678 * @return void
679 */
680 public function set_data( $name, $value ) {
681 $this->data[ $name ] = $value;
682 }
683
684 /**
685 * Returns an instance or null if doesn't exist.
686 *
687 * @date 13/2/18
688 * @since 5.6.9
689 *
690 * @param string $class The instance class name.
691 * @return object
692 */
693 public function get_instance( $class ) {
694 $name = strtolower( $class );
695 return isset( $this->instances[ $name ] ) ? $this->instances[ $name ] : null;
696 }
697
698 /**
699 * Creates and stores an instance of the given class.
700 *
701 * @date 13/2/18
702 * @since 5.6.9
703 *
704 * @param string $class The instance class name.
705 * @return object
706 */
707 public function new_instance( $class ) {
708 $instance = new $class();
709 $name = strtolower( $class );
710 $this->instances[ $name ] = $instance;
711 return $instance;
712 }
713
714 /**
715 * Magic __isset method for backwards compatibility.
716 *
717 * @date 24/4/20
718 * @since 5.9.0
719 *
720 * @param string $key Key name.
721 * @return boolean
722 */
723 public function __isset( $key ) {
724 return in_array( $key, array( 'locations', 'json' ), true );
725 }
726
727 /**
728 * Magic __get method for backwards compatibility.
729 *
730 * @date 24/4/20
731 * @since 5.9.0
732 *
733 * @param string $key Key name.
734 * @return mixed
735 */
736 public function __get( $key ) {
737 switch ( $key ) {
738 case 'locations':
739 return acf_get_instance( 'ACF_Legacy_Locations' );
740 case 'json':
741 return acf_get_instance( 'ACF_Local_JSON' );
742 }
743 return null;
744 }
745
746 /**
747 * Plugin Activation Hook
748 *
749 * @since 6.2.6
750 */
751 public function acf_plugin_activated() {
752 // Set the first activated version of ACF.
753 if ( null === get_option( 'acf_first_activated_version', null ) ) {
754 // If acf_version is set, this isn't the first activated version, so leave it unset so it's legacy.
755 if ( null === get_option( 'acf_version', null ) ) {
756 update_option( 'acf_first_activated_version', ACF_VERSION, true );
757 }
758 }
759 }
760 }
761
762 /**
763 * The main function responsible for returning the one true acf Instance to functions everywhere.
764 * Use this function like you would a global variable, except without needing to declare the global.
765 *
766 * Example: <?php $acf = acf(); ?>
767 *
768 * @date 4/09/13
769 * @since 4.3.0
770 *
771 * @return ACF
772 */
773 function acf() {
774 global $acf;
775
776 // Instantiate only once.
777 if ( ! isset( $acf ) ) {
778 $acf = new ACF();
779 $acf->initialize();
780 }
781 return $acf;
782 }
783
784 // Instantiate.
785 acf();
786 } // class_exists check
787