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