wppaste
WordPress

_wp_scripts_add_args_data( WP_Scripts $wp_scripts, string $handle, array $args )

Since
7.0.0
Source
wp-includes/functions.wp-scripts.php:92
Adds the data for the recognized args and warns for unrecognized args.

Compatibility

WordPress
since 7.0.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 2 of the 5 tracked releases, added in 7.0.0, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$wp_scriptsWP_Scripts
WP_Scripts instance.
$handlestring
Script handle.
$argsarray
Array of extra args for the script.

Performance profile

How much work a call to _wp_scripts_add_args_data() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
23–130

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 130.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()one call below _wp_scripts_add_args_data()

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 18 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost _wp_scripts_add_args_data() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
empty($unknown_keys) && $value && empty($args)23array_keys(), array_diff()
empty($unknown_keys) && empty($args)28–36array_keys(), array_diff(), ->add_data()
empty($unknown_keys)35–43array_keys(), array_diff(), ->add_data(), ->add_data()
empty($unknown_keys) && !empty($args)42–50array_keys(), array_diff(), ->add_data(), ->add_data(), ->add_data()
empty($unknown_keys) && !$value && !empty($args)53–55array_keys(), array_diff(), ->add_data(), ->add_data(), ->add_data(), ->add_data()
!empty($unknown_keys) && $value && empty($args)59–62array_keys(), array_diff(), debug_backtrace(), __(), wp_get_list_item_separator(), wp_get_list_item_separator(), sprintf(), _doing_it_wrong()
!empty($unknown_keys) && empty($args)64–75array_keys(), array_diff(), debug_backtrace(), __(), wp_get_list_item_separator(), wp_get_list_item_separator(), sprintf(), _doing_it_wrong(), ->add_data()
empty($unknown_keys) && $value68–72array_keys(), array_diff(), ->add_data(), debug_backtrace(), __(), sprintf(), _doing_it_wrong()
!empty($unknown_keys)71–82array_keys(), array_diff(), debug_backtrace(), __(), wp_get_list_item_separator(), wp_get_list_item_separator(), sprintf(), _doing_it_wrong(), ->add_data(), ->add_data()
empty($unknown_keys) && $value73–79array_keys(), array_diff(), ->add_data(), ->add_data(), debug_backtrace(), __(), sprintf(), _doing_it_wrong()
!empty($unknown_keys) && !empty($args)78–89array_keys(), array_diff(), debug_backtrace(), __(), wp_get_list_item_separator(), wp_get_list_item_separator(), sprintf(), _doing_it_wrong(), ->add_data(), ->add_data(), ->add_data()
empty($unknown_keys) && $value && !empty($args)80–86array_keys(), array_diff(), ->add_data(), ->add_data(), ->add_data(), debug_backtrace(), __(), sprintf(), _doing_it_wrong()
6 further outcomes, up to 130 instructions
empty($unknown_keys) && !empty($args)87–91array_keys(), array_diff(), ->add_data(), ->add_data(), ->add_data(), ->add_data(), debug_backtrace(), __(), sprintf(), _doing_it_wrong()
!empty($unknown_keys) && !$value && !empty($args)89–94array_keys(), array_diff(), debug_backtrace(), __(), wp_get_list_item_separator(), wp_get_list_item_separator(), sprintf(), _doing_it_wrong(), ->add_data(), ->add_data(), ->add_data(), ->add_data()
!empty($unknown_keys) && $value104–111array_keys(), array_diff(), debug_backtrace(), __(), wp_get_list_item_separator(), wp_get_list_item_separator(), sprintf(), _doing_it_wrong(), ->add_data(), debug_backtrace(), __(), sprintf(), _doing_it_wrong()
!empty($unknown_keys) && $value109–118array_keys(), array_diff(), debug_backtrace(), __(), wp_get_list_item_separator(), wp_get_list_item_separator(), sprintf(), _doing_it_wrong(), ->add_data(), ->add_data(), debug_backtrace(), __(), sprintf(), _doing_it_wrong()
!empty($unknown_keys) && $value && !empty($args)116–125array_keys(), array_diff(), debug_backtrace(), __(), wp_get_list_item_separator(), wp_get_list_item_separator(), sprintf(), _doing_it_wrong(), ->add_data(), ->add_data(), ->add_data(), debug_backtrace(), __(), sprintf(), _doing_it_wrong()
!empty($unknown_keys) && !empty($args)123–130array_keys(), array_diff(), debug_backtrace(), __(), wp_get_list_item_separator(), wp_get_list_item_separator(), sprintf(), _doing_it_wrong(), ->add_data(), ->add_data(), ->add_data(), ->add_data(), debug_backtrace(), __(), sprintf(), _doing_it_wrong()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev13023–13014
8.513023–13014
8.413023–130146 fewer instructions than PHP 8.3
8.313623–13614
8.213623–13614
8.113623–13614
7.413623–13614

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 3

Used by · 2

Source code

function _wp_scripts_add_args_data( WP_Scripts $wp_scripts, string $handle, array $args ): void {	$allowed_keys = array( 'strategy', 'in_footer', 'fetchpriority', 'module_dependencies' );	$unknown_keys = array_diff( array_keys( $args ), $allowed_keys );	if ( ! empty( $unknown_keys ) ) {		$trace         = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 );		$function_name = ( $trace[1]['class'] ?? '' ) . ( $trace[1]['type'] ?? '' ) . ( $trace[1]['function'] ?? __FUNCTION__ );		_doing_it_wrong(			$function_name,			sprintf(				/* translators: 1: $args, 2: List of unrecognized keys, 3: List of supported keys. */				__( 'Unrecognized key(s) in the %1$s param: %2$s. Supported keys: %3$s' ),				'$args',				implode( wp_get_list_item_separator(), $unknown_keys ),				implode( wp_get_list_item_separator(), $allowed_keys )			),			'7.0.0'		);	} 	$in_footer = ! empty( $args['in_footer'] );	if ( $in_footer ) {		$wp_scripts->add_data( $handle, 'group', 1 );	}	if ( ! empty( $args['strategy'] ) ) {		$wp_scripts->add_data( $handle, 'strategy', $args['strategy'] );	}	if ( ! empty( $args['fetchpriority'] ) ) {		$wp_scripts->add_data( $handle, 'fetchpriority', $args['fetchpriority'] );	}	if ( ! empty( $args['module_dependencies'] ) ) {		$wp_scripts->add_data( $handle, 'module_dependencies', $args['module_dependencies'] ); 		/*		 * A classic script with module dependencies must either be printed in the		 * footer or use the 'defer' loading strategy. Otherwise, the script may be		 * evaluated before the script modules import map is printed, causing		 * dynamic imports to fail with a "Failed to resolve module specifier" error.		 */		$is_deferred = 'defer' === ( $args['strategy'] ?? null );		if ( ! $in_footer && ! $is_deferred ) {			$trace         = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 );			$function_name = ( $trace[1]['class'] ?? '' ) . ( $trace[1]['type'] ?? '' ) . ( $trace[1]['function'] ?? __FUNCTION__ );			_doing_it_wrong(				$function_name,				sprintf(					/* translators: 1: 'module_dependencies', 2: Script handle, 3: 'in_footer', 4: 'strategy', 5: 'defer'. */					__( 'When the %1$s arg is provided, the "%2$s" script must either be printed in the footer (%3$s set to true) or use a deferred loading %4$s (%5$s) so that the import map is printed before the script is evaluated.' ),					'<code>module_dependencies</code>',					$handle,					'<code>in_footer</code>',					'<code>strategy</code>',					'<code>defer</code>'				),				'7.0.0'			);		}	}}

Changelog

Introduced in 7.0.0. Unchanged from 7.0.4 through 7.1.0.

  1. 7.0.4
  2. 7.1.0

Signature, return type and hooks compared across 2 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/functions.wp-scripts.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.