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