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