render_block_core_comment_author_name

函数
render_block_core_comment_author_name ( $attributes, $content, $block )
参数
  • (array) $attributes Block attributes.
    Required:
  • (string) $content Block default content.
    Required:
  • (WP_Block) $block Block instance.
    Required:
返回值
  • (string) Return the post comment's author.
定义位置
相关方法
register_block_core_comment_author_namerender_block_core_comment_daterender_block_core_comment_contentrender_block_core_post_authorrender_block_core_comments_title
引入
-
弃用
-

render_block_core_comment_author_name: 这个函数用来渲染WordPress中的评论作者名块。评论作者名块显示评论作者的名字: 这个函数负责生成评论作者名称块的HTML标记。

在服务器上呈现`core/comment-author-name’区块。

function render_block_core_comment_author_name( $attributes, $content, $block ) {
	if ( ! isset( $block->context['commentId'] ) ) {
		return '';
	}

	$comment            = get_comment( $block->context['commentId'] );
	$commenter          = wp_get_current_commenter();
	$show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author'];
	if ( empty( $comment ) ) {
		return '';
	}

	$classes = '';
	if ( isset( $attributes['textAlign'] ) ) {
		$classes .= 'has-text-align-' . $attributes['textAlign'];
	}

	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
	$comment_author     = get_comment_author( $comment );
	$link               = get_comment_author_url( $comment );

	if ( ! empty( $link ) && ! empty( $attributes['isLink'] ) && ! empty( $attributes['linkTarget'] ) ) {
		$comment_author = sprintf( '<a rel="external nofollow ugc" href="%1s" target="%2s" >%3s</a>', esc_url( $link ), esc_attr( $attributes['linkTarget'] ), $comment_author );
	}
	if ( '0' === $comment->comment_approved && ! $show_pending_links ) {
		$comment_author = wp_kses( $comment_author, array() );
	}

	return sprintf(
		'<div %1$s>%2$s</div>',
		$wrapper_attributes,
		$comment_author
	);
}

常见问题

FAQs
查看更多 >