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