wppaste
WordPress

_wp_get_iframed_editor_assets(): array

Since
6.0.0
Source
wp-includes/block-editor.php:301
Collect the block editor assets that need to be loaded into the editor's iframe.

Compatibility

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

Return value

array
The block editor assets.
  • $stylesstring|false

    String containing the HTML for styles.
  • $scriptsstring|false

    String containing the HTML for scripts.

Performance profile

How much work a call to _wp_get_iframed_editor_assets() 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
82–95

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

Plugin surface
1 hook

Third-party callbacks on 'enqueue_block_assets' run inside this call, and their cost is not bounded by anything here.

Called by
1

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

What it touches

  • hookthird-party callbacksdo_action()called directly

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 · 8 distinct outcomes

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

WhenInstructionsCalls it makes
!current_theme_supports()82–84wp_theme_has_theme_json(), wp_enqueue_script(), wp_enqueue_style(), current_theme_supports(), add_filter(), do_action(), remove_filter(), ::WP_Block_Type_Registry(), ->get_all_registered(), has_action(), ob_start(), wp_print_styles(), wp_print_font_faces(), wp_print_font_faces_from_style_variations(), ob_get_clean(), ob_start(), wp_print_head_scripts(), wp_print_footer_scripts(), ob_get_clean()
current_theme_supports()85–87wp_theme_has_theme_json(), wp_enqueue_script(), wp_enqueue_style(), current_theme_supports(), wp_enqueue_style(), add_filter(), do_action(), remove_filter(), ::WP_Block_Type_Registry(), ->get_all_registered(), has_action(), ob_start(), wp_print_styles(), wp_print_font_faces(), wp_print_font_faces_from_style_variations(), ob_get_clean(), ob_start(), wp_print_head_scripts(), wp_print_footer_scripts(), ob_get_clean()
!current_theme_supports()86–88wp_theme_has_theme_json(), wp_enqueue_script(), wp_enqueue_style(), current_theme_supports(), add_filter(), do_action(), remove_filter(), ::WP_Block_Type_Registry(), ->get_all_registered(), has_action(), ob_start(), wp_print_styles(), wp_print_font_faces(), wp_print_font_faces_from_style_variations(), ob_get_clean(), add_action(), ob_start(), wp_print_head_scripts(), wp_print_footer_scripts(), ob_get_clean()
!current_theme_supports()86–88wp_theme_has_theme_json(), wp_enqueue_script(), wp_enqueue_style(), current_theme_supports(), add_filter(), do_action(), remove_filter(), ::WP_Block_Type_Registry(), ->get_all_registered(), has_action(), remove_action(), ob_start(), wp_print_styles(), wp_print_font_faces(), wp_print_font_faces_from_style_variations(), ob_get_clean(), ob_start(), wp_print_head_scripts(), wp_print_footer_scripts(), ob_get_clean()
current_theme_supports()89–91wp_theme_has_theme_json(), wp_enqueue_script(), wp_enqueue_style(), current_theme_supports(), wp_enqueue_style(), add_filter(), do_action(), remove_filter(), ::WP_Block_Type_Registry(), ->get_all_registered(), has_action(), ob_start(), wp_print_styles(), wp_print_font_faces(), wp_print_font_faces_from_style_variations(), ob_get_clean(), add_action(), ob_start(), wp_print_head_scripts(), wp_print_footer_scripts(), ob_get_clean()
current_theme_supports()89–91wp_theme_has_theme_json(), wp_enqueue_script(), wp_enqueue_style(), current_theme_supports(), wp_enqueue_style(), add_filter(), do_action(), remove_filter(), ::WP_Block_Type_Registry(), ->get_all_registered(), has_action(), remove_action(), ob_start(), wp_print_styles(), wp_print_font_faces(), wp_print_font_faces_from_style_variations(), ob_get_clean(), ob_start(), wp_print_head_scripts(), wp_print_footer_scripts(), ob_get_clean()
!current_theme_supports()90–92wp_theme_has_theme_json(), wp_enqueue_script(), wp_enqueue_style(), current_theme_supports(), add_filter(), do_action(), remove_filter(), ::WP_Block_Type_Registry(), ->get_all_registered(), has_action(), remove_action(), ob_start(), wp_print_styles(), wp_print_font_faces(), wp_print_font_faces_from_style_variations(), ob_get_clean(), add_action(), ob_start(), wp_print_head_scripts(), wp_print_footer_scripts(), ob_get_clean()
current_theme_supports()93–95wp_theme_has_theme_json(), wp_enqueue_script(), wp_enqueue_style(), current_theme_supports(), wp_enqueue_style(), add_filter(), do_action(), remove_filter(), ::WP_Block_Type_Registry(), ->get_all_registered(), has_action(), remove_action(), ob_start(), wp_print_styles(), wp_print_font_faces(), wp_print_font_faces_from_style_variations(), ob_get_clean(), add_action(), ob_start(), wp_print_head_scripts(), wp_print_footer_scripts(), ob_get_clean()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 110 instructions, 82–95 executed per call, 10 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.

Hooks and filters fired · 1

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

  1. do_action( enqueue_block_assets )actionline 341 (+40 into the body)

    Fires after enqueuing block assets for both editor and front-end.

Uses · 18

Show all 18

Used by · 1

Source code

function _wp_get_iframed_editor_assets() {	global $wp_styles, $wp_scripts; 	// Keep track of the styles and scripts instance to restore later.	$current_wp_styles  = $wp_styles;	$current_wp_scripts = $wp_scripts; 	// Create new instances to collect the assets.	$wp_styles  = new WP_Styles();	$wp_scripts = new WP_Scripts(); 	/*	 * Register all currently registered styles and scripts. The actions that	 * follow enqueue assets, but don't necessarily register them.	 */	$wp_styles->registered  = $current_wp_styles->registered;	$wp_scripts->registered = $current_wp_scripts->registered; 	/*	 * We generally do not need reset styles for the iframed editor.	 * However, if it's a classic theme, margins will be added to every block,	 * which is reset specifically for list items, so classic themes rely on	 * these reset styles.	 */	$wp_styles->done =		wp_theme_has_theme_json() ? array( 'wp-reset-editor-styles' ) : array(); 	wp_enqueue_script( 'wp-polyfill' );	// Enqueue the `editorStyle` handles for all core block, and dependencies.	wp_enqueue_style( 'wp-edit-blocks' ); 	if ( current_theme_supports( 'wp-block-styles' ) ) {		wp_enqueue_style( 'wp-block-library-theme' );	} 	/*	 * We don't want to load EDITOR scripts in the iframe, only enqueue	 * front-end assets for the content.	 */	add_filter( 'should_load_block_editor_scripts_and_styles', '__return_false' );	do_action( 'enqueue_block_assets' );	remove_filter( 'should_load_block_editor_scripts_and_styles', '__return_false' ); 	$block_registry = WP_Block_Type_Registry::get_instance(); 	/*	 * Additionally, do enqueue `editorStyle` assets for all blocks, which	 * contains editor-only styling for blocks (editor content).	 */	foreach ( $block_registry->get_all_registered() as $block_type ) {		if ( isset( $block_type->editor_style_handles ) && is_array( $block_type->editor_style_handles ) ) {			foreach ( $block_type->editor_style_handles as $style_handle ) {				wp_enqueue_style( $style_handle );			}		}	} 	/**	 * Remove the deprecated `print_emoji_styles` handler.	 * It avoids breaking style generation with a deprecation message.	 */	$has_emoji_styles = has_action( 'wp_print_styles', 'print_emoji_styles' );	if ( $has_emoji_styles ) {		remove_action( 'wp_print_styles', 'print_emoji_styles' );	} 	ob_start();	wp_print_styles();	wp_print_font_faces();	wp_print_font_faces_from_style_variations();	$styles = ob_get_clean(); 	if ( $has_emoji_styles ) {		add_action( 'wp_print_styles', 'print_emoji_styles' );	} 	ob_start();	wp_print_head_scripts();	wp_print_footer_scripts();	$scripts = ob_get_clean();

Changelog

Introduced in 6.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 6.9.7 tag, from src/wp-includes/block-editor.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.