wp/wp-includes/blocks/comment-author-name.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     5  * @package WordPress
     5  * @package WordPress
     6  */
     6  */
     7 
     7 
     8 /**
     8 /**
     9  * Renders the `core/comment-author-name` block on the server.
     9  * Renders the `core/comment-author-name` block on the server.
       
    10  *
       
    11  * @since 6.0.0
    10  *
    12  *
    11  * @param array    $attributes Block attributes.
    13  * @param array    $attributes Block attributes.
    12  * @param string   $content    Block default content.
    14  * @param string   $content    Block default content.
    13  * @param WP_Block $block      Block instance.
    15  * @param WP_Block $block      Block instance.
    14  * @return string Return the post comment's author.
    16  * @return string Return the post comment's author.
    23 	$show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author'];
    25 	$show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author'];
    24 	if ( empty( $comment ) ) {
    26 	if ( empty( $comment ) ) {
    25 		return '';
    27 		return '';
    26 	}
    28 	}
    27 
    29 
    28 	$classes = '';
    30 	$classes = array();
    29 	if ( isset( $attributes['textAlign'] ) ) {
    31 	if ( isset( $attributes['textAlign'] ) ) {
    30 		$classes .= 'has-text-align-' . $attributes['textAlign'];
    32 		$classes[] = 'has-text-align-' . $attributes['textAlign'];
       
    33 	}
       
    34 	if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
       
    35 		$classes[] = 'has-link-color';
    31 	}
    36 	}
    32 
    37 
    33 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
    38 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
    34 	$comment_author     = get_comment_author( $comment );
    39 	$comment_author     = get_comment_author( $comment );
    35 	$link               = get_comment_author_url( $comment );
    40 	$link               = get_comment_author_url( $comment );
    36 
    41 
    37 	if ( ! empty( $attributes['isLink'] ) && ! empty( $attributes['linkTarget'] ) ) {
    42 	if ( ! empty( $link ) && ! empty( $attributes['isLink'] ) && ! empty( $attributes['linkTarget'] ) ) {
    38 		$comment_author = sprintf( '<a rel="external nofollow ugc" href="%1s" target="%2s" >%3s</a>', esc_url( $link ), esc_attr( $attributes['linkTarget'] ), $comment_author );
    43 		$comment_author = sprintf( '<a rel="external nofollow ugc" href="%1s" target="%2s" >%3s</a>', esc_url( $link ), esc_attr( $attributes['linkTarget'] ), $comment_author );
    39 	}
    44 	}
    40 	if ( '0' === $comment->comment_approved && ! $show_pending_links ) {
    45 	if ( '0' === $comment->comment_approved && ! $show_pending_links ) {
    41 		$comment_author = wp_kses( $comment_author, array() );
    46 		$comment_author = wp_kses( $comment_author, array() );
    42 	}
    47 	}
    48 	);
    53 	);
    49 }
    54 }
    50 
    55 
    51 /**
    56 /**
    52  * Registers the `core/comment-author-name` block on the server.
    57  * Registers the `core/comment-author-name` block on the server.
       
    58  *
       
    59  * @since 6.0.0
    53  */
    60  */
    54 function register_block_core_comment_author_name() {
    61 function register_block_core_comment_author_name() {
    55 	register_block_type_from_metadata(
    62 	register_block_type_from_metadata(
    56 		__DIR__ . '/comment-author-name',
    63 		__DIR__ . '/comment-author-name',
    57 		array(
    64 		array(