render_block_core_avatar( array $attributes, string $content, WP_Block $block ): string
- Since
- 6.0.0
- Source
wp-includes/blocks/avatar.php:18
core/avatar block on the server.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.
Parameters
$attributesarray- Block attributes.
$contentstring- Block default content.
$blockWP_Block- Block instance.
Return value
string- Return the avatar.
Performance profile
How much work a call to render_block_core_avatar() 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
- Heavy
- Scaling
- Constant
- Instructions
- 31–120
- Plugin surface
- None
- Called by
- 0
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 208.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below render_block_core_avatar() - querycontent query
get_post()one call below render_block_core_avatar() - optionoption read or write
get_option()one call below render_block_core_avatar()
Further down the call graph this can also reach cache, serialize 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 · 32 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_avatar() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($border_attributes) && !isset($value) && isset($attributes) && empty($author_id) | 31–34 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes() |
empty($border_attributes) && isset($value) | 33–36 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_comment() |
empty($border_attributes) && !isset($value) && !isset($attributes) && empty($author_id) | 36–39 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_query_var() |
!empty($border_attributes) && !isset($value) && isset($attributes) && empty($author_id) | 39–42 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr() |
empty($border_attributes) && !isset($attributes) && empty($author_id) | 41–44 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_post_field() |
!empty($border_attributes) && isset($value) | 41–44 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_comment() |
!empty($border_attributes) && !isset($value) && !isset($attributes) && empty($author_id) | 44–47 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_query_var() |
!empty($border_attributes) && !isset($attributes) && empty($author_id) | 49–52 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_post_field() |
empty($border_attributes) && isset($value) | 59–69 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_comment(), __(), sprintf(), extra_attr(), sprintf() |
empty($border_attributes) && !isset($value) && isset($attributes) && !empty($author_id) | 61–66 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_the_author_meta(), __(), sprintf(), extra_attr(), sprintf() |
empty($border_attributes) && !isset($value) && !isset($attributes) && !empty($author_id) | 66–71 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_query_var(), get_the_author_meta(), __(), sprintf(), extra_attr(), sprintf() |
!empty($border_attributes) && isset($value) | 67–77 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_comment(), __(), sprintf(), extra_attr(), sprintf() |
20 further outcomes, up to 120 instructions
!empty($border_attributes) && !isset($value) && isset($attributes) && !empty($author_id) | 69–74 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_the_author_meta(), __(), sprintf(), extra_attr(), sprintf() |
empty($border_attributes) && !isset($attributes) && !empty($author_id) | 71–76 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_post_field(), get_the_author_meta(), __(), sprintf(), extra_attr(), sprintf() |
!empty($border_attributes) && !isset($value) && !isset($attributes) && !empty($author_id) | 74–79 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_query_var(), get_the_author_meta(), __(), sprintf(), extra_attr(), sprintf() |
!empty($border_attributes) && !isset($attributes) && !empty($author_id) | 79–84 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_post_field(), get_the_author_meta(), __(), sprintf(), extra_attr(), sprintf() |
empty($border_attributes) && !isset($value) && isset($attributes) && !empty($author_id) && $attributes | 86–89 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_the_author_meta(), __(), sprintf(), extra_attr(), get_author_posts_url(), esc_url(), esc_attr(), sprintf(), sprintf() |
empty($border_attributes) && isset($value) && isset($attributes) && $attributes && isset($comment) | 88–91 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_comment(), __(), sprintf(), extra_attr(), esc_url(), esc_attr(), sprintf(), sprintf() |
empty($border_attributes) && !isset($value) && !empty($author_id) && $attributes | 91–94 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_query_var(), get_the_author_meta(), __(), sprintf(), extra_attr(), get_author_posts_url(), esc_url(), esc_attr(), sprintf(), sprintf() |
!empty($border_attributes) && !isset($value) && isset($attributes) && !empty($author_id) && $attributes | 94–97 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_the_author_meta(), __(), sprintf(), extra_attr(), get_author_posts_url(), esc_url(), esc_attr(), sprintf(), sprintf() |
!empty($border_attributes) && isset($value) && isset($attributes) && $attributes && isset($comment) | 96–99 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_comment(), __(), sprintf(), extra_attr(), esc_url(), esc_attr(), sprintf(), sprintf() |
empty($border_attributes) && !empty($author_id) && $attributes | 96–99 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_post_field(), get_the_author_meta(), __(), sprintf(), extra_attr(), get_author_posts_url(), esc_url(), esc_attr(), sprintf(), sprintf() |
!empty($border_attributes) && !isset($value) && !empty($author_id) && $attributes | 99–102 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_query_var(), get_the_author_meta(), __(), sprintf(), extra_attr(), get_author_posts_url(), esc_url(), esc_attr(), sprintf(), sprintf() |
empty($border_attributes) && !isset($value) && isset($attributes) && !empty($author_id) && $attributes | 99–102 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_the_author_meta(), __(), sprintf(), extra_attr(), __(), sprintf(), esc_attr(), get_author_posts_url(), esc_url(), esc_attr(), sprintf(), sprintf() |
empty($border_attributes) && isset($value) && isset($attributes) && $attributes && isset($comment) | 102–105 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_comment(), __(), sprintf(), extra_attr(), __(), sprintf(), esc_attr(), esc_url(), esc_attr(), sprintf(), sprintf() |
!empty($border_attributes) && !empty($author_id) && $attributes | 104–107 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_post_field(), get_the_author_meta(), __(), sprintf(), extra_attr(), get_author_posts_url(), esc_url(), esc_attr(), sprintf(), sprintf() |
empty($border_attributes) && !isset($value) && !empty($author_id) && $attributes | 104–107 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_query_var(), get_the_author_meta(), __(), sprintf(), extra_attr(), __(), sprintf(), esc_attr(), get_author_posts_url(), esc_url(), esc_attr(), sprintf(), sprintf() |
!empty($border_attributes) && !isset($value) && isset($attributes) && !empty($author_id) && $attributes | 107–110 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_the_author_meta(), __(), sprintf(), extra_attr(), __(), sprintf(), esc_attr(), get_author_posts_url(), esc_url(), esc_attr(), sprintf(), sprintf() |
empty($border_attributes) && !empty($author_id) && $attributes | 109–112 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), get_post_field(), get_the_author_meta(), __(), sprintf(), extra_attr(), __(), sprintf(), esc_attr(), get_author_posts_url(), esc_url(), esc_attr(), sprintf(), sprintf() |
!empty($border_attributes) && isset($value) && isset($attributes) && $attributes && isset($comment) | 110–113 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_comment(), __(), sprintf(), extra_attr(), __(), sprintf(), esc_attr(), esc_url(), esc_attr(), sprintf(), sprintf() |
!empty($border_attributes) && !isset($value) && !empty($author_id) && $attributes | 112–115 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_query_var(), get_the_author_meta(), __(), sprintf(), extra_attr(), __(), sprintf(), esc_attr(), get_author_posts_url(), esc_url(), esc_attr(), sprintf(), sprintf() |
!empty($border_attributes) && !empty($author_id) && $attributes | 117–120 | get_block_wrapper_attributes(), get_block_core_avatar_border_attributes(), esc_attr(), get_post_field(), get_the_author_meta(), __(), sprintf(), extra_attr(), __(), sprintf(), esc_attr(), get_author_posts_url(), esc_url(), esc_attr(), sprintf(), sprintf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 208 | 31–120 | 16 | |
| 8.5 | 208 | 31–120 | 16 | |
| 8.4 | 208 | 31–120 | 16 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 210 | 31–122 | 16 | |
| 8.2 | 210 | 31–122 | 16 | |
| 8.1 | 210 | 31–122 | 16 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 211 | 31–123 | 16 |
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 · 11
- get_block_wrapper_attributes()Generates a string of attributes by applying to the current block being rendered all of the features that the block supports.
- get_block_core_avatar_border_attributes()Generates class names and styles to apply the border support styles for the Avatar block.
- esc_attr()Escaping for HTML attributes.
- get_post_field()Retrieves data from a post field based on Post ID.
- get_query_var()Retrieves the value of a query variable in the WP_Query class.
- get_the_author_meta()Retrieves the requested data of the author of the current post.
- __()Retrieves the translation of $text.
- get_avatar()Retrieves the avatar `` tag for a user, email address, MD5 hash, comment, or post.
- esc_url()Checks and cleans a URL.
- get_author_posts_url()Retrieves the URL to the author page for the user with the ID provided.
- get_comment()Retrieves comment data given a comment ID or comment object.
Source code
function render_block_core_avatar( $attributes, $content, $block ) { $size = $attributes['size'] ?? 96; $wrapper_attributes = get_block_wrapper_attributes(); $border_attributes = get_block_core_avatar_border_attributes( $attributes ); // Class gets passed through `esc_attr` via `get_avatar`. $image_classes = ! empty( $border_attributes['class'] ) ? "wp-block-avatar__image {$border_attributes['class']}" : 'wp-block-avatar__image'; // Unlike class, `get_avatar` doesn't filter the styles via `esc_attr`. // The style engine does pass the border styles through // `safecss_filter_attr` however. $image_styles = ! empty( $border_attributes['style'] ) ? sprintf( ' style="%s"', esc_attr( $border_attributes['style'] ) ) : ''; if ( ! isset( $block->context['commentId'] ) ) { if ( isset( $attributes['userId'] ) ) { $author_id = $attributes['userId']; } elseif ( isset( $block->context['postId'] ) ) { $author_id = get_post_field( 'post_author', $block->context['postId'] ); } else { $author_id = get_query_var( 'author' ); } if ( empty( $author_id ) ) { return ''; } $author_name = get_the_author_meta( 'display_name', $author_id ); // translators: %s: Author name. $alt = sprintf( __( '%s Avatar' ), $author_name ); $avatar_block = get_avatar( $author_id, $size, '', $alt, array( 'extra_attr' => $image_styles, 'class' => $image_classes, ) ); if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) { $label = ''; if ( '_blank' === $attributes['linkTarget'] ) { // translators: %s is the Author name. $label = 'aria-label="' . esc_attr( sprintf( __( '(%s author archive, opens in a new tab)' ), $author_name ) ) . '"'; } // translators: 1: Author archive link. 2: Link target. %3$s Aria label. %4$s Avatar image. $avatar_block = sprintf( '<a href="%1$s" target="%2$s" %3$s class="wp-block-avatar__link">%4$s</a>', esc_url( get_author_posts_url( $author_id ) ), esc_attr( $attributes['linkTarget'] ), $label, $avatar_block ); } return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $avatar_block ); } $comment = get_comment( $block->context['commentId'] ); if ( ! $comment ) { return ''; } /* translators: %s: Author name. */ $alt = sprintf( __( '%s Avatar' ), $comment->comment_author ); $avatar_block = get_avatar( $comment, $size, '', $alt, array( 'extra_attr' => $image_styles, 'class' => $image_classes, ) ); if ( isset( $attributes['isLink'] ) && $attributes['isLink'] && isset( $comment->comment_author_url ) && '' !== $comment->comment_author_url ) { $label = ''; if ( '_blank' === $attributes['linkTarget'] ) { // translators: %s: Comment author name. $label = 'aria-label="' . esc_attr( sprintf( __( '(%s website link, opens in a new tab)' ), $comment->comment_author ) ) . '"'; } $avatar_block = sprintf( '<a href="%1$s" target="%2$s" %3$s class="wp-block-avatar__link">%4$s</a>', esc_url( $comment->comment_author_url ), esc_attr( $attributes['linkTarget'] ), $label, $avatar_block ); } return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $avatar_block );}Changelog
Introduced in 6.0.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.1.0 tag, from
src/wp-includes/blocks/avatar.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.