Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: avatar.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/avatar` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/avatar` block on the server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 6.0.0
[10] Fix | Delete
*
[11] Fix | Delete
* @param array $attributes Block attributes.
[12] Fix | Delete
* @param string $content Block default content.
[13] Fix | Delete
* @param WP_Block $block Block instance.
[14] Fix | Delete
* @return string Return the avatar.
[15] Fix | Delete
*/
[16] Fix | Delete
function render_block_core_avatar( $attributes, $content, $block ) {
[17] Fix | Delete
$size = isset( $attributes['size'] ) ? $attributes['size'] : 96;
[18] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes();
[19] Fix | Delete
$border_attributes = get_block_core_avatar_border_attributes( $attributes );
[20] Fix | Delete
[21] Fix | Delete
// Class gets passed through `esc_attr` via `get_avatar`.
[22] Fix | Delete
$image_classes = ! empty( $border_attributes['class'] )
[23] Fix | Delete
? "wp-block-avatar__image {$border_attributes['class']}"
[24] Fix | Delete
: 'wp-block-avatar__image';
[25] Fix | Delete
[26] Fix | Delete
// Unlike class, `get_avatar` doesn't filter the styles via `esc_attr`.
[27] Fix | Delete
// The style engine does pass the border styles through
[28] Fix | Delete
// `safecss_filter_attr` however.
[29] Fix | Delete
$image_styles = ! empty( $border_attributes['style'] )
[30] Fix | Delete
? sprintf( ' style="%s"', esc_attr( $border_attributes['style'] ) )
[31] Fix | Delete
: '';
[32] Fix | Delete
[33] Fix | Delete
if ( ! isset( $block->context['commentId'] ) ) {
[34] Fix | Delete
if ( isset( $attributes['userId'] ) ) {
[35] Fix | Delete
$author_id = $attributes['userId'];
[36] Fix | Delete
} elseif ( isset( $block->context['postId'] ) ) {
[37] Fix | Delete
$author_id = get_post_field( 'post_author', $block->context['postId'] );
[38] Fix | Delete
} else {
[39] Fix | Delete
$author_id = get_query_var( 'author' );
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
if ( empty( $author_id ) ) {
[43] Fix | Delete
return '';
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
$author_name = get_the_author_meta( 'display_name', $author_id );
[47] Fix | Delete
// translators: %s is the Author name.
[48] Fix | Delete
$alt = sprintf( __( '%s Avatar' ), $author_name );
[49] Fix | Delete
$avatar_block = get_avatar(
[50] Fix | Delete
$author_id,
[51] Fix | Delete
$size,
[52] Fix | Delete
'',
[53] Fix | Delete
$alt,
[54] Fix | Delete
array(
[55] Fix | Delete
'extra_attr' => $image_styles,
[56] Fix | Delete
'class' => $image_classes,
[57] Fix | Delete
)
[58] Fix | Delete
);
[59] Fix | Delete
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
[60] Fix | Delete
$label = '';
[61] Fix | Delete
if ( '_blank' === $attributes['linkTarget'] ) {
[62] Fix | Delete
// translators: %s is the Author name.
[63] Fix | Delete
$label = 'aria-label="' . esc_attr( sprintf( __( '(%s author archive, opens in a new tab)' ), $author_name ) ) . '"';
[64] Fix | Delete
}
[65] Fix | Delete
// translators: %1$s: Author archive link. %2$s: Link target. %3$s Aria label. %4$s Avatar image.
[66] Fix | Delete
$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 );
[67] Fix | Delete
}
[68] Fix | Delete
return sprintf( '<div %1s>%2s</div>', $wrapper_attributes, $avatar_block );
[69] Fix | Delete
}
[70] Fix | Delete
$comment = get_comment( $block->context['commentId'] );
[71] Fix | Delete
if ( ! $comment ) {
[72] Fix | Delete
return '';
[73] Fix | Delete
}
[74] Fix | Delete
/* translators: %s is the Comment Author name */
[75] Fix | Delete
$alt = sprintf( __( '%s Avatar' ), $comment->comment_author );
[76] Fix | Delete
$avatar_block = get_avatar(
[77] Fix | Delete
$comment,
[78] Fix | Delete
$size,
[79] Fix | Delete
'',
[80] Fix | Delete
$alt,
[81] Fix | Delete
array(
[82] Fix | Delete
'extra_attr' => $image_styles,
[83] Fix | Delete
'class' => $image_classes,
[84] Fix | Delete
)
[85] Fix | Delete
);
[86] Fix | Delete
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] && isset( $comment->comment_author_url ) && '' !== $comment->comment_author_url ) {
[87] Fix | Delete
$label = '';
[88] Fix | Delete
if ( '_blank' === $attributes['linkTarget'] ) {
[89] Fix | Delete
// translators: %s is the Comment Author name.
[90] Fix | Delete
$label = 'aria-label="' . esc_attr( sprintf( __( '(%s website link, opens in a new tab)' ), $comment->comment_author ) ) . '"';
[91] Fix | Delete
}
[92] Fix | Delete
// translators: %1$s: Comment Author website link. %2$s: Link target. %3$s Aria label. %4$s Avatar image.
[93] Fix | Delete
$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 );
[94] Fix | Delete
}
[95] Fix | Delete
return sprintf( '<div %1s>%2s</div>', $wrapper_attributes, $avatar_block );
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Generates class names and styles to apply the border support styles for
[100] Fix | Delete
* the Avatar block.
[101] Fix | Delete
*
[102] Fix | Delete
* @since 6.3.0
[103] Fix | Delete
*
[104] Fix | Delete
* @param array $attributes The block attributes.
[105] Fix | Delete
* @return array The border-related classnames and styles for the block.
[106] Fix | Delete
*/
[107] Fix | Delete
function get_block_core_avatar_border_attributes( $attributes ) {
[108] Fix | Delete
$border_styles = array();
[109] Fix | Delete
$sides = array( 'top', 'right', 'bottom', 'left' );
[110] Fix | Delete
[111] Fix | Delete
// Border radius.
[112] Fix | Delete
if ( isset( $attributes['style']['border']['radius'] ) ) {
[113] Fix | Delete
$border_styles['radius'] = $attributes['style']['border']['radius'];
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
// Border style.
[117] Fix | Delete
if ( isset( $attributes['style']['border']['style'] ) ) {
[118] Fix | Delete
$border_styles['style'] = $attributes['style']['border']['style'];
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
// Border width.
[122] Fix | Delete
if ( isset( $attributes['style']['border']['width'] ) ) {
[123] Fix | Delete
$border_styles['width'] = $attributes['style']['border']['width'];
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
// Border color.
[127] Fix | Delete
$preset_color = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null;
[128] Fix | Delete
$custom_color = $attributes['style']['border']['color'] ?? null;
[129] Fix | Delete
$border_styles['color'] = $preset_color ? $preset_color : $custom_color;
[130] Fix | Delete
[131] Fix | Delete
// Individual border styles e.g. top, left etc.
[132] Fix | Delete
foreach ( $sides as $side ) {
[133] Fix | Delete
$border = $attributes['style']['border'][ $side ] ?? null;
[134] Fix | Delete
$border_styles[ $side ] = array(
[135] Fix | Delete
'color' => isset( $border['color'] ) ? $border['color'] : null,
[136] Fix | Delete
'style' => isset( $border['style'] ) ? $border['style'] : null,
[137] Fix | Delete
'width' => isset( $border['width'] ) ? $border['width'] : null,
[138] Fix | Delete
);
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
$styles = wp_style_engine_get_styles( array( 'border' => $border_styles ) );
[142] Fix | Delete
$attributes = array();
[143] Fix | Delete
if ( ! empty( $styles['classnames'] ) ) {
[144] Fix | Delete
$attributes['class'] = $styles['classnames'];
[145] Fix | Delete
}
[146] Fix | Delete
if ( ! empty( $styles['css'] ) ) {
[147] Fix | Delete
$attributes['style'] = $styles['css'];
[148] Fix | Delete
}
[149] Fix | Delete
return $attributes;
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* Registers the `core/avatar` block on the server.
[154] Fix | Delete
*
[155] Fix | Delete
* @since 6.0.0
[156] Fix | Delete
*/
[157] Fix | Delete
function register_block_core_avatar() {
[158] Fix | Delete
register_block_type_from_metadata(
[159] Fix | Delete
__DIR__ . '/avatar',
[160] Fix | Delete
array(
[161] Fix | Delete
'render_callback' => 'render_block_core_avatar',
[162] Fix | Delete
)
[163] Fix | Delete
);
[164] Fix | Delete
}
[165] Fix | Delete
add_action( 'init', 'register_block_core_avatar' );
[166] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function