wppaste
WordPress

WP_Scripts::do_item( string $handle, int|false $group = false ): bool

Since
2.6.0, 2.8.0
Source
wp-includes/class-wp-scripts.php:280
Processes a script dependency.

Compatibility

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

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$handlestring
The script's registered handle.
$groupint|falseoptional
Group level: level (int), no groups (false).
Default false.Default: false

Return value

bool
True on success, false on failure.

Performance profile

How much work a call to WP_Scripts::do_item() 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
84–153

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

Plugin surface
2 hooks

Third-party callbacks on 'script_loader_src', 'script_loader_tag' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()called directly

Further down the call graph this can also reach option, cache, serialize, query 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 · 6 distinct outcomes

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

WhenInstructionsCalls it makes
::do_item() && $group !== 0 && $group !== false && !isset($handle) && ->is_delayed_strategy() && empty($ver)84–89::do_item(), ->get_eligible_loading_strategy(), ->get_data(), ->is_delayed_strategy(), ->get_inline_script_tag(), ->get_inline_script_tag(), ->print_translations(), ->print_extra_script(), apply_filters(), esc_url_raw()
::do_item() && $group !== 0 && $group !== false && !isset($handle) && ->is_delayed_strategy() && !empty($ver)90–95::do_item(), ->get_eligible_loading_strategy(), ->get_data(), ->is_delayed_strategy(), ->get_inline_script_tag(), ->get_inline_script_tag(), ->print_translations(), ->print_extra_script(), add_query_arg(), apply_filters(), esc_url_raw()
::do_item() && $group !== 0 && $group !== false && !isset($handle) && ->is_delayed_strategy() && empty($ver) && $original_fetchpriority === null124–146::do_item(), ->get_eligible_loading_strategy(), ->get_data(), ->is_delayed_strategy(), ->get_inline_script_tag(), ->get_inline_script_tag(), ->print_translations(), ->print_extra_script(), apply_filters(), esc_url_raw(), ->get_highest_fetchpriority_with_dependents(), wp_get_script_tag(), apply_filters()
::do_item() && $group !== 0 && $group !== false && !isset($handle) && ->is_delayed_strategy() && empty($ver) && $original_fetchpriority !== null127–148::do_item(), ->get_eligible_loading_strategy(), ->get_data(), ->is_delayed_strategy(), ->get_inline_script_tag(), ->get_inline_script_tag(), ->print_translations(), ->print_extra_script(), apply_filters(), esc_url_raw(), ->is_valid_fetchpriority(), ->get_highest_fetchpriority_with_dependents(), wp_get_script_tag(), apply_filters()
::do_item() && $group !== 0 && $group !== false && !isset($handle) && ->is_delayed_strategy() && !empty($ver) && $original_fetchpriority === null130–149::do_item(), ->get_eligible_loading_strategy(), ->get_data(), ->is_delayed_strategy(), ->get_inline_script_tag(), ->get_inline_script_tag(), ->print_translations(), ->print_extra_script(), add_query_arg(), apply_filters(), esc_url_raw(), ->get_highest_fetchpriority_with_dependents(), wp_get_script_tag(), apply_filters()
::do_item() && $group !== 0 && $group !== false && !isset($handle) && ->is_delayed_strategy() && !empty($ver) && $original_fetchpriority !== null133–153::do_item(), ->get_eligible_loading_strategy(), ->get_data(), ->is_delayed_strategy(), ->get_inline_script_tag(), ->get_inline_script_tag(), ->print_translations(), ->print_extra_script(), add_query_arg(), apply_filters(), esc_url_raw(), ->is_valid_fetchpriority(), ->get_highest_fetchpriority_with_dependents(), wp_get_script_tag(), apply_filters()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev28584–15345
8.528584–15345
8.428584–153459 fewer instructions than PHP 8.3
8.329487–15945
8.229487–15945
8.129487–159456 fewer instructions than PHP 7.4
7.430088–16245

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.

Hooks and filters fired · 3

3 hooks fire while WP_Scripts::do_item() runs, in this order:

  1. apply_filters( script_loader_src )filterline 374 (+94 into the body)

    Filters the script loader source.

  2. apply_filters( script_loader_src )filterline 420 (+140 into the body)

    Filters the script loader source.

  3. apply_filters( script_loader_tag )filterline 468 (+188 into the body)

    Filters the HTML script tag of an enqueued script.

Uses · 19

Show all 19

Source code

	public function do_item( $handle, $group = false ) {		if ( ! parent::do_item( $handle ) ) {			return false;		} 		if ( 0 === $group && $this->groups[ $handle ] > 0 ) {			$this->in_footer[] = $handle;			return false;		} 		if ( false === $group && in_array( $handle, $this->in_footer, true ) ) {			$this->in_footer = array_diff( $this->in_footer, (array) $handle );		} 		$obj = $this->registered[ $handle ];		if ( $obj->extra['conditional'] ?? false ) {			return false;		} 		if ( null === $obj->ver ) {			$ver = '';		} else {			$ver = $obj->ver ? $obj->ver : $this->default_version;		} 		if ( isset( $this->args[ $handle ] ) ) {			$ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ];		} 		$src               = $obj->src;		$strategy          = $this->get_eligible_loading_strategy( $handle );		$intended_strategy = (string) $this->get_data( $handle, 'strategy' ); 		if ( ! $this->is_delayed_strategy( $intended_strategy ) ) {			$intended_strategy = '';		} 		/*		 * Move this script to the footer if:		 * 1. The script is in the header group.		 * 2. The current output is the header.		 * 3. The intended strategy is delayed.		 * 4. The actual strategy is not delayed.		 * 5. All dependent scripts are in the footer.		 */		if (			0 === $group &&			0 === $this->groups[ $handle ] &&			$intended_strategy &&			! $this->is_delayed_strategy( $strategy ) &&			$this->are_all_dependents_in_footer( $handle )		) {			$this->in_footer[] = $handle;			return false;		} 		$before_script = $this->get_inline_script_tag( $handle, 'before' );		$after_script  = $this->get_inline_script_tag( $handle, 'after' ); 		if ( $before_script || $after_script ) {			$inline_script_tag = $before_script . $after_script;		} else {			$inline_script_tag = '';		} 		/*		 * Prevent concatenation of scripts if the text domain is defined		 * to ensure the dependency order is respected.		 */		$translations_stop_concat = ! empty( $obj->textdomain ); 		$translations = $this->print_translations( $handle, false );		if ( $translations ) {			/*			 * The sourceURL comment is not included by WP_Scripts::print_translations()			 * when `$display` is `false` to prevent issues where the script tag contents are used			 * by extenders for other purposes, for example concatenated with other script content.			 *			 * Include the sourceURL comment here as it would be when printed directly.			 */

Changelog

Introduced in 2.6.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

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

2.8.0
Added the $group parameter.from the docblock
2.6.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/class-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.