wp_enqueue_registered_block_scripts_and_styles()
- Since
- 5.0.0
- Source
wp-includes/script-loader.php:2773
Compatibility
- WordPress
- since 5.0.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 wp_enqueue_registered_block_scripts_and_styles() 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
- Light
- Scaling
- Scales with input
- Instructions
- 7–23
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 74.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below wp_enqueue_registered_block_scripts_and_styles()
Further down the call graph this can also reach option, 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 · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_enqueue_registered_block_scripts_and_styles() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
wp_should_load_block_assets_on_demand() && wp_is_block_theme() | 7 | wp_should_load_block_assets_on_demand(), wp_is_block_theme() |
wp_should_load_block_assets_on_demand() && !wp_is_block_theme() && !has_action() | 12 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), has_action() |
!wp_should_load_block_assets_on_demand() && !is_admin() | 15–16 | wp_should_load_block_assets_on_demand(), is_admin(), ::WP_Block_Type_Registry(), ->get_all_registered() |
!wp_should_load_block_assets_on_demand() && is_admin() | 18–19 | wp_should_load_block_assets_on_demand(), is_admin(), wp_should_load_block_editor_scripts_and_styles(), ::WP_Block_Type_Registry(), ->get_all_registered() |
wp_should_load_block_assets_on_demand() && !wp_is_block_theme() && has_action() | 23 | wp_should_load_block_assets_on_demand(), wp_is_block_theme(), has_action(), wp_register_style(), wp_add_inline_style(), wp_enqueue_style() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 74 instructions, 7–23 executed per call, 15 branches. The work does not change between versions.
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 · 10
- wp_should_load_block_assets_on_demand()Checks whether block styles should be loaded only on-render.
- wp_is_block_theme()Returns whether the active theme is a block-based theme or not.
- has_action()Checks if any action has been registered for a hook.
- wp_register_style()Registers a CSS stylesheet.
- wp_add_inline_style()Adds extra CSS styles to a registered stylesheet.
- wp_enqueue_style()Enqueues a CSS stylesheet.
- is_admin()Determines whether the current request is for an administrative interface page.
- wp_should_load_block_editor_scripts_and_styles()Checks if the editor scripts and styles for all registered block types should be enqueued on the current screen.
- wp_enqueue_script()Enqueues a script.
- WP_Block_Type_Registry::get_instance()Utility method to retrieve the main instance of the class.
Source code
function wp_enqueue_registered_block_scripts_and_styles() { if ( wp_should_load_block_assets_on_demand() ) { /** * Add placeholder for where block styles would historically get enqueued in a classic theme when block assets * are not loaded on demand. This happens right after {@see wp_common_block_scripts_and_styles()} is called * at which time wp-block-library is enqueued. */ if ( ! wp_is_block_theme() && has_action( 'wp_template_enhancement_output_buffer_started', 'wp_hoist_late_printed_styles' ) ) { wp_register_style( 'wp-block-styles-placeholder', false ); wp_add_inline_style( 'wp-block-styles-placeholder', ':root { --wp-internal-comment: "Placeholder for wp_hoist_late_printed_styles() to replace with the block styles printed at wp_footer." }' ); wp_enqueue_style( 'wp-block-styles-placeholder' ); } return; } $load_editor_scripts_and_styles = is_admin() && wp_should_load_block_editor_scripts_and_styles(); $block_registry = WP_Block_Type_Registry::get_instance(); /* * Block styles are only enqueued if they're registered. For core blocks, this is only the case if * `wp_should_load_separate_core_block_assets()` returns true. Otherwise they use the single combined * 'wp-block-library` stylesheet. See also `register_core_block_style_handles()`. * Since `wp_enqueue_style()` does not trigger warnings if the style is not registered, it is okay to not cater for * this behavior here and simply call `wp_enqueue_style()` unconditionally. */ foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { // Front-end and editor styles. foreach ( $block_type->style_handles as $style_handle ) { wp_enqueue_style( $style_handle ); } // Front-end and editor scripts. foreach ( $block_type->script_handles as $script_handle ) { wp_enqueue_script( $script_handle ); } if ( $load_editor_scripts_and_styles ) { // Editor styles. foreach ( $block_type->editor_style_handles as $editor_style_handle ) { wp_enqueue_style( $editor_style_handle ); } // Editor scripts. foreach ( $block_type->editor_script_handles as $editor_script_handle ) { wp_enqueue_script( $editor_script_handle ); } } }}Changelog
Introduced in 5.0.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/script-loader.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.