diff --git a/src/wp-includes/class-wp-script-modules.php b/src/wp-includes/class-wp-script-modules.php
index 08d08a5d1a..fa705d1505 100644
|
a
|
b
|
class WP_Script_Modules { |
| 75 | 75 | * @param array $args { |
| 76 | 76 | * Optional. An array of additional args. Default empty array. |
| 77 | 77 | * |
| | 78 | * @type bool $in_footer Whether to print the script module in the footer. Default 'false'. Optional. |
| 78 | 79 | * @type 'auto'|'low'|'high' $fetchpriority Fetch priority. Default 'auto'. Optional. |
| 79 | 80 | * } |
| 80 | 81 | */ |
| … |
… |
class WP_Script_Modules { |
| 101 | 102 | } |
| 102 | 103 | } |
| 103 | 104 | |
| | 105 | $in_footer = false; |
| | 106 | if ( isset( $args['in_footer'] ) ) { |
| | 107 | $in_footer = (bool) $args['in_footer']; |
| | 108 | } |
| | 109 | |
| 104 | 110 | $fetchpriority = 'auto'; |
| 105 | 111 | if ( isset( $args['fetchpriority'] ) ) { |
| 106 | 112 | if ( $this->is_valid_fetchpriority( $args['fetchpriority'] ) ) { |
| … |
… |
class WP_Script_Modules { |
| 124 | 130 | 'version' => $version, |
| 125 | 131 | 'enqueue' => isset( $this->enqueued_before_registered[ $id ] ), |
| 126 | 132 | 'dependencies' => $dependencies, |
| | 133 | 'in_footer' => $in_footer, |
| 127 | 134 | 'fetchpriority' => $fetchpriority, |
| 128 | 135 | ); |
| 129 | 136 | } |
| … |
… |
class WP_Script_Modules { |
| 209 | 216 | * @param array $args { |
| 210 | 217 | * Optional. An array of additional args. Default empty array. |
| 211 | 218 | * |
| | 219 | * @type bool $in_footer Whether to print the script module in the footer. Default 'false'. Optional. |
| 212 | 220 | * @type 'auto'|'low'|'high' $fetchpriority Fetch priority. Default 'auto'. Optional. |
| 213 | 221 | * } |
| 214 | 222 | */ |
| … |
… |
class WP_Script_Modules { |
| 276 | 284 | } |
| 277 | 285 | |
| 278 | 286 | /** |
| 279 | | * Prints the enqueued script modules using script tags with type="module" |
| 280 | | * attributes. |
| | 287 | * Prints the enqueued script modules in head or footer. |
| | 288 | * |
| | 289 | * For classic themes, all script modules are printed in the footer. |
| | 290 | * For block themes, allows script modules to be printed in the head or footer. |
| 281 | 291 | * |
| 282 | 292 | * @since 6.5.0 |
| 283 | 293 | */ |
| 284 | 294 | public function print_enqueued_script_modules() { |
| 285 | | foreach ( $this->get_marked_for_enqueue() as $id => $script_module ) { |
| | 295 | $script_modules = $this->get_marked_for_enqueue(); |
| | 296 | |
| | 297 | // If we're in wp_footer, just print everything. |
| | 298 | if ( 'wp_footer' === current_action() ) { |
| | 299 | $this->print_script_modules( $script_modules ); |
| | 300 | } else { |
| | 301 | $head_modules = array(); |
| | 302 | $footer_modules = array(); |
| | 303 | |
| | 304 | foreach ( $script_modules as $id => $script_module ) { |
| | 305 | if ( isset( $script_module['in_footer'] ) && $script_module['in_footer'] ) { |
| | 306 | $footer_modules[ $id ] = $script_module; |
| | 307 | } else { |
| | 308 | $head_modules[ $id ] = $script_module; |
| | 309 | } |
| | 310 | } |
| | 311 | $this->print_script_modules( $head_modules ); |
| | 312 | |
| | 313 | // If there are footer modules, print them in the footer. |
| | 314 | if ( count( $footer_modules ) > 0 ) { |
| | 315 | add_action( |
| | 316 | 'wp_footer', |
| | 317 | function () use ( $footer_modules ) { |
| | 318 | $this->print_script_modules( $footer_modules ); |
| | 319 | } |
| | 320 | ); |
| | 321 | } |
| | 322 | } |
| | 323 | } |
| | 324 | |
| | 325 | /** |
| | 326 | * Prints the enqueued script modules using script tags with type="module" |
| | 327 | * attributes. |
| | 328 | * |
| | 329 | * @since 6.9.0 |
| | 330 | * |
| | 331 | * @param array $modules The script modules to print. |
| | 332 | */ |
| | 333 | private function print_script_modules( $modules ) { |
| | 334 | foreach ( $modules as $id => $script_module ) { |
| 286 | 335 | $args = array( |
| 287 | 336 | 'type' => 'module', |
| 288 | 337 | 'src' => $this->get_src( $id ), |
diff --git a/src/wp-includes/script-modules.php b/src/wp-includes/script-modules.php
index 0d284833be..97e80f3ec8 100644
|
a
|
b
|
function wp_script_modules(): WP_Script_Modules { |
| 64 | 64 | * @param array $args { |
| 65 | 65 | * Optional. An array of additional args. Default empty array. |
| 66 | 66 | * |
| | 67 | * @type bool $in_footer Whether to print the script module in the footer. Default 'false'. Optional. |
| 67 | 68 | * @type 'auto'|'low'|'high' $fetchpriority Fetch priority. Default 'auto'. Optional. |
| 68 | 69 | * } |
| 69 | 70 | */ |
| … |
… |
function wp_register_script_module( string $id, string $src, array $deps = array |
| 107 | 108 | * @param array $args { |
| 108 | 109 | * Optional. An array of additional args. Default empty array. |
| 109 | 110 | * |
| | 111 | * @type bool $in_footer Whether to print the script module in the footer. Default 'false'. Optional. |
| 110 | 112 | * @type 'auto'|'low'|'high' $fetchpriority Fetch priority. Default 'auto'. Optional. |
| 111 | 113 | * } |
| 112 | 114 | */ |