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