PluginProbe
Advanced Custom Fields (ACF®) / 5.11.2
Advanced Custom Fields (ACF®) v5.11.2
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®) 5.11.2, at acf.php

672 lines 19.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Advanced Custom Fields
4 Plugin URI: https://www.advancedcustomfields.com
5 Description: Customize WordPress with powerful, professional and intuitive fields.
6 Version: 5.11.2
7 Author: Delicious Brains
8 Author URI: https://www.advancedcustomfields.com
9 Text Domain: acf
10 Domain Path: /lang
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly
15 }
16
17 if ( ! class_exists( 'ACF' ) ) :
18
19 class ACF {
20
21 /** @var string The plugin version number. */
22 var $version = '5.11.2';
23
24 /** @var array The plugin settings array. */
25 var $settings = array();
26
27 /** @var array The plugin data array. */
28 var $data = array();
29
30 /** @var array Storage for class instances. */
31 var $instances = array();
32
33 /**
34 * __construct
35 *
36 * A dummy constructor to ensure ACF is only setup once.
37 *
38 * @date 23/06/12
39 * @since 5.0.0
40 *
41 * @param void
42 * @return void
43 */
44 function __construct() {
45 // Do nothing.
46 }
47
48 /**
49 * initialize
50 *
51 * Sets up the ACF plugin.
52 *
53 * @date 28/09/13
54 * @since 5.0.0
55 *
56 * @param void
57 * @return void
58 */
59 function initialize() {
60
61 // Define constants.
62 $this->define( 'ACF', true );
63 $this->define( 'ACF_PATH', plugin_dir_path( __FILE__ ) );
64 $this->define( 'ACF_BASENAME', plugin_basename( __FILE__ ) );
65 $this->define( 'ACF_VERSION', $this->version );
66 $this->define( 'ACF_MAJOR_VERSION', 5 );
67
68 // Define settings.
69 $this->settings = array(
70 'name' => __( 'Advanced Custom Fields', 'acf' ),
71 'slug' => dirname( ACF_BASENAME ),
72 'version' => ACF_VERSION,
73 'basename' => ACF_BASENAME,
74 'path' => ACF_PATH,
75 'file' => __FILE__,
76 'url' => plugin_dir_url( __FILE__ ),
77 'show_admin' => true,
78 'show_updates' => true,
79 'stripslashes' => false,
80 'local' => true,
81 'json' => true,
82 'save_json' => '',
83 'load_json' => array(),
84 'default_language' => '',
85 'current_language' => '',
86 'capability' => 'manage_options',
87 'uploader' => 'wp',
88 'autoload' => false,
89 'l10n' => true,
90 'l10n_textdomain' => '',
91 'google_api_key' => '',
92 'google_api_client' => '',
93 'enqueue_google_maps' => true,
94 'enqueue_select2' => true,
95 'enqueue_datepicker' => true,
96 'enqueue_datetimepicker' => true,
97 'select2_version' => 4,
98 'row_index_offset' => 1,
99 'remove_wp_meta_box' => true,
100 'rest_api_enabled' => true,
101 'rest_api_format' => 'light',
102 'rest_api_embed_links' => true,
103 );
104
105 // Include utility functions.
106 include_once ACF_PATH . 'includes/acf-utility-functions.php';
107
108 // Include previous API functions.
109 acf_include( 'includes/api/api-helpers.php' );
110 acf_include( 'includes/api/api-template.php' );
111 acf_include( 'includes/api/api-term.php' );
112
113 // Include classes.
114 acf_include( 'includes/class-acf-data.php' );
115 acf_include( 'includes/fields/class-acf-field.php' );
116 acf_include( 'includes/locations/abstract-acf-legacy-location.php' );
117 acf_include( 'includes/locations/abstract-acf-location.php' );
118
119 // Include functions.
120 acf_include( 'includes/acf-helper-functions.php' );
121 acf_include( 'includes/acf-hook-functions.php' );
122 acf_include( 'includes/acf-field-functions.php' );
123 acf_include( 'includes/acf-field-group-functions.php' );
124 acf_include( 'includes/acf-form-functions.php' );
125 acf_include( 'includes/acf-meta-functions.php' );
126 acf_include( 'includes/acf-post-functions.php' );
127 acf_include( 'includes/acf-user-functions.php' );
128 acf_include( 'includes/acf-value-functions.php' );
129 acf_include( 'includes/acf-input-functions.php' );
130 acf_include( 'includes/acf-wp-functions.php' );
131
132 // Include core.
133 acf_include( 'includes/fields.php' );
134 acf_include( 'includes/locations.php' );
135 acf_include( 'includes/assets.php' );
136 acf_include( 'includes/compatibility.php' );
137 acf_include( 'includes/deprecated.php' );
138 acf_include( 'includes/l10n.php' );
139 acf_include( 'includes/local-fields.php' );
140 acf_include( 'includes/local-meta.php' );
141 acf_include( 'includes/local-json.php' );
142 acf_include( 'includes/loop.php' );
143 acf_include( 'includes/media.php' );
144 acf_include( 'includes/revisions.php' );
145 acf_include( 'includes/updates.php' );
146 acf_include( 'includes/upgrades.php' );
147 acf_include( 'includes/validation.php' );
148 acf_include( 'includes/rest-api.php' );
149
150 // Include ajax.
151 acf_include( 'includes/ajax/class-acf-ajax.php' );
152 acf_include( 'includes/ajax/class-acf-ajax-check-screen.php' );
153 acf_include( 'includes/ajax/class-acf-ajax-user-setting.php' );
154 acf_include( 'includes/ajax/class-acf-ajax-upgrade.php' );
155 acf_include( 'includes/ajax/class-acf-ajax-query.php' );
156 acf_include( 'includes/ajax/class-acf-ajax-query-users.php' );
157 acf_include( 'includes/ajax/class-acf-ajax-local-json-diff.php' );
158
159 // Include forms.
160 acf_include( 'includes/forms/form-attachment.php' );
161 acf_include( 'includes/forms/form-comment.php' );
162 acf_include( 'includes/forms/form-customizer.php' );
163 acf_include( 'includes/forms/form-front.php' );
164 acf_include( 'includes/forms/form-nav-menu.php' );
165 acf_include( 'includes/forms/form-post.php' );
166 acf_include( 'includes/forms/form-gutenberg.php' );
167 acf_include( 'includes/forms/form-taxonomy.php' );
168 acf_include( 'includes/forms/form-user.php' );
169 acf_include( 'includes/forms/form-widget.php' );
170
171 // Include admin.
172 if ( is_admin() ) {
173 acf_include( 'includes/admin/admin.php' );
174 acf_include( 'includes/admin/admin-field-group.php' );
175 acf_include( 'includes/admin/admin-field-groups.php' );
176 acf_include( 'includes/admin/admin-notices.php' );
177 acf_include( 'includes/admin/admin-tools.php' );
178 acf_include( 'includes/admin/admin-upgrade.php' );
179 }
180
181 // Include legacy.
182 acf_include( 'includes/legacy/legacy-locations.php' );
183
184 // Include PRO.
185 acf_include( 'pro/acf-pro.php' );
186
187 // Include tests.
188 if ( defined( 'ACF_DEV' ) && ACF_DEV ) {
189 acf_include( 'tests/tests.php' );
190 }
191
192 // Add actions.
193 add_action( 'init', array( $this, 'init' ), 5 );
194 add_action( 'init', array( $this, 'register_post_types' ), 5 );
195 add_action( 'init', array( $this, 'register_post_status' ), 5 );
196
197 // Add filters.
198 add_filter( 'posts_where', array( $this, 'posts_where' ), 10, 2 );
199 }
200
201 /**
202 * init
203 *
204 * Completes the setup process on "init" of earlier.
205 *
206 * @date 28/09/13
207 * @since 5.0.0
208 *
209 * @param void
210 * @return void
211 */
212 function init() {
213
214 // Bail early if called directly from functions.php or plugin file.
215 if ( ! did_action( 'plugins_loaded' ) ) {
216 return;
217 }
218
219 // This function may be called directly from template functions. Bail early if already did this.
220 if ( acf_did( 'init' ) ) {
221 return;
222 }
223
224 // Update url setting. Allows other plugins to modify the URL (force SSL).
225 acf_update_setting( 'url', plugin_dir_url( __FILE__ ) );
226
227 // Load textdomain file.
228 acf_load_textdomain();
229
230 // Include 3rd party compatiblity.
231 acf_include( 'includes/third-party.php' );
232
233 // Include wpml support.
234 if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
235 acf_include( 'includes/wpml.php' );
236 }
237
238 // Include fields.
239 acf_include( 'includes/fields/class-acf-field-text.php' );
240 acf_include( 'includes/fields/class-acf-field-textarea.php' );
241 acf_include( 'includes/fields/class-acf-field-number.php' );
242 acf_include( 'includes/fields/class-acf-field-range.php' );
243 acf_include( 'includes/fields/class-acf-field-email.php' );
244 acf_include( 'includes/fields/class-acf-field-url.php' );
245 acf_include( 'includes/fields/class-acf-field-password.php' );
246 acf_include( 'includes/fields/class-acf-field-image.php' );
247 acf_include( 'includes/fields/class-acf-field-file.php' );
248 acf_include( 'includes/fields/class-acf-field-wysiwyg.php' );
249 acf_include( 'includes/fields/class-acf-field-oembed.php' );
250 acf_include( 'includes/fields/class-acf-field-select.php' );
251 acf_include( 'includes/fields/class-acf-field-checkbox.php' );
252 acf_include( 'includes/fields/class-acf-field-radio.php' );
253 acf_include( 'includes/fields/class-acf-field-button-group.php' );
254 acf_include( 'includes/fields/class-acf-field-true_false.php' );
255 acf_include( 'includes/fields/class-acf-field-link.php' );
256 acf_include( 'includes/fields/class-acf-field-post_object.php' );
257 acf_include( 'includes/fields/class-acf-field-page_link.php' );
258 acf_include( 'includes/fields/class-acf-field-relationship.php' );
259 acf_include( 'includes/fields/class-acf-field-taxonomy.php' );
260 acf_include( 'includes/fields/class-acf-field-user.php' );
261 acf_include( 'includes/fields/class-acf-field-google-map.php' );
262 acf_include( 'includes/fields/class-acf-field-date_picker.php' );
263 acf_include( 'includes/fields/class-acf-field-date_time_picker.php' );
264 acf_include( 'includes/fields/class-acf-field-time_picker.php' );
265 acf_include( 'includes/fields/class-acf-field-color_picker.php' );
266 acf_include( 'includes/fields/class-acf-field-message.php' );
267 acf_include( 'includes/fields/class-acf-field-accordion.php' );
268 acf_include( 'includes/fields/class-acf-field-tab.php' );
269 acf_include( 'includes/fields/class-acf-field-group.php' );
270
271 /**
272 * Fires after field types have been included.
273 *
274 * @date 28/09/13
275 * @since 5.0.0
276 *
277 * @param int $major_version The major version of ACF.
278 */
279 do_action( 'acf/include_field_types', ACF_MAJOR_VERSION );
280
281 // Include locations.
282 acf_include( 'includes/locations/class-acf-location-post-type.php' );
283 acf_include( 'includes/locations/class-acf-location-post-template.php' );
284 acf_include( 'includes/locations/class-acf-location-post-status.php' );
285 acf_include( 'includes/locations/class-acf-location-post-format.php' );
286 acf_include( 'includes/locations/class-acf-location-post-category.php' );
287 acf_include( 'includes/locations/class-acf-location-post-taxonomy.php' );
288 acf_include( 'includes/locations/class-acf-location-post.php' );
289 acf_include( 'includes/locations/class-acf-location-page-template.php' );
290 acf_include( 'includes/locations/class-acf-location-page-type.php' );
291 acf_include( 'includes/locations/class-acf-location-page-parent.php' );
292 acf_include( 'includes/locations/class-acf-location-page.php' );
293 acf_include( 'includes/locations/class-acf-location-current-user.php' );
294 acf_include( 'includes/locations/class-acf-location-current-user-role.php' );
295 acf_include( 'includes/locations/class-acf-location-user-form.php' );
296 acf_include( 'includes/locations/class-acf-location-user-role.php' );
297 acf_include( 'includes/locations/class-acf-location-taxonomy.php' );
298 acf_include( 'includes/locations/class-acf-location-attachment.php' );
299 acf_include( 'includes/locations/class-acf-location-comment.php' );
300 acf_include( 'includes/locations/class-acf-location-widget.php' );
301 acf_include( 'includes/locations/class-acf-location-nav-menu.php' );
302 acf_include( 'includes/locations/class-acf-location-nav-menu-item.php' );
303
304 /**
305 * Fires after location types have been included.
306 *
307 * @date 28/09/13
308 * @since 5.0.0
309 *
310 * @param int $major_version The major version of ACF.
311 */
312 do_action( 'acf/include_location_rules', ACF_MAJOR_VERSION );
313
314 /**
315 * Fires during initialization. Used to add local fields.
316 *
317 * @date 28/09/13
318 * @since 5.0.0
319 *
320 * @param int $major_version The major version of ACF.
321 */
322 do_action( 'acf/include_fields', ACF_MAJOR_VERSION );
323
324 /**
325 * Fires after ACF is completely "initialized".
326 *
327 * @date 28/09/13
328 * @since 5.0.0
329 *
330 * @param int $major_version The major version of ACF.
331 */
332 do_action( 'acf/init', ACF_MAJOR_VERSION );
333 }
334
335 /**
336 * register_post_types
337 *
338 * Registers the ACF post types.
339 *
340 * @date 22/10/2015
341 * @since 5.3.2
342 *
343 * @param void
344 * @return void
345 */
346 function register_post_types() {
347
348 // Vars.
349 $cap = acf_get_setting( 'capability' );
350
351 // Register the Field Group post type.
352 register_post_type(
353 'acf-field-group',
354 array(
355 'labels' => array(
356 'name' => __( 'Field Groups', 'acf' ),
357 'singular_name' => __( 'Field Group', 'acf' ),
358 'add_new' => __( 'Add New', 'acf' ),
359 'add_new_item' => __( 'Add New Field Group', 'acf' ),
360 'edit_item' => __( 'Edit Field Group', 'acf' ),
361 'new_item' => __( 'New Field Group', 'acf' ),
362 'view_item' => __( 'View Field Group', 'acf' ),
363 'search_items' => __( 'Search Field Groups', 'acf' ),
364 'not_found' => __( 'No Field Groups found', 'acf' ),
365 'not_found_in_trash' => __( 'No Field Groups found in Trash', 'acf' ),
366 ),
367 'public' => false,
368 'hierarchical' => true,
369 'show_ui' => true,
370 'show_in_menu' => false,
371 '_builtin' => false,
372 'capability_type' => 'post',
373 'capabilities' => array(
374 'edit_post' => $cap,
375 'delete_post' => $cap,
376 'edit_posts' => $cap,
377 'delete_posts' => $cap,
378 ),
379 'supports' => array( 'title' ),
380 'rewrite' => false,
381 'query_var' => false,
382 )
383 );
384
385 // Register the Field post type.
386 register_post_type(
387 'acf-field',
388 array(
389 'labels' => array(
390 'name' => __( 'Fields', 'acf' ),
391 'singular_name' => __( 'Field', 'acf' ),
392 'add_new' => __( 'Add New', 'acf' ),
393 'add_new_item' => __( 'Add New Field', 'acf' ),
394 'edit_item' => __( 'Edit Field', 'acf' ),
395 'new_item' => __( 'New Field', 'acf' ),
396 'view_item' => __( 'View Field', 'acf' ),
397 'search_items' => __( 'Search Fields', 'acf' ),
398 'not_found' => __( 'No Fields found', 'acf' ),
399 'not_found_in_trash' => __( 'No Fields found in Trash', 'acf' ),
400 ),
401 'public' => false,
402 'hierarchical' => true,
403 'show_ui' => false,
404 'show_in_menu' => false,
405 '_builtin' => false,
406 'capability_type' => 'post',
407 'capabilities' => array(
408 'edit_post' => $cap,
409 'delete_post' => $cap,
410 'edit_posts' => $cap,
411 'delete_posts' => $cap,
412 ),
413 'supports' => array( 'title' ),
414 'rewrite' => false,
415 'query_var' => false,
416 )
417 );
418 }
419
420 /**
421 * register_post_status
422 *
423 * Registers the ACF post statuses.
424 *
425 * @date 22/10/2015
426 * @since 5.3.2
427 *
428 * @param void
429 * @return void
430 */
431 function register_post_status() {
432
433 // Register the Disabled post status.
434 register_post_status(
435 'acf-disabled',
436 array(
437 'label' => _x( 'Disabled', 'post status', 'acf' ),
438 'public' => true,
439 'exclude_from_search' => false,
440 'show_in_admin_all_list' => true,
441 'show_in_admin_status_list' => true,
442 'label_count' => _n_noop( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', 'acf' ),
443 )
444 );
445 }
446
447 /**
448 * posts_where
449 *
450 * Filters the $where clause allowing for custom WP_Query args.
451 *
452 * @date 31/8/19
453 * @since 5.8.1
454 *
455 * @param string $where The WHERE clause.
456 * @return WP_Query $wp_query The query object.
457 */
458 function posts_where( $where, $wp_query ) {
459 global $wpdb;
460
461 // Add custom "acf_field_key" arg.
462 if ( $field_key = $wp_query->get( 'acf_field_key' ) ) {
463 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $field_key );
464 }
465
466 // Add custom "acf_field_name" arg.
467 if ( $field_name = $wp_query->get( 'acf_field_name' ) ) {
468 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_excerpt = %s", $field_name );
469 }
470
471 // Add custom "acf_group_key" arg.
472 if ( $group_key = $wp_query->get( 'acf_group_key' ) ) {
473 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $group_key );
474 }
475
476 // Return.
477 return $where;
478 }
479
480 /**
481 * define
482 *
483 * Defines a constant if doesnt already exist.
484 *
485 * @date 3/5/17
486 * @since 5.5.13
487 *
488 * @param string $name The constant name.
489 * @param mixed $value The constant value.
490 * @return void
491 */
492 function define( $name, $value = true ) {
493 if ( ! defined( $name ) ) {
494 define( $name, $value );
495 }
496 }
497
498 /**
499 * has_setting
500 *
501 * Returns true if a setting exists for this name.
502 *
503 * @date 2/2/18
504 * @since 5.6.5
505 *
506 * @param string $name The setting name.
507 * @return boolean
508 */
509 function has_setting( $name ) {
510 return isset( $this->settings[ $name ] );
511 }
512
513 /**
514 * get_setting
515 *
516 * Returns a setting or null if doesn't exist.
517 *
518 * @date 28/09/13
519 * @since 5.0.0
520 *
521 * @param string $name The setting name.
522 * @return mixed
523 */
524 function get_setting( $name ) {
525 return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : null;
526 }
527
528 /**
529 * update_setting
530 *
531 * Updates a setting for the given name and value.
532 *
533 * @date 28/09/13
534 * @since 5.0.0
535 *
536 * @param string $name The setting name.
537 * @param mixed $value The setting value.
538 * @return true
539 */
540 function update_setting( $name, $value ) {
541 $this->settings[ $name ] = $value;
542 return true;
543 }
544
545 /**
546 * get_data
547 *
548 * Returns data or null if doesn't exist.
549 *
550 * @date 28/09/13
551 * @since 5.0.0
552 *
553 * @param string $name The data name.
554 * @return mixed
555 */
556 function get_data( $name ) {
557 return isset( $this->data[ $name ] ) ? $this->data[ $name ] : null;
558 }
559
560 /**
561 * set_data
562 *
563 * Sets data for the given name and value.
564 *
565 * @date 28/09/13
566 * @since 5.0.0
567 *
568 * @param string $name The data name.
569 * @param mixed $value The data value.
570 * @return void
571 */
572 function set_data( $name, $value ) {
573 $this->data[ $name ] = $value;
574 }
575
576 /**
577 * get_instance
578 *
579 * Returns an instance or null if doesn't exist.
580 *
581 * @date 13/2/18
582 * @since 5.6.9
583 *
584 * @param string $class The instance class name.
585 * @return object
586 */
587 function get_instance( $class ) {
588 $name = strtolower( $class );
589 return isset( $this->instances[ $name ] ) ? $this->instances[ $name ] : null;
590 }
591
592 /**
593 * new_instance
594 *
595 * Creates and stores an instance of the given class.
596 *
597 * @date 13/2/18
598 * @since 5.6.9
599 *
600 * @param string $class The instance class name.
601 * @return object
602 */
603 function new_instance( $class ) {
604 $instance = new $class();
605 $name = strtolower( $class );
606 $this->instances[ $name ] = $instance;
607 return $instance;
608 }
609
610 /**
611 * Magic __isset method for backwards compatibility.
612 *
613 * @date 24/4/20
614 * @since 5.9.0
615 *
616 * @param string $key Key name.
617 * @return bool
618 */
619 public function __isset( $key ) {
620 return in_array( $key, array( 'locations', 'json' ) );
621 }
622
623 /**
624 * Magic __get method for backwards compatibility.
625 *
626 * @date 24/4/20
627 * @since 5.9.0
628 *
629 * @param string $key Key name.
630 * @return mixed
631 */
632 public function __get( $key ) {
633 switch ( $key ) {
634 case 'locations':
635 return acf_get_instance( 'ACF_Legacy_Locations' );
636 case 'json':
637 return acf_get_instance( 'ACF_Local_JSON' );
638 }
639 return null;
640 }
641 }
642
643 /*
644 * acf
645 *
646 * The main function responsible for returning the one true acf Instance to functions everywhere.
647 * Use this function like you would a global variable, except without needing to declare the global.
648 *
649 * Example: <?php $acf = acf(); ?>
650 *
651 * @date 4/09/13
652 * @since 4.3.0
653 *
654 * @param void
655 * @return ACF
656 */
657 function acf() {
658 global $acf;
659
660 // Instantiate only once.
661 if ( ! isset( $acf ) ) {
662 $acf = new ACF();
663 $acf->initialize();
664 }
665 return $acf;
666 }
667
668 // Instantiate.
669 acf();
670
671 endif; // class_exists check
672