wppaste
WordPress

get_block_wrapper_attributes( string[] $extra_attributes = array() ): string

Since
5.6.0
Source
wp-includes/class-wp-block-supports.php:175
Generates a string of attributes by applying to the current block being rendered all of the features that the block supports.

Compatibility

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

$extra_attributesstring[]optional
Array of extra attributes to render on the block wrapper.Default: array()

Return value

string
String of HTML attributes.

Performance profile

How much work a call to get_block_wrapper_attributes() 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 what you pass in.

Instructions
11–25

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
50

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

What it touches

  • hookthird-party callbacksapply_filters()one call below get_block_wrapper_attributes()

Further down the call graph this can also reach option, cache, serialize, 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_wrapper_attributes() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always11–25::WP_Block_Supports(), ->apply_block_supports()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev6611–2514
8.56611–2514
8.46611–25143 fewer instructions than PHP 8.3
8.36911–2814
8.26911–2814
8.16911–2814
7.46911–2814

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

Used by · 50

Show all 50

Source code

function get_block_wrapper_attributes( $extra_attributes = array() ) {	$new_attributes = WP_Block_Supports::get_instance()->apply_block_supports(); 	if ( empty( $new_attributes ) && empty( $extra_attributes ) ) {		return '';	} 	// This is hardcoded on purpose.	// We only support a fixed list of attributes.	$attributes_to_merge = array( 'style', 'class', 'id', 'aria-label' );	$attributes          = array();	foreach ( $attributes_to_merge as $attribute_name ) {		if ( empty( $new_attributes[ $attribute_name ] ) && empty( $extra_attributes[ $attribute_name ] ) ) {			continue;		} 		if ( empty( $new_attributes[ $attribute_name ] ) ) {			$attributes[ $attribute_name ] = $extra_attributes[ $attribute_name ];			continue;		} 		if ( empty( $extra_attributes[ $attribute_name ] ) ) {			$attributes[ $attribute_name ] = $new_attributes[ $attribute_name ];			continue;		} 		$attributes[ $attribute_name ] = $extra_attributes[ $attribute_name ] . ' ' . $new_attributes[ $attribute_name ];	} 	foreach ( $extra_attributes as $attribute_name => $value ) {		if ( ! in_array( $attribute_name, $attributes_to_merge, true ) ) {			$attributes[ $attribute_name ] = $value;		}	} 	if ( empty( $attributes ) ) {		return '';	} 	$normalized_attributes = array();	foreach ( $attributes as $key => $value ) {		$normalized_attributes[] = $key . '="' . esc_attr( $value ) . '"';	} 	return implode( ' ', $normalized_attributes );}

Changelog

Introduced in 5.6.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.8.8 tag, from src/wp-includes/class-wp-block-supports.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.