get_block_asset_url( string $path ): string|false
- Since
- 6.4.0
- Source
wp-includes/blocks.php:97
Compatibility
- WordPress
- since 6.4.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
$pathstring- A normalized path to a block asset.
Return value
string|false- The URL to the block asset or false on failure.
Performance profile
How much work a call to get_block_asset_url() 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
- Moderate
- Scaling
- Constant
- Instructions
- 4–73
- Plugin surface
- None
- Called by
- 3
Reads stored settings via get_option(), cached per request but not free on a cold cache.
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 94.
Nothing here hands control to plugin code.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below get_block_asset_url() - optionoption read or write
get_option()one call below get_block_asset_url()
Further down the call graph this can also reach cache, serialize, transient and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 27 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_block_asset_url() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($path) | 4 | none |
!empty($path) && $path | 13 | includes_url() |
!empty($path) && $path | 23 | realpath(), wp_normalize_path(), includes_url() |
!empty($path) && isset($template_paths_norm[$template]) | 27 | get_template(), trailingslashit(), get_theme_file_uri() |
!empty($path) && !$path && isset($template_paths_norm[$template]) && !is_child_theme() | 31 | get_template(), trailingslashit(), is_child_theme(), basename(), plugins_url() |
!empty($path) && isset($template_paths_norm[$template]) | 37 | realpath(), wp_normalize_path(), get_template(), trailingslashit(), get_theme_file_uri() |
!empty($path) && !isset($template_paths_norm[$template]) | 37 | get_template(), get_template_directory(), realpath(), wp_normalize_path(), trailingslashit(), get_theme_file_uri() |
!empty($path) && !$path && isset($template_paths_norm[$template]) && !is_child_theme() | 41 | realpath(), wp_normalize_path(), get_template(), trailingslashit(), is_child_theme(), basename(), plugins_url() |
!empty($path) && !$path && !isset($template_paths_norm[$template]) && !is_child_theme() | 41 | get_template(), get_template_directory(), realpath(), wp_normalize_path(), trailingslashit(), is_child_theme(), basename(), plugins_url() |
!empty($path) && isset($template_paths_norm[$template]) && is_child_theme() && isset($template_paths_norm[$stylesheet]) | 42 | get_template(), trailingslashit(), is_child_theme(), get_stylesheet(), trailingslashit(), get_theme_file_uri() |
!empty($path) && !$path && isset($template_paths_norm[$template]) && is_child_theme() && isset($template_paths_norm[$stylesheet]) | 43 | get_template(), trailingslashit(), is_child_theme(), get_stylesheet(), trailingslashit(), basename(), plugins_url() |
!empty($path) && !isset($template_paths_norm[$template]) | 47 | realpath(), wp_normalize_path(), get_template(), get_template_directory(), realpath(), wp_normalize_path(), trailingslashit(), get_theme_file_uri() |
15 further outcomes, up to 73 instructions
!empty($path) && !$path && !isset($template_paths_norm[$template]) && !is_child_theme() | 51 | realpath(), wp_normalize_path(), get_template(), get_template_directory(), realpath(), wp_normalize_path(), trailingslashit(), is_child_theme(), basename(), plugins_url() |
!empty($path) && isset($template_paths_norm[$template]) && is_child_theme() && isset($template_paths_norm[$stylesheet]) | 52 | realpath(), wp_normalize_path(), get_template(), trailingslashit(), is_child_theme(), get_stylesheet(), trailingslashit(), get_theme_file_uri() |
!empty($path) && isset($template_paths_norm[$template]) && is_child_theme() && !isset($template_paths_norm[$stylesheet]) | 52 | get_template(), trailingslashit(), is_child_theme(), get_stylesheet(), get_stylesheet_directory(), realpath(), wp_normalize_path(), trailingslashit(), get_theme_file_uri() |
!empty($path) && !isset($template_paths_norm[$template]) && is_child_theme() && isset($template_paths_norm[$stylesheet]) | 52 | get_template(), get_template_directory(), realpath(), wp_normalize_path(), trailingslashit(), is_child_theme(), get_stylesheet(), trailingslashit(), get_theme_file_uri() |
!empty($path) && !$path && isset($template_paths_norm[$template]) && is_child_theme() && isset($template_paths_norm[$stylesheet]) | 53 | realpath(), wp_normalize_path(), get_template(), trailingslashit(), is_child_theme(), get_stylesheet(), trailingslashit(), basename(), plugins_url() |
!empty($path) && !$path && isset($template_paths_norm[$template]) && is_child_theme() && !isset($template_paths_norm[$stylesheet]) | 53 | get_template(), trailingslashit(), is_child_theme(), get_stylesheet(), get_stylesheet_directory(), realpath(), wp_normalize_path(), trailingslashit(), basename(), plugins_url() |
!empty($path) && !$path && !isset($template_paths_norm[$template]) && is_child_theme() && isset($template_paths_norm[$stylesheet]) | 53 | get_template(), get_template_directory(), realpath(), wp_normalize_path(), trailingslashit(), is_child_theme(), get_stylesheet(), trailingslashit(), basename(), plugins_url() |
!empty($path) && isset($template_paths_norm[$template]) && is_child_theme() && !isset($template_paths_norm[$stylesheet]) | 62 | realpath(), wp_normalize_path(), get_template(), trailingslashit(), is_child_theme(), get_stylesheet(), get_stylesheet_directory(), realpath(), wp_normalize_path(), trailingslashit(), get_theme_file_uri() |
!empty($path) && !isset($template_paths_norm[$template]) && is_child_theme() && isset($template_paths_norm[$stylesheet]) | 62 | realpath(), wp_normalize_path(), get_template(), get_template_directory(), realpath(), wp_normalize_path(), trailingslashit(), is_child_theme(), get_stylesheet(), trailingslashit(), get_theme_file_uri() |
!empty($path) && !isset($template_paths_norm[$template]) && is_child_theme() && !isset($template_paths_norm[$stylesheet]) | 62 | get_template(), get_template_directory(), realpath(), wp_normalize_path(), trailingslashit(), is_child_theme(), get_stylesheet(), get_stylesheet_directory(), realpath(), wp_normalize_path(), trailingslashit(), get_theme_file_uri() |
!empty($path) && !$path && isset($template_paths_norm[$template]) && is_child_theme() && !isset($template_paths_norm[$stylesheet]) | 63 | realpath(), wp_normalize_path(), get_template(), trailingslashit(), is_child_theme(), get_stylesheet(), get_stylesheet_directory(), realpath(), wp_normalize_path(), trailingslashit(), basename(), plugins_url() |
!empty($path) && !$path && !isset($template_paths_norm[$template]) && is_child_theme() && isset($template_paths_norm[$stylesheet]) | 63 | realpath(), wp_normalize_path(), get_template(), get_template_directory(), realpath(), wp_normalize_path(), trailingslashit(), is_child_theme(), get_stylesheet(), trailingslashit(), basename(), plugins_url() |
!empty($path) && !$path && !isset($template_paths_norm[$template]) && is_child_theme() && !isset($template_paths_norm[$stylesheet]) | 63 | get_template(), get_template_directory(), realpath(), wp_normalize_path(), trailingslashit(), is_child_theme(), get_stylesheet(), get_stylesheet_directory(), realpath(), wp_normalize_path(), trailingslashit(), basename(), plugins_url() |
!empty($path) && !isset($template_paths_norm[$template]) && is_child_theme() && !isset($template_paths_norm[$stylesheet]) | 72 | realpath(), wp_normalize_path(), get_template(), get_template_directory(), realpath(), wp_normalize_path(), trailingslashit(), is_child_theme(), get_stylesheet(), get_stylesheet_directory(), realpath(), wp_normalize_path(), trailingslashit(), get_theme_file_uri() |
!empty($path) && !$path && !isset($template_paths_norm[$template]) && is_child_theme() && !isset($template_paths_norm[$stylesheet]) | 73 | realpath(), wp_normalize_path(), get_template(), get_template_directory(), realpath(), wp_normalize_path(), trailingslashit(), is_child_theme(), get_stylesheet(), get_stylesheet_directory(), realpath(), wp_normalize_path(), trailingslashit(), basename(), plugins_url() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 94 | 4–73 | 8 | |
| 8.5 | 94 | 4–73 | 8 | |
| 8.4 | 94 | 4–73 | 8 | 18 fewer instructions than PHP 8.3 |
| 8.3 | 112 | 4–84 | 8 | |
| 8.2 | 112 | 4–84 | 8 | |
| 8.1 | 112 | 4–84 | 8 | |
| 7.4 | 112 | 4–84 | 8 |
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 · 11
- wp_normalize_path()Normalizes a filesystem path.
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- includes_url()Retrieves the URL to the includes directory.
- get_template()Retrieves name of the active theme.
- get_template_directory()Retrieves template directory path for the active theme.
- trailingslashit()Appends a trailing slash.
- get_theme_file_uri()Retrieves the URL of a file in the theme.
- is_child_theme()Whether a child theme is in use.
- get_stylesheet()Retrieves name of the current stylesheet.
- get_stylesheet_directory()Retrieves stylesheet directory path for the active theme.
- plugins_url()Retrieves a URL within the plugins or mu-plugins directory.
Used by · 3
- register_block_script_handle()Finds a script handle for the selected block metadata field.
- register_block_script_module_id()Finds a script module ID for the selected block metadata field.
- register_block_style_handle()Finds a style handle for the block metadata field.
Source code
function get_block_asset_url( $path ) { if ( empty( $path ) ) { return false; } // Path needs to be normalized to work in Windows env. static $wpinc_path_norm = ''; if ( ! $wpinc_path_norm ) { $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) ); } if ( str_starts_with( $path, $wpinc_path_norm ) ) { return includes_url( str_replace( $wpinc_path_norm, '', $path ) ); } /** @var array<string, string> $template_paths_norm */ static $template_paths_norm = array(); $template = get_template(); if ( ! isset( $template_paths_norm[ $template ] ) ) { $template_paths_norm[ $template ] = wp_normalize_path( realpath( get_template_directory() ) ); } if ( str_starts_with( $path, trailingslashit( $template_paths_norm[ $template ] ) ) ) { return get_theme_file_uri( str_replace( $template_paths_norm[ $template ], '', $path ) ); } if ( is_child_theme() ) { $stylesheet = get_stylesheet(); if ( ! isset( $template_paths_norm[ $stylesheet ] ) ) { $template_paths_norm[ $stylesheet ] = wp_normalize_path( realpath( get_stylesheet_directory() ) ); } if ( str_starts_with( $path, trailingslashit( $template_paths_norm[ $stylesheet ] ) ) ) { return get_theme_file_uri( str_replace( $template_paths_norm[ $stylesheet ], '', $path ) ); } } return plugins_url( basename( $path ), $path );}Changelog
Introduced in 6.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/blocks.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.