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