PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.8.5
Secure Custom Fields v6.8.5
6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / assets.php
secure-custom-fields / includes Last commit date
Blocks 1 month ago Datastore 1 month ago Meta 1 year ago abilities 6 months ago admin 1 month ago ajax 1 month ago api 1 month ago fields 1 month ago forms 1 month ago legacy 1 year ago locations 1 year ago post-types 1 month ago rest-api 2 months ago walkers 1 year ago acf-bidirectional-functions.php 1 year ago acf-field-functions.php 1 month ago acf-field-group-functions.php 7 months ago acf-form-functions.php 1 year ago acf-helper-functions.php 1 year ago acf-hook-functions.php 1 year ago acf-input-functions.php 7 months ago acf-internal-post-type-functions.php 7 months ago acf-meta-functions.php 1 year ago acf-post-functions.php 1 year ago acf-post-type-functions.php 1 year ago acf-taxonomy-functions.php 1 year ago acf-user-functions.php 1 year ago acf-utility-functions.php 1 year ago acf-value-functions.php 1 year ago acf-wp-functions.php 1 year ago assets.php 1 month ago blocks-auto-inline-editing.php 1 month ago blocks.php 1 month ago class-acf-data.php 10 months ago class-acf-internal-post-type.php 1 month ago class-acf-options-page.php 1 year ago class-acf-site-health.php 3 months ago class-scf-json-schema-validator.php 6 months ago class-scf-schema-builder.php 1 month ago compatibility.php 1 year ago datastore.php 1 month ago deprecated.php 1 year ago fields.php 10 months ago index.php 1 year ago l10n.php 1 year ago local-fields.php 1 year ago local-json.php 1 month ago local-meta.php 1 year ago locations.php 1 year ago loop.php 10 months ago media.php 1 year ago rest-api.php 10 months ago revisions.php 1 month ago scf-ui-options-page-functions.php 1 year ago third-party.php 7 months ago upgrades.php 1 year ago validation.php 10 months ago wpml.php 1 year ago
assets.php
785 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 if ( ! class_exists( 'ACF_Assets' ) ) :
8
9 class ACF_Assets {
10
11
12 /**
13 * Storage for i18n data.
14 *
15 * @since ACF 5.6.9
16 * @var array
17 */
18 public $text = array();
19
20 /**
21 * Storage for l10n data.
22 *
23 * @since ACF 5.6.9
24 * @var array
25 */
26 public $data = array();
27
28 /**
29 * List of enqueue flags.
30 *
31 * @since ACF 5.9.0
32 * @var boolean
33 */
34 private $enqueue = array();
35
36 /**
37 * Constructor.
38 *
39 * @date 10/4/18
40 * @since ACF 5.6.9
41 *
42 * @return void
43 */
44 public function __construct() {
45 add_action( 'init', array( $this, 'register_scripts' ) );
46 }
47
48 /**
49 * Magic __call method for backwards compatibility.
50 *
51 * @date 10/4/20
52 * @since ACF 5.9.0
53 *
54 * @param string $name The method name.
55 * @param array $arguments The array of arguments.
56 * @return mixed
57 */
58 public function __call( $name, $arguments ) {
59 switch ( $name ) {
60 case 'admin_enqueue_scripts':
61 case 'admin_print_scripts':
62 case 'admin_head':
63 case 'admin_footer':
64 case 'admin_print_footer_scripts':
65 _doing_it_wrong( __FUNCTION__, 'The ACF_Assets class should not be accessed directly.', '5.9.0' );
66 }
67 }
68
69 /**
70 * Appends an array of i18n data.
71 *
72 * @date 13/4/18
73 * @since ACF 5.6.9
74 *
75 * @param array $text An array of text for i18n.
76 * @return void
77 */
78 public function add_text( $text ) {
79 foreach ( (array) $text as $k => $v ) {
80 $this->text[ $k ] = $v;
81 }
82 }
83
84 /**
85 * Appends an array of l10n data.
86 *
87 * @date 13/4/18
88 * @since ACF 5.6.9
89 *
90 * @param array $data An array of data for l10n.
91 * @return void
92 */
93 public function add_data( $data ) {
94 foreach ( (array) $data as $k => $v ) {
95 $this->data[ $k ] = $v;
96 }
97 }
98
99 /**
100 * Registers the ACF scripts and styles.
101 *
102 * @date 10/4/18
103 * @since ACF 5.6.9
104 *
105 * @return void
106 */
107 public function register_scripts() {
108 // Extract vars.
109 $suffix = defined( 'SCF_DEVELOPMENT_MODE' ) && SCF_DEVELOPMENT_MODE ? '' : '.min';
110 $version = acf_get_setting( 'version' );
111
112 // Define path patterns.
113 $js_path_patterns = array(
114 'pro' => 'assets/build/js/pro/%s' . $suffix . '.js',
115 'base' => 'assets/build/js/%s' . $suffix . '.js',
116 );
117 $css_path_patterns = array(
118 'pro' => 'assets/build/css/pro/%s.css',
119 'base' => 'assets/build/css/%s' . $suffix . '.css',
120 );
121 $asset_path_patterns = array(
122 'pro' => 'assets/build/js/pro/%s.asset.php',
123 'base' => 'assets/build/js/%s.asset.php',
124 );
125
126 // Define script registrations.
127 $scripts = array(
128 'acf-pro-input' => array(
129 'handle' => 'acf-pro-input',
130 'src' => acf_get_url( sprintf( $js_path_patterns['pro'], 'acf-pro-input' ) ),
131 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['pro'], 'acf-pro-input' ) ),
132 'deps' => array( 'acf-input' ),
133 'version' => $version,
134 'in_footer' => true,
135 ),
136 'acf-pro-field-group' => array(
137 'handle' => 'acf-pro-field-group',
138 'src' => acf_get_url( sprintf( $js_path_patterns['pro'], 'acf-pro-field-group' ) ),
139 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['pro'], 'acf-pro-field-group' ) ),
140 'deps' => array( 'acf-field-group' ),
141 'version' => $version,
142 'in_footer' => true,
143 ),
144 'acf-pro-ui-options-page' => array(
145 'handle' => 'acf-pro-ui-options-page',
146 'src' => acf_get_url( sprintf( $js_path_patterns['pro'], 'acf-pro-ui-options-page' ) ),
147 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['pro'], 'acf-pro-ui-options-page' ) ),
148 'deps' => array( 'acf-input' ),
149 'version' => $version,
150 'in_footer' => true,
151 ),
152 'acf-datastore' => array(
153 'handle' => 'acf-datastore',
154 'src' => acf_get_url( sprintf( $js_path_patterns['pro'], 'acf-datastore' ) ),
155 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['pro'], 'acf-datastore' ) ),
156 'deps' => array( 'acf-input', 'wp-data' ),
157 'version' => $version,
158 'in_footer' => true,
159 ),
160 'acf-field-bindings' => array(
161 'handle' => 'acf-field-bindings',
162 'src' => acf_get_url( sprintf( $js_path_patterns['pro'], 'acf-field-bindings' ) ),
163 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['pro'], 'acf-field-bindings' ) ),
164 'deps' => array( 'acf-datastore', 'wp-blocks' ),
165 'version' => $version,
166 'in_footer' => true,
167 ),
168 'acf' => array(
169 'handle' => 'acf',
170 'src' => acf_get_url( sprintf( $js_path_patterns['base'], 'acf' ) ),
171 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['base'], 'acf' ) ),
172 'deps' => array( 'jquery' ),
173 'version' => $version,
174 'in_footer' => false,
175 ),
176 'acf-input' => array(
177 'handle' => 'acf-input',
178 'src' => acf_get_url( sprintf( $js_path_patterns['base'], 'acf-input' ) ),
179 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['base'], 'acf-input' ) ),
180 'deps' => array( 'jquery', 'jquery-ui-sortable', 'jquery-ui-resizable', 'acf', 'wp-a11y' ),
181 'version' => $version,
182 'in_footer' => false,
183 ),
184 'acf-field-group' => array(
185 'handle' => 'acf-field-group',
186 'src' => acf_get_url( sprintf( $js_path_patterns['base'], 'acf-field-group' ) ),
187 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['base'], 'acf-field-group' ) ),
188 'deps' => array( 'acf-input' ),
189 'version' => $version,
190 'in_footer' => false,
191 ),
192 'acf-internal-post-type' => array(
193 'handle' => 'acf-internal-post-type',
194 'src' => acf_get_url( sprintf( $js_path_patterns['base'], 'acf-internal-post-type' ) ),
195 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['base'], 'acf-internal-post-type' ) ),
196 'deps' => array( 'acf-input' ),
197 'version' => $version,
198 'in_footer' => false,
199 ),
200 'acf-escaped-html-notice' => array(
201 'handle' => 'acf-escaped-html-notice',
202 'src' => acf_get_url( sprintf( $js_path_patterns['base'], 'acf-escaped-html-notice' ) ),
203 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['base'], 'acf-escaped-html-notice' ) ),
204 'deps' => array( 'jquery' ),
205 'version' => $version,
206 'in_footer' => true,
207 ),
208 'scf-bindings' => array(
209 'handle' => 'scf-bindings',
210 'src' => acf_get_url( sprintf( $js_path_patterns['base'], 'scf-bindings' ) ),
211 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['base'], 'scf-bindings' ) ),
212 'version' => $version,
213 'deps' => array(),
214 'in_footer' => true,
215 ),
216 );
217
218 // Define style registrations.
219 $styles = array(
220 'acf-pro-input' => array(
221 'handle' => 'acf-pro-input',
222 'src' => acf_get_url( sprintf( $css_path_patterns['pro'], 'acf-pro-input' ) ),
223 'deps' => array( 'acf-input' ),
224 'version' => $version,
225 ),
226 'acf-pro-field-group' => array(
227 'handle' => 'acf-pro-field-group',
228 'src' => acf_get_url( sprintf( $css_path_patterns['pro'], 'acf-pro-field-group' ) ),
229 'deps' => array( 'acf-input' ),
230 'version' => $version,
231 ),
232 'acf-global' => array(
233 'handle' => 'acf-global',
234 'src' => acf_get_url( sprintf( $css_path_patterns['base'], 'acf-global' ) ),
235 'deps' => array( 'dashicons' ),
236 'version' => $version,
237 ),
238 'acf-input' => array(
239 'handle' => 'acf-input',
240 'src' => acf_get_url( sprintf( $css_path_patterns['base'], 'acf-input' ) ),
241 'deps' => array( 'acf-global' ),
242 'version' => $version,
243 ),
244 'acf-field-group' => array(
245 'handle' => 'acf-field-group',
246 'src' => acf_get_url( sprintf( $css_path_patterns['base'], 'acf-field-group' ) ),
247 'deps' => array( 'acf-input' ),
248 'version' => $version,
249 ),
250 );
251
252 // Register scripts.
253 foreach ( $scripts as $script ) {
254 // Load asset file if it exists.
255 $asset = file_exists( $script['asset_file'] ) ? require $script['asset_file'] : null;
256
257 // Merge dependencies if asset file exists.
258 $deps = $asset ? array_merge( $asset['dependencies'], $script['deps'] ) : $script['deps'];
259 $ver = $asset ? $asset['version'] : $script['version'];
260
261 wp_register_script(
262 $script['handle'],
263 $script['src'],
264 $deps,
265 $ver,
266 $script['in_footer']
267 );
268 }
269
270 wp_register_script(
271 'scf-commands-admin',
272 acf_get_url( 'assets/build/js/commands/scf-admin' . $suffix . '.js' ),
273 array( 'acf', 'wp-plugins', 'wp-element', 'wp-components', 'wp-data', 'wp-commands', 'wp-i18n', 'wp-dom-ready' ),
274 $version,
275 array(
276 'in_footer' => true,
277 'strategy' => 'defer',
278 )
279 );
280
281 wp_register_script(
282 'scf-commands-custom-post-types',
283 acf_get_url( 'assets/build/js/commands/scf-custom-post-types' . $suffix . '.js' ),
284 array( 'acf', 'wp-plugins', 'wp-element', 'wp-components', 'wp-data', 'wp-commands', 'wp-i18n', 'wp-dom-ready' ),
285 $version,
286 array(
287 'in_footer' => true,
288 'strategy' => 'defer',
289 )
290 );
291
292 // Register styles.
293 foreach ( $styles as $style ) {
294 wp_register_style(
295 $style['handle'],
296 $style['src'],
297 $style['deps'],
298 $style['version']
299 );
300 }
301
302 /**
303 * Fires after core scripts and styles have been registered.
304 *
305 * @since ACF 5.6.9
306 *
307 * @param string $version The ACF version.
308 * @param string $suffix The potential ".min" filename suffix.
309 */
310 do_action( 'acf/register_scripts', $version, $suffix );
311 }
312
313 /**
314 * Enqueues a script and sets up actions for printing supplemental scripts.
315 *
316 * @date 27/4/20
317 * @since ACF 5.9.0
318 *
319 * @param string $name The script name.
320 * @return void
321 */
322 public function enqueue_script( $name ) {
323 wp_enqueue_script( $name );
324 $this->add_actions();
325 }
326
327 /**
328 * Enqueues a style.
329 *
330 * @date 27/4/20
331 * @since ACF 5.9.0
332 *
333 * @param string $name The style name.
334 * @return void
335 */
336 public function enqueue_style( $name ) {
337 wp_enqueue_style( $name );
338 }
339
340 /**
341 * Adds the actions needed to print supporting inline scripts.
342 *
343 * @date 27/4/20
344 * @since ACF 5.9.0
345 *
346 * @return void
347 */
348 private function add_actions() {
349
350 // Only run once.
351 if ( acf_has_done( 'ACF_Assets::add_actions' ) ) {
352 return;
353 }
354
355 // Add actions.
356 $this->add_action( 'admin_enqueue_scripts', 'enqueue_scripts', 20 );
357 $this->add_action( 'admin_print_scripts', 'print_scripts', 20 );
358 $this->add_action( 'admin_print_footer_scripts', 'print_footer_scripts', 20 );
359 }
360
361 /**
362 * Extends the add_action() function with two additional features:
363 * 1. Renames $action depending on the current page (customizer, login, front-end).
364 * 2. Alters the priority or calls the method directly if the action has already passed.
365 *
366 * @date 28/4/20
367 * @since ACF 5.9.0
368 *
369 * @param string $action The action name.
370 * @param string $method The method name.
371 * @param integer $priority See add_action().
372 * @param integer $accepted_args See add_action().
373 * @return void
374 */
375 public function add_action( $action, $method, $priority = 10, $accepted_args = 1 ) {
376
377 // Generate an array of action replacements.
378 $replacements = array(
379 'customizer' => array(
380 'admin_enqueue_scripts' => 'admin_enqueue_scripts',
381 'admin_print_scripts' => 'customize_controls_print_scripts',
382 'admin_head' => 'customize_controls_print_scripts',
383 'admin_footer' => 'customize_controls_print_footer_scripts',
384 'admin_print_footer_scripts' => 'customize_controls_print_footer_scripts',
385 ),
386 'login' => array(
387 'admin_enqueue_scripts' => 'login_enqueue_scripts',
388 'admin_print_scripts' => 'login_head',
389 'admin_head' => 'login_head',
390 'admin_footer' => 'login_footer',
391 'admin_print_footer_scripts' => 'login_footer',
392 ),
393 'wp' => array(
394 'admin_enqueue_scripts' => 'wp_enqueue_scripts',
395 'admin_print_scripts' => 'wp_print_scripts',
396 'admin_head' => 'wp_head',
397 'admin_footer' => 'wp_footer',
398 'admin_print_footer_scripts' => 'wp_print_footer_scripts',
399 ),
400 );
401
402 // Determine the current context.
403 if ( did_action( 'customize_controls_init' ) ) {
404 $context = 'customizer';
405 } elseif ( did_action( 'login_form_register' ) ) {
406 $context = 'login';
407 } elseif ( is_admin() ) {
408 $context = 'admin';
409 } else {
410 $context = 'wp';
411 }
412
413 // Replace action if possible.
414 if ( isset( $replacements[ $context ][ $action ] ) ) {
415 $action = $replacements[ $context ][ $action ];
416 }
417
418 // Check if action is currently being or has already been run.
419 if ( did_action( $action ) ) {
420 $doing = acf_doing_action( $action );
421 if ( $doing && $doing < $priority ) {
422 // Allow action to be added as per usual.
423 } else {
424 // Call method directly.
425 return call_user_func( array( $this, $method ) );
426 }
427 }
428
429 // Add action.
430 add_action( $action, array( $this, $method ), $priority, $accepted_args );
431 }
432
433 /**
434 * Generic controller for enqueuing scripts and styles.
435 *
436 * @date 28/4/20
437 * @since ACF 5.9.0
438 *
439 * @param array $args {
440 * @type bool $uploader Whether or not to enqueue uploader scripts.
441 * }
442 * @return void
443 */
444 public function enqueue( $args = array() ) {
445
446 // Apply defaults.
447 $args = wp_parse_args(
448 $args,
449 array(
450 'input' => true,
451 'uploader' => false,
452 )
453 );
454
455 // Set enqueue flags and add actions.
456 if ( $args['input'] ) {
457 $this->enqueue[] = 'input';
458 }
459 if ( $args['uploader'] ) {
460 $this->enqueue[] = 'uploader';
461 }
462 $this->add_actions();
463 }
464
465 /**
466 * Enqueues the scripts and styles needed for the WP media uploader.
467 *
468 * @date 27/10/2014
469 * @since ACF 5.0.9
470 *
471 * @return void
472 */
473 public function enqueue_uploader() {
474
475 // Only run once.
476 if ( acf_has_done( 'ACF_Assets::enqueue_uploader' ) ) {
477 return;
478 }
479
480 // Enqueue media assets.
481 if ( current_user_can( 'upload_files' ) ) {
482 wp_enqueue_media();
483 }
484
485 // Add actions.
486 $this->add_action( 'admin_footer', 'print_uploader_scripts', 1 );
487
488 /**
489 * Fires when enqueuing the uploader.
490 *
491 * @since ACF 5.6.9
492 */
493 do_action( 'acf/enqueue_uploader' );
494 }
495
496 /**
497 * Enqueues and localizes scripts.
498 *
499 * @since ACF 5.9.0
500 *
501 * @return void
502 */
503 public function enqueue_scripts() {
504 // Enqueue input scripts.
505 if ( in_array( 'input', $this->enqueue, true ) ) {
506 wp_enqueue_script( 'acf-input' );
507 wp_enqueue_style( 'acf-input' );
508 }
509
510 // Enqueue media scripts.
511 if ( in_array( 'uploader', $this->enqueue, true ) ) {
512 $this->enqueue_uploader();
513 }
514
515 // Localize text.
516 acf_localize_text(
517 array(
518 // Tooltip
519 'Are you sure?' => __( 'Are you sure?', 'secure-custom-fields' ),
520 'Yes' => __( 'Yes', 'secure-custom-fields' ),
521 'No' => __( 'No', 'secure-custom-fields' ),
522 'Remove' => __( 'Remove', 'secure-custom-fields' ),
523 'Cancel' => __( 'Cancel', 'secure-custom-fields' ),
524 'Close modal' => esc_html__( 'Close modal', 'secure-custom-fields' ),
525 )
526 );
527
528 // Localize "input" text.
529 if ( wp_script_is( 'acf-input' ) ) {
530 acf_localize_text(
531 array(
532 // Unload
533 'The changes you made will be lost if you navigate away from this page' => esc_html__( 'The changes you made will be lost if you navigate away from this page', 'secure-custom-fields' ),
534
535 // Metaboxes
536 'Toggle panel' => esc_html__( 'Toggle panel', 'secure-custom-fields' ),
537 // Validation
538 'Validation successful' => esc_html__( 'Validation successful', 'secure-custom-fields' ),
539 'Validation failed' => esc_html__( 'Validation failed', 'secure-custom-fields' ),
540 '1 field requires attention' => esc_html__( '1 field requires attention', 'secure-custom-fields' ),
541 /* translators: %d: number of fields */
542 '%d fields require attention' => esc_html__( '%d fields require attention', 'secure-custom-fields' ),
543
544 // Block Validation
545 'An ACF Block on this page requires attention before you can save.' => esc_html__( 'An ACF Block on this page requires attention before you can save.', 'secure-custom-fields' ),
546
547 // Other
548 'Edit field group' => esc_html__( 'Edit field group', 'secure-custom-fields' ),
549 )
550 );
551
552 // @todo integrate into the above. Previously, they were simply hooked into the hook below.
553 wp_enqueue_script( 'acf-pro-input' );
554 wp_enqueue_script( 'acf-pro-ui-options-page' );
555 if ( ! acf_is_using_datastore() ) {
556 wp_enqueue_script( 'scf-bindings' );
557 }
558 wp_enqueue_style( 'acf-pro-input' );
559
560 /**
561 * Fires during "admin_enqueue_scripts" when ACF scripts are enqueued.
562 *
563 * @since ACF 5.6.9
564 */
565 do_action( 'acf/input/admin_enqueue_scripts' );
566 }
567
568 /**
569 * Fires during "admin_enqueue_scripts" when ACF scripts are enqueued.
570 *
571 * @since ACF 5.6.9
572 */
573 do_action( 'acf/admin_enqueue_scripts' );
574 do_action( 'acf/enqueue_scripts' );
575
576 // Filter i18n translations that differ from English and localize script.
577 $text = array();
578 foreach ( $this->text as $k => $v ) {
579 if ( str_replace( '.verb', '', $k ) !== $v ) {
580 $text[ $k ] = $v;
581 }
582 }
583
584 if ( $text ) {
585 wp_localize_script( 'acf', 'acfL10n', $text );
586 }
587 }
588
589 /**
590 * Prints scripts in head.
591 *
592 * @date 27/4/20
593 * @since ACF 5.9.0
594 *
595 * @return void
596 */
597 public function print_scripts() {
598 if ( wp_script_is( 'acf-input' ) ) {
599
600 /**
601 * Fires during "admin_head" when ACF scripts are enqueued.
602 *
603 * @since ACF 5.6.9
604 */
605 do_action( 'acf/input/admin_head' );
606 do_action( 'acf/input/admin_print_scripts' );
607 }
608
609 /**
610 * Fires during "admin_head" when ACF scripts are enqueued.
611 *
612 * @since ACF 5.6.9
613 */
614 do_action( 'acf/admin_head' );
615 do_action( 'acf/admin_print_scripts' );
616 }
617
618 /**
619 * Prints scripts in footer.
620 *
621 * @date 27/4/20
622 * @since ACF 5.9.0
623 *
624 * @return void
625 */
626 public function print_footer_scripts() {
627 global $wp_version;
628
629 // Bail early if 'acf' script was never enqueued (fixes Elementor enqueue reset conflict).
630 if ( ! wp_script_is( 'acf' ) ) {
631 return;
632 }
633
634 // Localize data.
635 $data_to_localize = array(
636 'admin_url' => admin_url(),
637 'ajaxurl' => admin_url( 'admin-ajax.php' ),
638 'nonce' => wp_create_nonce( 'acf_nonce' ),
639 'acf_version' => acf_get_setting( 'version' ),
640 'wp_version' => $wp_version,
641 'browser' => acf_get_browser(),
642 'locale' => acf_get_locale(),
643 'rtl' => is_rtl(),
644 'screen' => acf_get_form_data( 'screen' ),
645 'post_id' => acf_get_form_data( 'post_id' ),
646 'validation' => acf_get_form_data( 'validation' ),
647 'editor' => acf_is_block_editor() ? 'block' : 'classic',
648 'is_pro' => true,
649 'debug' => acf_is_beta() || ( defined( 'SCF_DEVELOPMENT_MODE' ) && SCF_DEVELOPMENT_MODE ),
650 'StrictMode' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && version_compare( $wp_version, '6.6', '>=' ),
651 );
652
653 acf_localize_data( $data_to_localize );
654
655 // Print inline script.
656 wp_print_inline_script_tag( 'acf.data = ' . wp_json_encode( $this->data ) . ';' );
657
658 if ( wp_script_is( 'acf-input' ) ) {
659
660 /**
661 * Filters an empty array for compat l10n data.
662 *
663 * @since ACF 5.0.0
664 *
665 * @param array $data An array of data to append to.
666 */
667 $compat_l10n = apply_filters( 'acf/input/admin_l10n', array() );
668 if ( $compat_l10n ) {
669 wp_print_inline_script_tag( 'acf.l10n = ' . wp_json_encode( $compat_l10n ) . ';' );
670 }
671
672 /**
673 * Fires during "admin_footer" when ACF scripts are enqueued.
674 *
675 * @since ACF 5.6.9
676 */
677 do_action( 'acf/input/admin_footer' );
678 do_action( 'acf/input/admin_print_footer_scripts' );
679 }
680
681 /**
682 * Fires during "admin_footer" when ACF scripts are enqueued.
683 *
684 * @since ACF 5.6.9
685 */
686 do_action( 'acf/admin_footer' );
687 do_action( 'acf/admin_print_footer_scripts' );
688
689 // Once all data is localized, trigger acf.prepare() to execute functionality before DOM ready.
690 wp_print_inline_script_tag( "acf.doAction( 'prepare' );" );
691 }
692
693 /**
694 * Prints uploader scripts in footer.
695 *
696 * @date 11/06/2020
697 * @since ACF 5.9.0
698 *
699 * @return void
700 */
701 public function print_uploader_scripts() {
702 // Todo: investigate output-buffer to hide HTML.
703 ?>
704 <div id="acf-hidden-wp-editor" style="display: none;">
705 <?php wp_editor( '', 'acf_content' ); ?>
706 </div>
707 <?php
708
709 /**
710 * Fires when printing uploader scripts.
711 *
712 * @since ACF 5.6.9
713 */
714 do_action( 'acf/admin_print_uploader_scripts' );
715 }
716 }
717
718 // instantiate
719 acf_new_instance( 'ACF_Assets' );
720 endif; // class_exists check
721
722 /**
723 * Appends an array of i18n data for localization.
724 *
725 * @date 13/4/18
726 * @since ACF 5.6.9
727 *
728 * @param array $text An array of text for i18n.
729 * @return void
730 */
731 function acf_localize_text( $text ) {
732 return acf_get_instance( 'ACF_Assets' )->add_text( $text );
733 }
734
735 /**
736 * Appends an array of l10n data for localization.
737 *
738 * @date 13/4/18
739 * @since ACF 5.6.9
740 *
741 * @param array $data An array of data for l10n.
742 * @return void
743 */
744 function acf_localize_data( $data ) {
745 return acf_get_instance( 'ACF_Assets' )->add_data( $data );
746 }
747
748 /**
749 * Enqueues a script with support for supplemental inline scripts.
750 *
751 * @date 27/4/20
752 * @since ACF 5.9.0
753 *
754 * @param string $name The script name.
755 * @return void
756 */
757 function acf_enqueue_script( $name ) {
758 return acf_get_instance( 'ACF_Assets' )->enqueue_script( $name );
759 }
760
761 /**
762 * Enqueues the input scripts required for fields.
763 *
764 * @date 13/4/18
765 * @since ACF 5.6.9
766 *
767 * @param array $args See ACF_Assets::enqueue_scripts() for a list of args.
768 * @return void
769 */
770 function acf_enqueue_scripts( $args = array() ) {
771 return acf_get_instance( 'ACF_Assets' )->enqueue( $args );
772 }
773
774 /**
775 * Enqueues the WP media uploader scripts and styles.
776 *
777 * @date 27/10/2014
778 * @since ACF 5.0.9
779 *
780 * @return void
781 */
782 function acf_enqueue_uploader() {
783 return acf_get_instance( 'ACF_Assets' )->enqueue_uploader();
784 }
785