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