wppaste
WordPress

wp_enqueue_registered_block_scripts_and_styles()

Since
5.0.0
Source
wp-includes/script-loader.php:2773
Enqueues registered block scripts and styles, depending on current rendered context (only enqueuing editor scripts while in context of the editor).

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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
7–23

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
wp_should_load_block_assets_on_demand() && wp_is_block_theme()7wp_should_load_block_assets_on_demand(), wp_is_block_theme()
wp_should_load_block_assets_on_demand() && !wp_is_block_theme() && !has_action()12wp_should_load_block_assets_on_demand(), wp_is_block_theme(), has_action()
!wp_should_load_block_assets_on_demand() && !is_admin()15–16wp_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–19wp_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()23wp_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

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.

  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/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.