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