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