wppaste
WordPress

register_core_block_style_handles()

Since
6.3.0
Source
wp-includes/blocks/index.php:29
Registers core block style handles.

Description

While register_block_style_handle() is typically used for that, the way it is implemented is inefficient for core block styles. Registering those style handles here avoids unnecessary logic and filesystem lookups in the other function.

Compatibility

WordPress
since 6.3.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.

Performance profile

How much work a call to register_core_block_style_handles() 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
26–65

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

Plugin surface
1 hook

Third-party callbacks on 'block_type_metadata' 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

  • transienttransientget_transient()called directly
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()one call below register_core_block_style_handles()
  • optionoption read or writeget_option()one call below register_core_block_style_handles()

Further down the call graph this can also reach serialize 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 · 3 distinct outcomes

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

WhenInstructionsCalls it makes
!$style_path26wp_normalize_path(), ->add()
$style_path41–44wp_normalize_path(), ->add(), ->add_data(), is_rtl()
$style_path && is_rtl() && $rtl_file65wp_normalize_path(), ->add(), ->add_data(), is_rtl(), ->add_data(), ->add_data(), ->add_data()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev20226–6519
8.520226–6519
8.420226–651912 fewer instructions than PHP 8.3
8.321429–7419
8.221429–7419
8.121429–7419
7.421429–7419

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 · 1

One hook fires while register_core_block_style_handles() runs, in this order:

  1. apply_filters( block_type_metadata )filterline 122 (+93 into the body)

    Filters the metadata provided for registering a block type.

Uses · 11

Source code

function register_core_block_style_handles() {	$wp_version = wp_get_wp_version(); 	if ( ! wp_should_load_separate_core_block_assets() ) {		return;	} 	$blocks_url   = includes_url( 'blocks/' );	$suffix       = wp_scripts_get_suffix();	$wp_styles    = wp_styles();	$style_fields = array(		'style'       => 'style',		'editorStyle' => 'editor',	); 	static $core_blocks_meta;	if ( ! $core_blocks_meta ) {		$core_blocks_meta = require BLOCKS_PATH . 'blocks-json.php';	} 	$files          = false;	$transient_name = 'wp_core_block_css_files'; 	/*	 * Ignore transient cache when the development mode is set to 'core'. Why? To avoid interfering with	 * the core developer's workflow.	 */	$can_use_cached = ! wp_is_development_mode( 'core' ); 	if ( $can_use_cached ) {		$cached_files = get_transient( $transient_name ); 		// Check the validity of cached values by checking against the current WordPress version.		if (			is_array( $cached_files )			&& isset( $cached_files['version'] )			&& $cached_files['version'] === $wp_version			&& isset( $cached_files['files'] )		) {			$files = $cached_files['files'];		}	} 	if ( ! $files ) {		$files = glob( wp_normalize_path( BLOCKS_PATH . '**/**.css' ) ); 		// Normalize BLOCKS_PATH prior to substitution for Windows environments.		$normalized_blocks_path = wp_normalize_path( BLOCKS_PATH ); 		$files = array_map(			static function ( $file ) use ( $normalized_blocks_path ) {				return str_replace( $normalized_blocks_path, '', $file );			},			$files		); 		// Save core block style paths in cache when not in development mode.		if ( $can_use_cached ) {			set_transient(				$transient_name,				array(					'version' => $wp_version,					'files'   => $files,				)			);		}	} 	$register_style = static function ( $name, $filename, $style_handle ) use ( $blocks_url, $suffix, $wp_styles, $files ) {		$style_path = "{$name}/{$filename}{$suffix}.css";		$path       = wp_normalize_path( BLOCKS_PATH . $style_path ); 		if ( ! in_array( $style_path, $files, true ) ) {			$wp_styles->add(				$style_handle,				false			);			return;		}

Changelog

Introduced in 6.3.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/index.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.