register_core_block_style_handles()
- Since
- 6.3.0
- Source
wp-includes/blocks/index.php:29
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
- Scaling
- Constant
- Instructions
- 26–65
- Plugin surface
- 1 hook
- Called by
- 0
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 202.
Third-party callbacks on 'block_type_metadata' 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
- transienttransient
get_transient()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()one call below register_core_block_style_handles() - optionoption read or write
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
!$style_path | 26 | wp_normalize_path(), ->add() |
$style_path | 41–44 | wp_normalize_path(), ->add(), ->add_data(), is_rtl() |
$style_path && is_rtl() && $rtl_file | 65 | wp_normalize_path(), ->add(), ->add_data(), is_rtl(), ->add_data(), ->add_data(), ->add_data() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 202 | 26–65 | 19 | |
| 8.5 | 202 | 26–65 | 19 | |
| 8.4 | 202 | 26–65 | 19 | 12 fewer instructions than PHP 8.3 |
| 8.3 | 214 | 29–74 | 19 | |
| 8.2 | 214 | 29–74 | 19 | |
| 8.1 | 214 | 29–74 | 19 | |
| 7.4 | 214 | 29–74 | 19 |
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:
- apply_filters( block_type_metadata )filterline 122 (+93 into the body)
Filters the metadata provided for registering a block type.
Uses · 11
- wp_get_wp_version()Returns the current WordPress version.
- wp_should_load_separate_core_block_assets()Checks whether separate styles should be loaded for core blocks.
- includes_url()Retrieves the URL to the includes directory.
- wp_scripts_get_suffix()Returns the suffix that can be used for the scripts.
- wp_styles()Initializes $wp_styles if it has not been set.
- wp_is_development_mode()Checks whether the site is in the given development mode.
- get_transient()Retrieves the value of a transient.
- wp_normalize_path()Normalizes a filesystem path.
- set_transient()Sets/updates the value of a transient.
- is_rtl()Determines whether the current locale is right-to-left (RTL).
- apply_filters()Calls the callback functions that have been added to a filter hook.
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.
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.