diff --git a/wp-includes/class.wp-scripts.php b/wp-includes/class.wp-scripts.php
index f4277c8586..cc88455bc1 100644
|
a
|
b
|
class WP_Scripts extends WP_Dependencies { |
| 351 | 351 | echo $cond_after; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | | $async_attr = ''; |
| 355 | | $defer_attr = ''; |
| 356 | | |
| 357 | | if ( false === in_array( $handle, $this->in_footer ) ) { |
| 358 | | if( true === apply_filters( 'script_attr_async', $obj->extra['is_async'] ?? false ) ) { |
| 359 | | $async_attr = ' async'; |
| 360 | | } |
| 361 | | |
| 362 | | if( true === apply_filters( 'script_attr_defer', $obj->extra['is_defer'] ?? false ) ) { |
| 363 | | $defer_attr = ' defer'; |
| 364 | | } |
| 365 | | } |
| 366 | | |
| 367 | 354 | // A single item may alias a set of items, by having dependencies, but no source. |
| 368 | 355 | if ( ! $src ) { |
| 369 | 356 | if ( $inline_script_tag ) { |
| … |
… |
class WP_Scripts extends WP_Dependencies { |
| 398 | 385 | } |
| 399 | 386 | |
| 400 | 387 | $tag = $translations . $cond_before . $before_handle; |
| 401 | | $tag .= sprintf( "<script%s src='%s'%s%s></script>\n", $this->type_attr, $src, $async_attr, $defer_attr ); |
| | 388 | $tag .= sprintf( "<script%s src='%s'></script>\n", $this->type_attr, $src ); |
| 402 | 389 | $tag .= $after_handle . $cond_after; |
| 403 | 390 | |
| 404 | 391 | /** |
diff --git a/wp-includes/functions.wp-scripts.php b/wp-includes/functions.wp-scripts.php
index b900fa2b2a..3eefe4f903 100644
|
a
|
b
|
function wp_script_is( $handle, $list = 'enqueued' ) { |
| 389 | 389 | */ |
| 390 | 390 | function wp_script_add_data( $handle, $key, $value ) { |
| 391 | 391 | return wp_scripts()->add_data( $handle, $key, $value ); |
| 392 | | } |
| 393 | | |
| 394 | | /** |
| 395 | | * Add 'is_async' metadata to a script. |
| 396 | | * |
| 397 | | * @see WP_Dependencies::add_data() |
| 398 | | * |
| 399 | | * @param string|array $handles Names of the scripts. |
| 400 | | */ |
| 401 | | function wp_async_script($handles) { |
| 402 | | if('string' === gettype($handles)) { |
| 403 | | $handles = [$handles]; |
| 404 | | } |
| 405 | | |
| 406 | | if('array' !== gettype($handles)) { |
| 407 | | return; |
| 408 | | } |
| 409 | | |
| 410 | | foreach($handles as $handle ) { |
| 411 | | wp_scripts()->add_data( $handle, 'is_async', true ); |
| 412 | | } |
| 413 | | } |
| 414 | | |
| 415 | | /** |
| 416 | | * Add 'is_defer' metadata to a script. |
| 417 | | * |
| 418 | | * @see WP_Dependencies::add_data() |
| 419 | | * |
| 420 | | * @param string|array $handles Names of the scripts. |
| 421 | | */ |
| 422 | | function wp_defer_script($handles) { |
| 423 | | if('string' === gettype($handles)) { |
| 424 | | $handles = [$handles]; |
| 425 | | } |
| 426 | | |
| 427 | | if('array' !== gettype($handles)) { |
| 428 | | return; |
| 429 | | } |
| 430 | | |
| 431 | | foreach($handles as $handle ) { |
| 432 | | wp_scripts()->add_data( $handle, 'is_defer', true ); |
| 433 | | } |
| 434 | 392 | } |