wppaste
WordPress

get_block_editor_settings( array $custom_settings, WP_Block_Editor_Context $block_editor_context ): array

Since
5.8.0
Source
wp-includes/block-editor.php:490
Returns the contextualized block editor settings for a selected editor context.

Compatibility

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

Parameters

$custom_settingsarray
Custom settings to use with the given editor type.
$block_editor_contextWP_Block_Editor_Context
The current block editor context.

Return value

array
The contextualized block editor settings.

Performance profile

How much work a call to get_block_editor_settings() 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
Expensive

Reaches an outbound HTTP request via wp_remote_get().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
191–274

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

Plugin surface
2 hooks

Third-party callbacks on 'block_editor_settings_all', 'block_editor_settings' 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

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_get()one call below get_block_editor_settings()
  • httpoutbound HTTP requestwp_remote_get()one call below get_block_editor_settings()
  • serializeserialisationmaybe_unserialize()one call below get_block_editor_settings()

Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 1 distinct outcome

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

WhenInstructionsCalls it makes
array_keys() && $actual_css === "" && !isset($value)191–274get_default_block_editor_settings(), get_allowed_block_types(), get_block_categories(), allowedBlockTypes(), ::WP_Block_Type_Registry(), ->get_all_registered(), array_keys(), wp_get_global_stylesheet(), wp_get_custom_css(), wp_get_global_stylesheet(), get_block_editor_theme_styles(), array_merge(), wp_get_global_settings(), _wp_get_iframed_editor_assets(), wp_is_block_theme(), current_theme_supports(), get_option(), get_option(), get_option(), get_option(), get_option(), get_option(), get_option(), get_option(), size(), wp_get_post_content_block_attributes(), current_user_can(), apply_filters(), current_user_can()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev336191–27428
8.5336191–27428
8.4336191–27428
8.3336191–27428
8.2336191–27428
8.1336191–274284 fewer instructions than PHP 7.4
7.4340191–27528

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

2 hooks fire while get_block_editor_settings() runs, in this order:

  1. apply_filters( block_editor_settings_all )filterline 645 (+155 into the body)

    Filters the settings to pass to the block editor for all editor type.

  2. do_action( block_editor_settings )filter_deprecatedline 659 (+169 into the body)

    Filters the settings to pass to the block editor.

Uses · 19

Show all 19

Used by · 1

Source code

function get_block_editor_settings( array $custom_settings, $block_editor_context ) {	$editor_settings = array_merge(		get_default_block_editor_settings(),		array(			'allowedBlockTypes' => get_allowed_block_types( $block_editor_context ),			'blockCategories'   => get_block_categories( $block_editor_context ),		),		$custom_settings	); 	$editor_settings['__experimentalBlockBindingsSupportedAttributes'] = array();	foreach ( array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() ) as $block_type ) {		$supported_block_attributes = get_block_bindings_supported_attributes( $block_type );		if ( ! empty( $supported_block_attributes ) ) {			$editor_settings['__experimentalBlockBindingsSupportedAttributes'][ $block_type ] = $supported_block_attributes;		}	} 	$global_styles = array();	$presets       = array(		array(			'css'            => 'variables',			'__unstableType' => 'presets',			'isGlobalStyles' => true,		),		array(			'css'            => 'presets',			'__unstableType' => 'presets',			'isGlobalStyles' => true,		),	);	foreach ( $presets as $preset_style ) {		$actual_css = wp_get_global_stylesheet( array( $preset_style['css'] ) );		if ( '' !== $actual_css ) {			$preset_style['css'] = $actual_css;			$global_styles[]     = $preset_style;		}	} 	$block_classes = array(		'css'            => 'styles',		'__unstableType' => 'theme',		'isGlobalStyles' => true,	);	$actual_css    = wp_get_global_stylesheet( array( $block_classes['css'] ) );	if ( '' !== $actual_css ) {		$block_classes['css'] = $actual_css;		$global_styles[]      = $block_classes;	} 	// Get any additional css from the customizer and add it before global styles custom CSS.	$global_styles[] = array(		'css'            => wp_get_custom_css(),		'__unstableType' => 'user',		'isGlobalStyles' => false,	); 	/*	 * Add the custom CSS as a separate stylesheet so any invalid CSS	 * entered by users does not break other global styles.	 */	$global_styles[] = array(		'css'            => wp_get_global_stylesheet( array( 'custom-css' ) ),		'__unstableType' => 'user',		'isGlobalStyles' => true,	); 	$editor_settings['styles'] = array_merge( $global_styles, get_block_editor_theme_styles() ); 	$editor_settings['__experimentalFeatures'] = wp_get_global_settings();	// These settings may need to be updated based on data coming from theme.json sources.	if ( isset( $editor_settings['__experimentalFeatures']['color']['palette'] ) ) {		$colors_by_origin          = $editor_settings['__experimentalFeatures']['color']['palette'];		$editor_settings['colors'] = $colors_by_origin['custom'] ?? $colors_by_origin['theme'] ?? $colors_by_origin['default'];	}	if ( isset( $editor_settings['__experimentalFeatures']['color']['gradients'] ) ) {		$gradients_by_origin          = $editor_settings['__experimentalFeatures']['color']['gradients'];		$editor_settings['gradients'] = $gradients_by_origin['custom'] ?? $gradients_by_origin['theme'] ?? $gradients_by_origin['default'];	}	if ( isset( $editor_settings['__experimentalFeatures']['typography']['fontSizes'] ) ) {

Changelog

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