PluginProbe
Advanced Custom Fields (ACF®) / 5.8.8
Advanced Custom Fields (ACF®) v5.8.8
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
618 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.8
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.8';
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 }
169
170 // Include PRO.
171 acf_include('pro/acf-pro.php');
172
173 // Include tests.
174 if( defined('ACF_DEV') && ACF_DEV ) {
175 acf_include('tests/tests.php');
176 }
177
178 // Add actions.
179 add_action( 'init', array($this, 'init'), 5 );
180 add_action( 'init', array($this, 'register_post_types'), 5 );
181 add_action( 'init', array($this, 'register_post_status'), 5 );
182
183 // Add filters.
184 add_filter( 'posts_where', array($this, 'posts_where'), 10, 2 );
185 }
186
187 /**
188 * init
189 *
190 * Completes the setup process on "init" of earlier.
191 *
192 * @date 28/09/13
193 * @since 5.0.0
194 *
195 * @param void
196 * @return void
197 */
198 function init() {
199
200 // Bail early if called directly from functions.php or plugin file.
201 if( !did_action('plugins_loaded') ) {
202 return;
203 }
204
205 // This function may be called directly from template functions. Bail early if already did this.
206 if( acf_did('init') ) {
207 return;
208 }
209
210 // Update url setting. Allows other plugins to modify the URL (force SSL).
211 acf_update_setting( 'url', plugin_dir_url( __FILE__ ) );
212
213 // Load textdomain file.
214 acf_load_textdomain();
215
216 // Include 3rd party compatiblity.
217 acf_include('includes/third-party.php');
218
219 // Include wpml support.
220 if( defined('ICL_SITEPRESS_VERSION') ) {
221 acf_include('includes/wpml.php');
222 }
223
224 // Include fields.
225 acf_include('includes/fields/class-acf-field-text.php');
226 acf_include('includes/fields/class-acf-field-textarea.php');
227 acf_include('includes/fields/class-acf-field-number.php');
228 acf_include('includes/fields/class-acf-field-range.php');
229 acf_include('includes/fields/class-acf-field-email.php');
230 acf_include('includes/fields/class-acf-field-url.php');
231 acf_include('includes/fields/class-acf-field-password.php');
232 acf_include('includes/fields/class-acf-field-image.php');
233 acf_include('includes/fields/class-acf-field-file.php');
234 acf_include('includes/fields/class-acf-field-wysiwyg.php');
235 acf_include('includes/fields/class-acf-field-oembed.php');
236 acf_include('includes/fields/class-acf-field-select.php');
237 acf_include('includes/fields/class-acf-field-checkbox.php');
238 acf_include('includes/fields/class-acf-field-radio.php');
239 acf_include('includes/fields/class-acf-field-button-group.php');
240 acf_include('includes/fields/class-acf-field-true_false.php');
241 acf_include('includes/fields/class-acf-field-link.php');
242 acf_include('includes/fields/class-acf-field-post_object.php');
243 acf_include('includes/fields/class-acf-field-page_link.php');
244 acf_include('includes/fields/class-acf-field-relationship.php');
245 acf_include('includes/fields/class-acf-field-taxonomy.php');
246 acf_include('includes/fields/class-acf-field-user.php');
247 acf_include('includes/fields/class-acf-field-google-map.php');
248 acf_include('includes/fields/class-acf-field-date_picker.php');
249 acf_include('includes/fields/class-acf-field-date_time_picker.php');
250 acf_include('includes/fields/class-acf-field-time_picker.php');
251 acf_include('includes/fields/class-acf-field-color_picker.php');
252 acf_include('includes/fields/class-acf-field-message.php');
253 acf_include('includes/fields/class-acf-field-accordion.php');
254 acf_include('includes/fields/class-acf-field-tab.php');
255 acf_include('includes/fields/class-acf-field-group.php');
256
257 /**
258 * Fires after field types have been included.
259 *
260 * @date 28/09/13
261 * @since 5.0.0
262 *
263 * @param int $major_version The major version of ACF.
264 */
265 do_action( 'acf/include_field_types', ACF_MAJOR_VERSION );
266
267 // Include locations.
268 acf_include('includes/locations/class-acf-location-post-type.php');
269 acf_include('includes/locations/class-acf-location-post-template.php');
270 acf_include('includes/locations/class-acf-location-post-status.php');
271 acf_include('includes/locations/class-acf-location-post-format.php');
272 acf_include('includes/locations/class-acf-location-post-category.php');
273 acf_include('includes/locations/class-acf-location-post-taxonomy.php');
274 acf_include('includes/locations/class-acf-location-post.php');
275 acf_include('includes/locations/class-acf-location-page-template.php');
276 acf_include('includes/locations/class-acf-location-page-type.php');
277 acf_include('includes/locations/class-acf-location-page-parent.php');
278 acf_include('includes/locations/class-acf-location-page.php');
279 acf_include('includes/locations/class-acf-location-current-user.php');
280 acf_include('includes/locations/class-acf-location-current-user-role.php');
281 acf_include('includes/locations/class-acf-location-user-form.php');
282 acf_include('includes/locations/class-acf-location-user-role.php');
283 acf_include('includes/locations/class-acf-location-taxonomy.php');
284 acf_include('includes/locations/class-acf-location-attachment.php');
285 acf_include('includes/locations/class-acf-location-comment.php');
286 acf_include('includes/locations/class-acf-location-widget.php');
287 acf_include('includes/locations/class-acf-location-nav-menu.php');
288 acf_include('includes/locations/class-acf-location-nav-menu-item.php');
289
290 /**
291 * Fires after location types have been included.
292 *
293 * @date 28/09/13
294 * @since 5.0.0
295 *
296 * @param int $major_version The major version of ACF.
297 */
298 do_action( 'acf/include_location_rules', ACF_MAJOR_VERSION );
299
300 /**
301 * Fires during initialization. Used to add local fields.
302 *
303 * @date 28/09/13
304 * @since 5.0.0
305 *
306 * @param int $major_version The major version of ACF.
307 */
308 do_action( 'acf/include_fields', ACF_MAJOR_VERSION );
309
310 /**
311 * Fires after ACF is completely "initialized".
312 *
313 * @date 28/09/13
314 * @since 5.0.0
315 *
316 * @param int $major_version The major version of ACF.
317 */
318 do_action( 'acf/init', ACF_MAJOR_VERSION );
319 }
320
321 /**
322 * register_post_types
323 *
324 * Registers the ACF post types.
325 *
326 * @date 22/10/2015
327 * @since 5.3.2
328 *
329 * @param void
330 * @return void
331 */
332 function register_post_types() {
333
334 // Vars.
335 $cap = acf_get_setting('capability');
336
337 // Register the Field Group post type.
338 register_post_type('acf-field-group', array(
339 'labels' => array(
340 'name' => __( 'Field Groups', 'acf' ),
341 'singular_name' => __( 'Field Group', 'acf' ),
342 'add_new' => __( 'Add New' , 'acf' ),
343 'add_new_item' => __( 'Add New Field Group' , 'acf' ),
344 'edit_item' => __( 'Edit Field Group' , 'acf' ),
345 'new_item' => __( 'New Field Group' , 'acf' ),
346 'view_item' => __( 'View Field Group', 'acf' ),
347 'search_items' => __( 'Search Field Groups', 'acf' ),
348 'not_found' => __( 'No Field Groups found', 'acf' ),
349 'not_found_in_trash' => __( 'No Field Groups found in Trash', 'acf' ),
350 ),
351 'public' => false,
352 'hierarchical' => true,
353 'show_ui' => true,
354 'show_in_menu' => false,
355 '_builtin' => false,
356 'capability_type' => 'post',
357 'capabilities' => array(
358 'edit_post' => $cap,
359 'delete_post' => $cap,
360 'edit_posts' => $cap,
361 'delete_posts' => $cap,
362 ),
363 'supports' => array('title'),
364 'rewrite' => false,
365 'query_var' => false,
366 ));
367
368
369 // Register the Field post type.
370 register_post_type('acf-field', array(
371 'labels' => array(
372 'name' => __( 'Fields', 'acf' ),
373 'singular_name' => __( 'Field', 'acf' ),
374 'add_new' => __( 'Add New' , 'acf' ),
375 'add_new_item' => __( 'Add New Field' , 'acf' ),
376 'edit_item' => __( 'Edit Field' , 'acf' ),
377 'new_item' => __( 'New Field' , 'acf' ),
378 'view_item' => __( 'View Field', 'acf' ),
379 'search_items' => __( 'Search Fields', 'acf' ),
380 'not_found' => __( 'No Fields found', 'acf' ),
381 'not_found_in_trash' => __( 'No Fields found in Trash', 'acf' ),
382 ),
383 'public' => false,
384 'hierarchical' => true,
385 'show_ui' => false,
386 'show_in_menu' => false,
387 '_builtin' => false,
388 'capability_type' => 'post',
389 'capabilities' => array(
390 'edit_post' => $cap,
391 'delete_post' => $cap,
392 'edit_posts' => $cap,
393 'delete_posts' => $cap,
394 ),
395 'supports' => array('title'),
396 'rewrite' => false,
397 'query_var' => false,
398 ));
399 }
400
401 /**
402 * register_post_status
403 *
404 * Registers the ACF post statuses.
405 *
406 * @date 22/10/2015
407 * @since 5.3.2
408 *
409 * @param void
410 * @return void
411 */
412 function register_post_status() {
413
414 // Register the Disabled post status.
415 register_post_status('acf-disabled', array(
416 'label' => __( 'Inactive', 'acf' ),
417 'public' => true,
418 'exclude_from_search' => false,
419 'show_in_admin_all_list' => true,
420 'show_in_admin_status_list' => true,
421 'label_count' => _n_noop( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', 'acf' ),
422 ));
423 }
424
425 /**
426 * posts_where
427 *
428 * Filters the $where clause allowing for custom WP_Query args.
429 *
430 * @date 31/8/19
431 * @since 5.8.1
432 *
433 * @param string $where The WHERE clause.
434 * @return WP_Query $wp_query The query object.
435 */
436 function posts_where( $where, $wp_query ) {
437 global $wpdb;
438
439 // Add custom "acf_field_key" arg.
440 if( $field_key = $wp_query->get('acf_field_key') ) {
441 $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_name = %s", $field_key );
442 }
443
444 // Add custom "acf_field_name" arg.
445 if( $field_name = $wp_query->get('acf_field_name') ) {
446 $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_excerpt = %s", $field_name );
447 }
448
449 // Add custom "acf_group_key" arg.
450 if( $group_key = $wp_query->get('acf_group_key') ) {
451 $where .= $wpdb->prepare(" AND {$wpdb->posts}.post_name = %s", $group_key );
452 }
453
454 // Return.
455 return $where;
456 }
457
458 /**
459 * define
460 *
461 * Defines a constant if doesnt already exist.
462 *
463 * @date 3/5/17
464 * @since 5.5.13
465 *
466 * @param string $name The constant name.
467 * @param mixed $value The constant value.
468 * @return void
469 */
470 function define( $name, $value = true ) {
471 if( !defined($name) ) {
472 define( $name, $value );
473 }
474 }
475
476 /**
477 * has_setting
478 *
479 * Returns true if a setting exists for this name.
480 *
481 * @date 2/2/18
482 * @since 5.6.5
483 *
484 * @param string $name The setting name.
485 * @return boolean
486 */
487 function has_setting( $name ) {
488 return isset($this->settings[ $name ]);
489 }
490
491 /**
492 * get_setting
493 *
494 * Returns a setting or null if doesn't exist.
495 *
496 * @date 28/09/13
497 * @since 5.0.0
498 *
499 * @param string $name The setting name.
500 * @return mixed
501 */
502 function get_setting( $name ) {
503 return isset($this->settings[ $name ]) ? $this->settings[ $name ] : null;
504 }
505
506 /**
507 * update_setting
508 *
509 * Updates a setting for the given name and value.
510 *
511 * @date 28/09/13
512 * @since 5.0.0
513 *
514 * @param string $name The setting name.
515 * @param mixed $value The setting value.
516 * @return true
517 */
518 function update_setting( $name, $value ) {
519 $this->settings[ $name ] = $value;
520 return true;
521 }
522
523 /**
524 * get_data
525 *
526 * Returns data or null if doesn't exist.
527 *
528 * @date 28/09/13
529 * @since 5.0.0
530 *
531 * @param string $name The data name.
532 * @return mixed
533 */
534 function get_data( $name ) {
535 return isset($this->data[ $name ]) ? $this->data[ $name ] : null;
536 }
537
538 /**
539 * set_data
540 *
541 * Sets data for the given name and value.
542 *
543 * @date 28/09/13
544 * @since 5.0.0
545 *
546 * @param string $name The data name.
547 * @param mixed $value The data value.
548 * @return void
549 */
550 function set_data( $name, $value ) {
551 $this->data[ $name ] = $value;
552 }
553
554 /**
555 * get_instance
556 *
557 * Returns an instance or null if doesn't exist.
558 *
559 * @date 13/2/18
560 * @since 5.6.9
561 *
562 * @param string $class The instance class name.
563 * @return object
564 */
565 function get_instance( $class ) {
566 $name = strtolower($class);
567 return isset($this->instances[ $name ]) ? $this->instances[ $name ] : null;
568 }
569
570 /**
571 * new_instance
572 *
573 * Creates and stores an instance of the given class.
574 *
575 * @date 13/2/18
576 * @since 5.6.9
577 *
578 * @param string $class The instance class name.
579 * @return object
580 */
581 function new_instance( $class ) {
582 $instance = new $class();
583 $name = strtolower($class);
584 $this->instances[ $name ] = $instance;
585 return $instance;
586 }
587 }
588
589 /*
590 * acf
591 *
592 * The main function responsible for returning the one true acf Instance to functions everywhere.
593 * Use this function like you would a global variable, except without needing to declare the global.
594 *
595 * Example: <?php $acf = acf(); ?>
596 *
597 * @date 4/09/13
598 * @since 4.3.0
599 *
600 * @param void
601 * @return ACF
602 */
603 function acf() {
604 global $acf;
605
606 // Instantiate only once.
607 if( !isset($acf) ) {
608 $acf = new ACF();
609 $acf->initialize();
610 }
611 return $acf;
612 }
613
614 // Instantiate.
615 acf();
616
617 endif; // class_exists check
618