Changeset 56033 for trunk/src/wp-includes/functions.wp-scripts.php
- Timestamp:
- 06/26/2023 01:40:31 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.wp-scripts.php
r55732 r56033 158 158 * @since 2.1.0 159 159 * @since 4.3.0 A return value was added. 160 * @since 6.3.0 The $in_footer parameter of type boolean was overloaded to be an $args parameter of type array. 160 161 * 161 162 * @param string $handle Name of the script. Should be unique. … … 167 168 * number is automatically added equal to current installed WordPress version. 168 169 * If set to null, no version is added. 169 * @param bool $in_footer Optional. Whether to enqueue the script before `</body>` instead of in the `<head>`. 170 * Default 'false'. 170 * @param array|bool $args { 171 * Optional. An array of additional script loading strategies. Default empty array. 172 * Otherwise, it may be a boolean in which case it determines whether the script is printed in the footer. Default false. 173 * 174 * @type string $strategy Optional. If provided, may be either 'defer' or 'async'. 175 * @type bool $in_footer Optional. Whether to print the script in the footer. Default 'false'. 176 * } 171 177 * @return bool Whether the script has been registered. True on success, false on failure. 172 178 */ 173 function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { 179 function wp_register_script( $handle, $src, $deps = array(), $ver = false, $args = array() ) { 180 if ( ! is_array( $args ) ) { 181 $args = array( 182 'in_footer' => (bool) $args, 183 ); 184 } 174 185 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 175 186 … … 177 188 178 189 $registered = $wp_scripts->add( $handle, $src, $deps, $ver ); 179 if ( $in_footer) {190 if ( ! empty( $args['in_footer'] ) ) { 180 191 $wp_scripts->add_data( $handle, 'group', 1 ); 181 192 } 182 193 if ( ! empty( $args['strategy'] ) ) { 194 $wp_scripts->add_data( $handle, 'strategy', $args['strategy'] ); 195 } 183 196 return $registered; 184 197 } … … 332 345 * 333 346 * @since 2.1.0 347 * @since 6.3.0 The $in_footer parameter of type boolean was overloaded to be an $args parameter of type array. 334 348 * 335 349 * @param string $handle Name of the script. Should be unique. … … 341 355 * number is automatically added equal to current installed WordPress version. 342 356 * If set to null, no version is added. 343 * @param bool $in_footer Optional. Whether to enqueue the script before `</body>` instead of in the `<head>`. 344 * Default 'false'. 345 */ 346 function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $in_footer = false ) { 357 * @param array|bool $args { 358 * Optional. An array of additional script loading strategies. Default empty array. 359 * Otherwise, it may be a boolean in which case it determines whether the script is printed in the footer. Default false. 360 * 361 * @type string $strategy Optional. If provided, may be either 'defer' or 'async'. 362 * @type bool $in_footer Optional. Whether to print the script in the footer. Default 'false'. 363 * } 364 */ 365 function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $args = array() ) { 347 366 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); 348 367 349 368 $wp_scripts = wp_scripts(); 350 369 351 if ( $src || $in_footer) {370 if ( $src || ! empty( $args ) ) { 352 371 $_handle = explode( '?', $handle ); 372 if ( ! is_array( $args ) ) { 373 $args = array( 374 'in_footer' => (bool) $args, 375 ); 376 } 353 377 354 378 if ( $src ) { 355 379 $wp_scripts->add( $_handle[0], $src, $deps, $ver ); 356 380 } 357 358 if ( $in_footer ) { 381 if ( ! empty( $args['in_footer'] ) ) { 359 382 $wp_scripts->add_data( $_handle[0], 'group', 1 ); 383 } 384 if ( ! empty( $args['strategy'] ) ) { 385 $wp_scripts->add_data( $_handle[0], 'strategy', $args['strategy'] ); 360 386 } 361 387 }
Note: See TracChangeset
for help on using the changeset viewer.