PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.9.0
Secure Custom Fields v6.9.0
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 week ago Datastore 1 month ago Meta 1 year ago abilities 1 week ago admin 1 week ago ajax 1 month ago api 1 week ago fields 1 week ago forms 1 week ago legacy 1 year ago locations 1 year ago post-types 2 months ago rest-api 1 week ago walkers 1 year ago acf-bidirectional-functions.php 1 year ago acf-field-functions.php 2 months 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 2 weeks 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 week 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 week ago blocks-auto-inline-editing.php 2 months ago blocks.php 2 weeks ago class-acf-data.php 10 months ago class-acf-internal-post-type.php 1 week 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 2 months 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 2 weeks ago validation.php 10 months ago wpml.php 1 year ago
assets.php
876 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 * Returns generated asset file data for a script.
101 *
102 * @since SCF 6.8.10
103 *
104 * @param string $asset_file The generated asset file path.
105 * @param string $version The fallback version.
106 * @return array
107 */
108 private function get_asset_file_data( $asset_file, $version ) {
109 $asset = file_exists( $asset_file ) ? require $asset_file : array();
110
111 return array(
112 'dependencies' => isset( $asset['dependencies'] ) ? $asset['dependencies'] : array(),
113 'version' => isset( $asset['version'] ) ? $asset['version'] : $version,
114 );
115 }
116
117 /**
118 * Registers a fallback for the React JSX runtime script handle.
119 *
120 * WordPress 6.6+ registers this handle in core. Older supported versions
121 * do not, but bundled WordPress packages may still depend on the global.
122 *
123 * @since SCF 6.8.10
124 *
125 * @param string $version The script version.
126 * @return void
127 */
128 private function register_react_jsx_runtime_polyfill( $version ) {
129 if ( wp_script_is( 'react-jsx-runtime', 'registered' ) ) {
130 return;
131 }
132
133 wp_register_script(
134 'react-jsx-runtime',
135 false,
136 array( 'wp-element' ),
137 $version,
138 true
139 );
140
141 wp_add_inline_script(
142 'react-jsx-runtime',
143 '(function(){if(window.ReactJSXRuntime||!window.wp||!window.wp.element){return;}var element=window.wp.element;function jsx(type,props,key){if(key!==undefined){var nextProps={};props=props||{};for(var prop in props){if(Object.prototype.hasOwnProperty.call(props,prop)){nextProps[prop]=props[prop];}}nextProps.key=key;props=nextProps;}return element.createElement(type,props);}window.ReactJSXRuntime={Fragment:element.Fragment,jsx:jsx,jsxs:jsx};})();'
144 );
145 }
146
147 /**
148 * Returns whether the legacy SCF block bindings editor script can run.
149 *
150 * The script depends on the stable WordPress block bindings JavaScript
151 * APIs, which are only available in WordPress 6.7+.
152 *
153 * @since SCF 6.8.10
154 *
155 * @return bool
156 */
157 private function supports_block_bindings_editor_script() {
158 global $wp_version;
159
160 return version_compare( $wp_version, '6.7', '>=' );
161 }
162
163 /**
164 * Registers the ACF scripts and styles.
165 *
166 * @date 10/4/18
167 * @since ACF 5.6.9
168 *
169 * @return void
170 */
171 public function register_scripts() {
172 // Extract vars.
173 $suffix = defined( 'SCF_DEVELOPMENT_MODE' ) && SCF_DEVELOPMENT_MODE ? '' : '.min';
174 $version = acf_get_setting( 'version' );
175
176 $this->register_react_jsx_runtime_polyfill( $version );
177
178 // Define path patterns.
179 $js_path_patterns = array(
180 'pro' => 'assets/build/js/pro/%s' . $suffix . '.js',
181 'base' => 'assets/build/js/%s' . $suffix . '.js',
182 );
183 $css_path_patterns = array(
184 'pro' => 'assets/build/css/pro/%s.css',
185 'base' => 'assets/build/css/%s' . $suffix . '.css',
186 );
187 $asset_path_patterns = array(
188 'pro' => 'assets/build/js/pro/%s.asset.php',
189 'base' => 'assets/build/js/%s.asset.php',
190 );
191
192 // Define script registrations.
193 $scripts = array(
194 'acf-pro-input' => array(
195 'handle' => 'acf-pro-input',
196 'src' => acf_get_url( sprintf( $js_path_patterns['pro'], 'acf-pro-input' ) ),
197 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['pro'], 'acf-pro-input' ) ),
198 'deps' => array( 'acf-input' ),
199 'version' => $version,
200 'in_footer' => true,
201 ),
202 'acf-pro-field-group' => array(
203 'handle' => 'acf-pro-field-group',
204 'src' => acf_get_url( sprintf( $js_path_patterns['pro'], 'acf-pro-field-group' ) ),
205 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['pro'], 'acf-pro-field-group' ) ),
206 'deps' => array( 'acf-field-group' ),
207 'version' => $version,
208 'in_footer' => true,
209 ),
210 'acf-pro-ui-options-page' => array(
211 'handle' => 'acf-pro-ui-options-page',
212 'src' => acf_get_url( sprintf( $js_path_patterns['pro'], 'acf-pro-ui-options-page' ) ),
213 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['pro'], 'acf-pro-ui-options-page' ) ),
214 'deps' => array( 'acf-input' ),
215 'version' => $version,
216 'in_footer' => true,
217 ),
218 'acf-datastore' => array(
219 'handle' => 'acf-datastore',
220 'src' => acf_get_url( sprintf( $js_path_patterns['pro'], 'acf-datastore' ) ),
221 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['pro'], 'acf-datastore' ) ),
222 'deps' => array( 'acf-input', 'wp-data' ),
223 'version' => $version,
224 'in_footer' => true,
225 ),
226 'acf-field-bindings' => array(
227 'handle' => 'acf-field-bindings',
228 'src' => acf_get_url( sprintf( $js_path_patterns['pro'], 'acf-field-bindings' ) ),
229 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['pro'], 'acf-field-bindings' ) ),
230 'deps' => array( 'acf-datastore', 'wp-blocks' ),
231 'version' => $version,
232 'in_footer' => true,
233 ),
234 'acf' => array(
235 'handle' => 'acf',
236 'src' => acf_get_url( sprintf( $js_path_patterns['base'], 'acf' ) ),
237 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['base'], 'acf' ) ),
238 'deps' => array( 'jquery' ),
239 'version' => $version,
240 'in_footer' => false,
241 ),
242 'acf-input' => array(
243 'handle' => 'acf-input',
244 'src' => acf_get_url( sprintf( $js_path_patterns['base'], 'acf-input' ) ),
245 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['base'], 'acf-input' ) ),
246 'deps' => array( 'jquery', 'jquery-ui-sortable', 'jquery-ui-resizable', 'acf', 'wp-a11y' ),
247 'version' => $version,
248 'in_footer' => false,
249 ),
250 'acf-field-group' => array(
251 'handle' => 'acf-field-group',
252 'src' => acf_get_url( sprintf( $js_path_patterns['base'], 'acf-field-group' ) ),
253 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['base'], 'acf-field-group' ) ),
254 'deps' => array( 'acf-input' ),
255 'version' => $version,
256 'in_footer' => false,
257 ),
258 'acf-internal-post-type' => array(
259 'handle' => 'acf-internal-post-type',
260 'src' => acf_get_url( sprintf( $js_path_patterns['base'], 'acf-internal-post-type' ) ),
261 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['base'], 'acf-internal-post-type' ) ),
262 'deps' => array( 'acf-input' ),
263 'version' => $version,
264 'in_footer' => false,
265 ),
266 'acf-escaped-html-notice' => array(
267 'handle' => 'acf-escaped-html-notice',
268 'src' => acf_get_url( sprintf( $js_path_patterns['base'], 'acf-escaped-html-notice' ) ),
269 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['base'], 'acf-escaped-html-notice' ) ),
270 'deps' => array( 'jquery' ),
271 'version' => $version,
272 'in_footer' => true,
273 ),
274 'scf-bindings' => array(
275 'handle' => 'scf-bindings',
276 'src' => acf_get_url( sprintf( $js_path_patterns['base'], 'scf-bindings' ) ),
277 'asset_file' => acf_get_path( sprintf( $asset_path_patterns['base'], 'scf-bindings' ) ),
278 'version' => $version,
279 'deps' => array(),
280 'in_footer' => true,
281 ),
282 );
283
284 // Define style registrations.
285 $styles = array(
286 'acf-pro-input' => array(
287 'handle' => 'acf-pro-input',
288 'src' => acf_get_url( sprintf( $css_path_patterns['pro'], 'acf-pro-input' ) ),
289 'deps' => array( 'acf-input' ),
290 'version' => $version,
291 ),
292 'acf-pro-field-group' => array(
293 'handle' => 'acf-pro-field-group',
294 'src' => acf_get_url( sprintf( $css_path_patterns['pro'], 'acf-pro-field-group' ) ),
295 'deps' => array( 'acf-input' ),
296 'version' => $version,
297 ),
298 'acf-global' => array(
299 'handle' => 'acf-global',
300 'src' => acf_get_url( sprintf( $css_path_patterns['base'], 'acf-global' ) ),
301 'deps' => array( 'dashicons' ),
302 'version' => $version,
303 ),
304 'acf-input' => array(
305 'handle' => 'acf-input',
306 'src' => acf_get_url( sprintf( $css_path_patterns['base'], 'acf-input' ) ),
307 'deps' => array( 'acf-global' ),
308 'version' => $version,
309 ),
310 'acf-field-group' => array(
311 'handle' => 'acf-field-group',
312 'src' => acf_get_url( sprintf( $css_path_patterns['base'], 'acf-field-group' ) ),
313 'deps' => array( 'acf-input' ),
314 'version' => $version,
315 ),
316 );
317
318 // Register scripts.
319 foreach ( $scripts as $script ) {
320 // Load asset file if it exists.
321 $asset = $this->get_asset_file_data( $script['asset_file'], $script['version'] );
322
323 // Merge dependencies if asset file exists.
324 $deps = array_values( array_unique( array_merge( $asset['dependencies'], $script['deps'] ) ) );
325 $ver = $asset['version'];
326
327 wp_register_script(
328 $script['handle'],
329 $script['src'],
330 $deps,
331 $ver,
332 $script['in_footer']
333 );
334 }
335
336 $admin_commands_asset_file = acf_get_path( 'assets/build/js/commands/scf-admin.asset.php' );
337 $admin_commands_asset = $this->get_asset_file_data( $admin_commands_asset_file, $version );
338 $admin_commands_deps = array_values(
339 array_unique(
340 array_merge(
341 $admin_commands_asset['dependencies'],
342 array( 'acf', 'wp-plugins', 'wp-element', 'wp-components', 'wp-data', 'wp-commands', 'wp-i18n', 'wp-dom-ready' )
343 )
344 )
345 );
346
347 wp_register_script(
348 'scf-commands-admin',
349 acf_get_url( 'assets/build/js/commands/scf-admin' . $suffix . '.js' ),
350 $admin_commands_deps,
351 $admin_commands_asset['version'],
352 array(
353 'in_footer' => true,
354 'strategy' => 'defer',
355 )
356 );
357
358 $custom_post_type_commands_asset_file = acf_get_path( 'assets/build/js/commands/scf-custom-post-types.asset.php' );
359 $custom_post_type_commands_asset = $this->get_asset_file_data( $custom_post_type_commands_asset_file, $version );
360 $custom_post_type_commands_deps = array_values(
361 array_unique(
362 array_merge(
363 $custom_post_type_commands_asset['dependencies'],
364 array( 'acf', 'wp-plugins', 'wp-element', 'wp-components', 'wp-data', 'wp-commands', 'wp-i18n', 'wp-dom-ready' )
365 )
366 )
367 );
368
369 wp_register_script(
370 'scf-commands-custom-post-types',
371 acf_get_url( 'assets/build/js/commands/scf-custom-post-types' . $suffix . '.js' ),
372 $custom_post_type_commands_deps,
373 $custom_post_type_commands_asset['version'],
374 array(
375 'in_footer' => true,
376 'strategy' => 'defer',
377 )
378 );
379
380 // Register styles.
381 foreach ( $styles as $style ) {
382 wp_register_style(
383 $style['handle'],
384 $style['src'],
385 $style['deps'],
386 $style['version']
387 );
388 }
389
390 /**
391 * Fires after core scripts and styles have been registered.
392 *
393 * @since ACF 5.6.9
394 *
395 * @param string $version The ACF version.
396 * @param string $suffix The potential ".min" filename suffix.
397 */
398 do_action( 'acf/register_scripts', $version, $suffix );
399 }
400
401 /**
402 * Enqueues a script and sets up actions for printing supplemental scripts.
403 *
404 * @date 27/4/20
405 * @since ACF 5.9.0
406 *
407 * @param string $name The script name.
408 * @return void
409 */
410 public function enqueue_script( $name ) {
411 wp_enqueue_script( $name );
412 $this->add_actions();
413 }
414
415 /**
416 * Enqueues a style.
417 *
418 * @date 27/4/20
419 * @since ACF 5.9.0
420 *
421 * @param string $name The style name.
422 * @return void
423 */
424 public function enqueue_style( $name ) {
425 wp_enqueue_style( $name );
426 }
427
428 /**
429 * Adds the actions needed to print supporting inline scripts.
430 *
431 * @date 27/4/20
432 * @since ACF 5.9.0
433 *
434 * @return void
435 */
436 private function add_actions() {
437
438 // Only run once.
439 if ( acf_has_done( 'ACF_Assets::add_actions' ) ) {
440 return;
441 }
442
443 // Add actions.
444 $this->add_action( 'admin_enqueue_scripts', 'enqueue_scripts', 20 );
445 $this->add_action( 'admin_print_scripts', 'print_scripts', 20 );
446 $this->add_action( 'admin_print_footer_scripts', 'print_footer_scripts', 20 );
447 }
448
449 /**
450 * Extends the add_action() function with two additional features:
451 * 1. Renames $action depending on the current page (customizer, login, front-end).
452 * 2. Alters the priority or calls the method directly if the action has already passed.
453 *
454 * @date 28/4/20
455 * @since ACF 5.9.0
456 *
457 * @param string $action The action name.
458 * @param string $method The method name.
459 * @param integer $priority See add_action().
460 * @param integer $accepted_args See add_action().
461 * @return void
462 */
463 public function add_action( $action, $method, $priority = 10, $accepted_args = 1 ) {
464
465 // Generate an array of action replacements.
466 $replacements = array(
467 'customizer' => array(
468 'admin_enqueue_scripts' => 'admin_enqueue_scripts',
469 'admin_print_scripts' => 'customize_controls_print_scripts',
470 'admin_head' => 'customize_controls_print_scripts',
471 'admin_footer' => 'customize_controls_print_footer_scripts',
472 'admin_print_footer_scripts' => 'customize_controls_print_footer_scripts',
473 ),
474 'login' => array(
475 'admin_enqueue_scripts' => 'login_enqueue_scripts',
476 'admin_print_scripts' => 'login_head',
477 'admin_head' => 'login_head',
478 'admin_footer' => 'login_footer',
479 'admin_print_footer_scripts' => 'login_footer',
480 ),
481 'wp' => array(
482 'admin_enqueue_scripts' => 'wp_enqueue_scripts',
483 'admin_print_scripts' => 'wp_print_scripts',
484 'admin_head' => 'wp_head',
485 'admin_footer' => 'wp_footer',
486 'admin_print_footer_scripts' => 'wp_print_footer_scripts',
487 ),
488 );
489
490 // Determine the current context.
491 if ( did_action( 'customize_controls_init' ) ) {
492 $context = 'customizer';
493 } elseif ( did_action( 'login_form_register' ) ) {
494 $context = 'login';
495 } elseif ( is_admin() ) {
496 $context = 'admin';
497 } else {
498 $context = 'wp';
499 }
500
501 // Replace action if possible.
502 if ( isset( $replacements[ $context ][ $action ] ) ) {
503 $action = $replacements[ $context ][ $action ];
504 }
505
506 // Check if action is currently being or has already been run.
507 if ( did_action( $action ) ) {
508 $doing = acf_doing_action( $action );
509 if ( $doing && $doing < $priority ) {
510 // Allow action to be added as per usual.
511 } else {
512 // Call method directly.
513 return call_user_func( array( $this, $method ) );
514 }
515 }
516
517 // Add action.
518 add_action( $action, array( $this, $method ), $priority, $accepted_args );
519 }
520
521 /**
522 * Generic controller for enqueuing scripts and styles.
523 *
524 * @date 28/4/20
525 * @since ACF 5.9.0
526 *
527 * @param array $args {
528 * @type bool $uploader Whether or not to enqueue uploader scripts.
529 * }
530 * @return void
531 */
532 public function enqueue( $args = array() ) {
533
534 // Apply defaults.
535 $args = wp_parse_args(
536 $args,
537 array(
538 'input' => true,
539 'uploader' => false,
540 )
541 );
542
543 // Set enqueue flags and add actions.
544 if ( $args['input'] ) {
545 $this->enqueue[] = 'input';
546 }
547 if ( $args['uploader'] ) {
548 $this->enqueue[] = 'uploader';
549 }
550 $this->add_actions();
551 }
552
553 /**
554 * Enqueues the scripts and styles needed for the WP media uploader.
555 *
556 * @date 27/10/2014
557 * @since ACF 5.0.9
558 *
559 * @return void
560 */
561 public function enqueue_uploader() {
562
563 // Only run once.
564 if ( acf_has_done( 'ACF_Assets::enqueue_uploader' ) ) {
565 return;
566 }
567
568 // Enqueue media assets.
569 if ( current_user_can( 'upload_files' ) ) {
570 wp_enqueue_media();
571 }
572
573 // Add actions.
574 $this->add_action( 'admin_footer', 'print_uploader_scripts', 1 );
575
576 /**
577 * Fires when enqueuing the uploader.
578 *
579 * @since ACF 5.6.9
580 */
581 do_action( 'acf/enqueue_uploader' );
582 }
583
584 /**
585 * Enqueues and localizes scripts.
586 *
587 * @since ACF 5.9.0
588 *
589 * @return void
590 */
591 public function enqueue_scripts() {
592 // Enqueue input scripts.
593 if ( in_array( 'input', $this->enqueue, true ) ) {
594 wp_enqueue_script( 'acf-input' );
595 wp_enqueue_style( 'acf-input' );
596 }
597
598 // Enqueue media scripts.
599 if ( in_array( 'uploader', $this->enqueue, true ) ) {
600 $this->enqueue_uploader();
601 }
602
603 // Localize text.
604 acf_localize_text(
605 array(
606 // Tooltip
607 'Are you sure?' => __( 'Are you sure?', 'secure-custom-fields' ),
608 'Yes' => __( 'Yes', 'secure-custom-fields' ),
609 'No' => __( 'No', 'secure-custom-fields' ),
610 'Remove' => __( 'Remove', 'secure-custom-fields' ),
611 'Cancel' => __( 'Cancel', 'secure-custom-fields' ),
612 'Close modal' => esc_html__( 'Close modal', 'secure-custom-fields' ),
613 )
614 );
615
616 // Localize "input" text.
617 if ( wp_script_is( 'acf-input' ) ) {
618 acf_localize_text(
619 array(
620 // Unload
621 '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' ),
622
623 // Metaboxes
624 'Toggle panel' => esc_html__( 'Toggle panel', 'secure-custom-fields' ),
625 // Validation
626 'Validation successful' => esc_html__( 'Validation successful', 'secure-custom-fields' ),
627 'Validation failed' => esc_html__( 'Validation failed', 'secure-custom-fields' ),
628 '1 field requires attention' => esc_html__( '1 field requires attention', 'secure-custom-fields' ),
629 /* translators: %d: number of fields */
630 '%d fields require attention' => esc_html__( '%d fields require attention', 'secure-custom-fields' ),
631
632 // Block Validation
633 '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' ),
634
635 // Other
636 'Edit field group' => esc_html__( 'Edit field group', 'secure-custom-fields' ),
637 )
638 );
639
640 // @todo integrate into the above. Previously, they were simply hooked into the hook below.
641 wp_enqueue_script( 'acf-pro-input' );
642 wp_enqueue_script( 'acf-pro-ui-options-page' );
643 if (
644 ! acf_is_using_datastore() &&
645 $this->supports_block_bindings_editor_script()
646 ) {
647 wp_enqueue_script( 'scf-bindings' );
648 }
649 wp_enqueue_style( 'acf-pro-input' );
650
651 /**
652 * Fires during "admin_enqueue_scripts" when ACF scripts are enqueued.
653 *
654 * @since ACF 5.6.9
655 */
656 do_action( 'acf/input/admin_enqueue_scripts' );
657 }
658
659 /**
660 * Fires during "admin_enqueue_scripts" when ACF scripts are enqueued.
661 *
662 * @since ACF 5.6.9
663 */
664 do_action( 'acf/admin_enqueue_scripts' );
665 do_action( 'acf/enqueue_scripts' );
666
667 // Filter i18n translations that differ from English and localize script.
668 $text = array();
669 foreach ( $this->text as $k => $v ) {
670 if ( str_replace( '.verb', '', $k ) !== $v ) {
671 $text[ $k ] = $v;
672 }
673 }
674
675 if ( $text ) {
676 wp_localize_script( 'acf', 'acfL10n', $text );
677 }
678 }
679
680 /**
681 * Prints scripts in head.
682 *
683 * @date 27/4/20
684 * @since ACF 5.9.0
685 *
686 * @return void
687 */
688 public function print_scripts() {
689 if ( wp_script_is( 'acf-input' ) ) {
690
691 /**
692 * Fires during "admin_head" when ACF scripts are enqueued.
693 *
694 * @since ACF 5.6.9
695 */
696 do_action( 'acf/input/admin_head' );
697 do_action( 'acf/input/admin_print_scripts' );
698 }
699
700 /**
701 * Fires during "admin_head" when ACF scripts are enqueued.
702 *
703 * @since ACF 5.6.9
704 */
705 do_action( 'acf/admin_head' );
706 do_action( 'acf/admin_print_scripts' );
707 }
708
709 /**
710 * Prints scripts in footer.
711 *
712 * @date 27/4/20
713 * @since ACF 5.9.0
714 *
715 * @return void
716 */
717 public function print_footer_scripts() {
718 global $wp_version;
719
720 // Bail early if 'acf' script was never enqueued (fixes Elementor enqueue reset conflict).
721 if ( ! wp_script_is( 'acf' ) ) {
722 return;
723 }
724
725 // Localize data.
726 $data_to_localize = array(
727 'admin_url' => admin_url(),
728 'ajaxurl' => admin_url( 'admin-ajax.php' ),
729 'nonce' => wp_create_nonce( 'acf_nonce' ),
730 'acf_version' => acf_get_setting( 'version' ),
731 'wp_version' => $wp_version,
732 'browser' => acf_get_browser(),
733 'locale' => acf_get_locale(),
734 'rtl' => is_rtl(),
735 'screen' => acf_get_form_data( 'screen' ),
736 'post_id' => acf_get_form_data( 'post_id' ),
737 'validation' => acf_get_form_data( 'validation' ),
738 'editor' => acf_is_block_editor() ? 'block' : 'classic',
739 'is_pro' => true,
740 'debug' => acf_is_beta() || ( defined( 'SCF_DEVELOPMENT_MODE' ) && SCF_DEVELOPMENT_MODE ),
741 'StrictMode' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && version_compare( $wp_version, '6.6', '>=' ),
742 );
743
744 acf_localize_data( $data_to_localize );
745
746 // Print inline script.
747 wp_print_inline_script_tag( 'acf.data = ' . wp_json_encode( $this->data ) . ';' );
748
749 if ( wp_script_is( 'acf-input' ) ) {
750
751 /**
752 * Filters an empty array for compat l10n data.
753 *
754 * @since ACF 5.0.0
755 *
756 * @param array $data An array of data to append to.
757 */
758 $compat_l10n = apply_filters( 'acf/input/admin_l10n', array() );
759 if ( $compat_l10n ) {
760 wp_print_inline_script_tag( 'acf.l10n = ' . wp_json_encode( $compat_l10n ) . ';' );
761 }
762
763 /**
764 * Fires during "admin_footer" when ACF scripts are enqueued.
765 *
766 * @since ACF 5.6.9
767 */
768 do_action( 'acf/input/admin_footer' );
769 do_action( 'acf/input/admin_print_footer_scripts' );
770 }
771
772 /**
773 * Fires during "admin_footer" when ACF scripts are enqueued.
774 *
775 * @since ACF 5.6.9
776 */
777 do_action( 'acf/admin_footer' );
778 do_action( 'acf/admin_print_footer_scripts' );
779
780 // Once all data is localized, trigger acf.prepare() to execute functionality before DOM ready.
781 wp_print_inline_script_tag( "acf.doAction( 'prepare' );" );
782 }
783
784 /**
785 * Prints uploader scripts in footer.
786 *
787 * @date 11/06/2020
788 * @since ACF 5.9.0
789 *
790 * @return void
791 */
792 public function print_uploader_scripts() {
793 // Todo: investigate output-buffer to hide HTML.
794 ?>
795 <div id="acf-hidden-wp-editor" style="display: none;">
796 <?php wp_editor( '', 'acf_content' ); ?>
797 </div>
798 <?php
799
800 /**
801 * Fires when printing uploader scripts.
802 *
803 * @since ACF 5.6.9
804 */
805 do_action( 'acf/admin_print_uploader_scripts' );
806 }
807 }
808
809 // instantiate
810 acf_new_instance( 'ACF_Assets' );
811 endif; // class_exists check
812
813 /**
814 * Appends an array of i18n data for localization.
815 *
816 * @date 13/4/18
817 * @since ACF 5.6.9
818 *
819 * @param array $text An array of text for i18n.
820 * @return void
821 */
822 function acf_localize_text( $text ) {
823 return acf_get_instance( 'ACF_Assets' )->add_text( $text );
824 }
825
826 /**
827 * Appends an array of l10n data for localization.
828 *
829 * @date 13/4/18
830 * @since ACF 5.6.9
831 *
832 * @param array $data An array of data for l10n.
833 * @return void
834 */
835 function acf_localize_data( $data ) {
836 return acf_get_instance( 'ACF_Assets' )->add_data( $data );
837 }
838
839 /**
840 * Enqueues a script with support for supplemental inline scripts.
841 *
842 * @date 27/4/20
843 * @since ACF 5.9.0
844 *
845 * @param string $name The script name.
846 * @return void
847 */
848 function acf_enqueue_script( $name ) {
849 return acf_get_instance( 'ACF_Assets' )->enqueue_script( $name );
850 }
851
852 /**
853 * Enqueues the input scripts required for fields.
854 *
855 * @date 13/4/18
856 * @since ACF 5.6.9
857 *
858 * @param array $args See ACF_Assets::enqueue_scripts() for a list of args.
859 * @return void
860 */
861 function acf_enqueue_scripts( $args = array() ) {
862 return acf_get_instance( 'ACF_Assets' )->enqueue( $args );
863 }
864
865 /**
866 * Enqueues the WP media uploader scripts and styles.
867 *
868 * @date 27/10/2014
869 * @since ACF 5.0.9
870 *
871 * @return void
872 */
873 function acf_enqueue_uploader() {
874 return acf_get_instance( 'ACF_Assets' )->enqueue_uploader();
875 }
876