wppaste
WordPress

get_block_asset_url( string $path ): string|false

Since
6.4.0
Source
wp-includes/blocks.php:97
Gets the URL to a block asset.

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

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

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

Instructions
4–73

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

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

What it touches

  • hookthird-party callbacksapply_filters()one call below get_block_asset_url()
  • optionoption read or writeget_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.

WhenInstructionsCalls it makes
empty($path)4none
!empty($path) && $path13includes_url()
!empty($path) && $path23realpath(), wp_normalize_path(), includes_url()
!empty($path) && isset($template_paths_norm[$template])27get_template(), trailingslashit(), get_theme_file_uri()
!empty($path) && !$path && isset($template_paths_norm[$template]) && !is_child_theme()31get_template(), trailingslashit(), is_child_theme(), basename(), plugins_url()
!empty($path) && isset($template_paths_norm[$template])37realpath(), wp_normalize_path(), get_template(), trailingslashit(), get_theme_file_uri()
!empty($path) && !isset($template_paths_norm[$template])37get_template(), get_template_directory(), realpath(), wp_normalize_path(), trailingslashit(), get_theme_file_uri()
!empty($path) && !$path && isset($template_paths_norm[$template]) && !is_child_theme()41realpath(), wp_normalize_path(), get_template(), trailingslashit(), is_child_theme(), basename(), plugins_url()
!empty($path) && !$path && !isset($template_paths_norm[$template]) && !is_child_theme()41get_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])42get_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])43get_template(), trailingslashit(), is_child_theme(), get_stylesheet(), trailingslashit(), basename(), plugins_url()
!empty($path) && !isset($template_paths_norm[$template])47realpath(), 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()51realpath(), 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])52realpath(), 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])52get_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])52get_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])53realpath(), 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])53get_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])53get_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])62realpath(), 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])62realpath(), 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])62get_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])63realpath(), 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])63realpath(), 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])63get_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])72realpath(), 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])73realpath(), 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

PHPCompiledExecutedBranchesNotes
8.6-dev944–738
8.5944–738
8.4944–73818 fewer instructions than PHP 8.3
8.31124–848
8.21124–848
8.11124–848
7.41124–848

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

Used by · 3

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.

  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.

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.