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
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
- Scaling
- Constant
- Instructions
- 84–153
- Plugin surface
- 2 hooks
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 285.
Third-party callbacks on 'script_loader_src', 'script_loader_tag' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_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.
| When | Instructions | Calls 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 === null | 124–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 !== null | 127–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 === null | 130–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 !== null | 133–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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 285 | 84–153 | 45 | |
| 8.5 | 285 | 84–153 | 45 | |
| 8.4 | 285 | 84–153 | 45 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 294 | 87–159 | 45 | |
| 8.2 | 294 | 87–159 | 45 | |
| 8.1 | 294 | 87–159 | 45 | 6 fewer instructions than PHP 7.4 |
| 7.4 | 300 | 88–162 | 45 |
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:
- apply_filters( script_loader_src )filterline 374 (+94 into the body)
Filters the script loader source.
- apply_filters( script_loader_src )filterline 420 (+140 into the body)
Filters the script loader source.
- apply_filters( script_loader_tag )filterline 468 (+188 into the body)
Filters the HTML script tag of an enqueued script.
Uses · 19
- wp_get_inline_script_tag()Constructs an inline script tag.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- _print_scripts()Prints scripts (internal use only)
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- add_query_arg()Retrieves a modified URL query string.
- esc_url_raw()Sanitizes a URL for database or redirect usage.
- wp_get_script_tag()Formats `` loader tags.
- WP_Dependencies::do_item()Processes a dependency.
- WP_Scripts::get_eligible_loading_strategy()Gets the best eligible loading strategy for a script.
- WP_Scripts::get_data()
- WP_Scripts::is_delayed_strategy()Checks if the strategy passed is a valid delayed (non-blocking) strategy.
- WP_Scripts::are_all_dependents_in_footer()Checks whether all dependents of a given handle are in the footer.
Show all 19
- WP_Scripts::get_inline_script_tag()Gets tags for inline scripts registered for a specific handle.
- WP_Scripts::print_translations()Prints translations set for a specific handle.
- WP_Scripts::in_default_dir()Whether a handle's source is in a default directory.
- WP_Scripts::reset()Resets class properties.
- WP_Scripts::print_extra_script()Prints extra scripts of a registered script.
- WP_Scripts::is_valid_fetchpriority()Checks if the provided fetchpriority is valid.
- WP_Scripts::get_highest_fetchpriority_with_dependents()Gets the highest fetch priority for a given script and all of its dependent scripts.
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.
Signature, return type and hooks compared across 5 parsed releases.
$group parameter.from the docblockAbout 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.