Skip to content

Commit 2b3ddf8

Browse files
westonrutersirrealgemini-code-assist[bot]
committed
Script Loader: Remove $function_name argument from _wp_scripts_add_args_data().
Automatically determine the calling function name using debug_backtrace() for context in _doing_it_wrong() calls. Co-authored-by: Jon Surrell <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 12adf99 commit 2b3ddf8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/wp-includes/functions.wp-scripts.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ function _wp_scripts_maybe_doing_it_wrong( $function_name, $handle = '' ) {
7474
* @ignore
7575
* @since 7.0.0
7676
*
77-
* @param string $function_name Function name.
78-
* @param WP_Scripts $wp_scripts WP_Scripts instance.
79-
* @param string $handle Script handle.
80-
* @param array $args Array of extra args for the script.
77+
* @param WP_Scripts $wp_scripts WP_Scripts instance.
78+
* @param string $handle Script handle.
79+
* @param array $args Array of extra args for the script.
8180
*/
82-
function _wp_scripts_add_args_data( string $function_name, WP_Scripts $wp_scripts, string $handle, array $args ) {
81+
function _wp_scripts_add_args_data( WP_Scripts $wp_scripts, string $handle, array $args ) {
8382
$allowed_keys = array( 'strategy', 'in_footer', 'fetchpriority', 'module_dependencies' );
8483
$unknown_keys = array_diff( array_keys( $args ), $allowed_keys );
8584
if ( ! empty( $unknown_keys ) ) {
85+
$trace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 );
86+
$function_name = ( $trace[1]['class'] ?? '' ) . ( $trace[1]['type'] ?? '' ) . $trace[1]['function'];
8687
_doing_it_wrong(
8788
$function_name,
8889
sprintf(
@@ -233,7 +234,7 @@ function wp_register_script( $handle, $src, $deps = array(), $ver = false, $args
233234
$wp_scripts = wp_scripts();
234235

235236
$registered = $wp_scripts->add( $handle, $src, $deps, $ver );
236-
_wp_scripts_add_args_data( __FUNCTION__, $wp_scripts, $handle, $args );
237+
_wp_scripts_add_args_data( $wp_scripts, $handle, $args );
237238

238239
return $registered;
239240
}
@@ -420,7 +421,7 @@ function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $
420421
$wp_scripts->add( $_handle[0], $src, $deps, $ver );
421422
}
422423
if ( ! empty( $args ) ) {
423-
_wp_scripts_add_args_data( __FUNCTION__, $wp_scripts, $_handle[0], $args );
424+
_wp_scripts_add_args_data( $wp_scripts, $_handle[0], $args );
424425
}
425426
}
426427

0 commit comments

Comments
 (0)