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