get_block_wrapper_attributes( string[] $extra_attributes = array() ): string
- Since
- 5.6.0
- Source
wp-includes/class-wp-block-supports.php:175
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
- Trivial
- Scaling
- Constant
- Instructions
- 5
- Plugin surface
- None
- Called by
- 50
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 152.
Nothing here hands control to plugin code.
50 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 5 | none |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 152 | 5 | 18 | |
| 8.5 | 152 | 5 | 18 | |
| 8.4 | 152 | 5 | 18 | 13 fewer instructions than PHP 8.3 |
| 8.3 | 165 | 5 | 18 | |
| 8.2 | 165 | 5 | 18 | |
| 8.1 | 165 | 5 | 18 | |
| 7.4 | 165 | 5 | 18 |
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 · 4
- safecss_filter_attr()Filters an inline style attribute and removes disallowed rules.
- esc_attr()Escaping for HTML attributes.
- WP_Block_Supports::get_instance()::apply_block_supports()
- WP_Block_Supports::get_instance()Utility method to retrieve the main instance of the class.
Used by · 50
- WP_Navigation_Block_Renderer::get_inner_blocks_html()Returns the html for the inner blocks of the navigation block.
- WP_Navigation_Block_Renderer::get_nav_attributes()Get the wrapper attributes
- block_core_home_link_build_li_wrapper_attributes()Builds an array with classes and style for the li wrapper
- render_block_core_archives()Renders the `core/archives` block on server.
- render_block_core_avatar()Renders the `core/avatar` block on the server.
- render_block_core_breadcrumbs()Renders the `core/breadcrumbs` block on the server.
- render_block_core_calendar()Renders the `core/calendar` block on server.
- render_block_core_categories()Renders the `core/categories` block on server.
- render_block_core_comment_author_name()Renders the `core/comment-author-name` block on the server.
- render_block_core_comment_content()Renders the `core/comment-content` block on the server.
- render_block_core_comment_date()Renders the `core/comment-date` block on the server.
- render_block_core_comment_edit_link()Renders the `core/comment-edit-link` block on the server.
Show all 50
- render_block_core_comment_reply_link()Renders the `core/comment-reply-link` block on the server.
- render_block_core_comment_template()Renders the `core/comment-template` block on the server.
- render_block_core_comments()Renders the `core/comments` block on the server.
- render_block_core_comments_pagination()Renders the `core/comments-pagination` block on the server.
- render_block_core_comments_pagination_next()Renders the `core/comments-pagination-next` block on the server.
- render_block_core_comments_pagination_numbers()Renders the `core/comments-pagination-numbers` block on the server.
- render_block_core_comments_pagination_previous()Renders the `core/comments-pagination-previous` block on the server.
- render_block_core_comments_title()Renders the `core/comments-title` block on the server.
- render_block_core_footnotes()Renders the `core/footnotes` block on the server.
- render_block_core_icon()Renders the `core/icon` block on server.
- render_block_core_latest_comments()Renders the `core/latest-comments` block on server.
- render_block_core_latest_posts()Renders the `core/latest-posts` block on server.
- render_block_core_loginout()Renders the `core/loginout` block on server.
- render_block_core_navigation_link()Renders the `core/navigation-link` block.
- render_block_core_navigation_overlay_close()Renders the `core/navigation-overlay-close` block on server.
- render_block_core_navigation_submenu()Renders the `core/navigation-submenu` block.
- render_block_core_page_list()Renders the `core/page-list` block on server.
- render_block_core_post_author()Renders the `core/post-author` block on the server.
- render_block_core_post_author_biography()Renders the `core/post-author-biography` block on the server.
- render_block_core_post_author_name()Renders the `core/post-author-name` block on the server.
- render_block_core_post_comments_count()Renders the `core/post-comments-count` block on the server.
- render_block_core_post_comments_form()Renders the `core/post-comments-form` block on the server.
- render_block_core_post_comments_link()Renders the `core/post-comments-link` block on the server.
- render_block_core_post_content()Renders the `core/post-content` block on the server.
- render_block_core_post_date()Renders the `core/post-date` block on the server.
- render_block_core_post_excerpt()Renders the `core/post-excerpt` block on the server.
- render_block_core_post_featured_image()Renders the `core/post-featured-image` block on the server.
- render_block_core_post_navigation_link()Renders the `core/post-navigation-link` block on the server.
- render_block_core_post_template()Renders the `core/post-template` block on the server.
- render_block_core_post_terms()Renders the `core/post-terms` block on the server.
- render_block_core_post_time_to_read()Renders the `core/post-time-to-read` block on the server.
- render_block_core_post_title()Renders the `core/post-title` block on the server.
- render_block_core_query_no_results()Renders the `core/query-no-results` block on the server.
- render_block_core_query_pagination()Renders the `core/query-pagination` block on the server.
- render_block_core_query_pagination_next()Renders the `core/query-pagination-next` block on the server.
- render_block_core_query_pagination_numbers()Renders the `core/query-pagination-numbers` block on the server.
- render_block_core_query_pagination_previous()Renders the `core/query-pagination-previous` block on the server.
- render_block_core_query_title()Renders the `core/query-title` block on the server.
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 ''; } // Attribute values are concatenated or overridden depending on the attribute type. // This is hardcoded on purpose, as we only support a fixed list of attributes. $attribute_merge_callbacks = array( 'style' => static function ( $new_attribute, $extra_attribute ) { $styles = array_filter( array( rtrim( trim( $new_attribute ), ';' ), rtrim( trim( $extra_attribute ), ';' ), ) ); return safecss_filter_attr( implode( ';', array_filter( $styles ) ) ); }, 'class' => static function ( $new_attribute, $extra_attribute ) { $classes = array_merge( (array) preg_split( '/\s+/', $extra_attribute, -1, PREG_SPLIT_NO_EMPTY ), (array) preg_split( '/\s+/', $new_attribute, -1, PREG_SPLIT_NO_EMPTY ) ); $classes = array_unique( array_filter( $classes ) ); return implode( ' ', $classes ); }, 'id' => static function ( $new_attribute, $extra_attribute ) { return '' !== $extra_attribute ? $extra_attribute : $new_attribute; }, 'aria-label' => static function ( $new_attribute, $extra_attribute ) { return '' !== $extra_attribute ? $extra_attribute : $new_attribute; }, ); $attributes = array(); foreach ( $attribute_merge_callbacks as $attribute_name => $merge_callback ) { $new_attribute = $new_attributes[ $attribute_name ] ?? ''; $extra_attribute = $extra_attributes[ $attribute_name ] ?? ''; $new_attribute = is_string( $new_attribute ) ? $new_attribute : ''; $extra_attribute = is_string( $extra_attribute ) ? $extra_attribute : ''; if ( '' === $new_attribute && '' === $extra_attribute ) { continue; } $attributes[ $attribute_name ] = $merge_callback( $new_attribute, $extra_attribute ); } foreach ( $extra_attributes as $attribute_name => $value ) { if ( ! isset( $attribute_merge_callbacks[ $attribute_name ] ) ) { $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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 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.