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