wp/wp-includes/blocks/comment-reply-link.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-reply-link` block on the server.
     9  * Renders the `core/comment-reply-link` 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 reply link.
    16  * @return string Return the post comment's reply link.
    32 	$max_depth = get_option( 'thread_comments_depth' );
    34 	$max_depth = get_option( 'thread_comments_depth' );
    33 	$parent_id = $comment->comment_parent;
    35 	$parent_id = $comment->comment_parent;
    34 
    36 
    35 	// Compute comment's depth iterating over its ancestors.
    37 	// Compute comment's depth iterating over its ancestors.
    36 	while ( ! empty( $parent_id ) ) {
    38 	while ( ! empty( $parent_id ) ) {
    37 		$depth++;
    39 		++$depth;
    38 		$parent_id = get_comment( $parent_id )->comment_parent;
    40 		$parent_id = get_comment( $parent_id )->comment_parent;
    39 	}
    41 	}
    40 
    42 
    41 	$comment_reply_link = get_comment_reply_link(
    43 	$comment_reply_link = get_comment_reply_link(
    42 		array(
    44 		array(
    49 	// Render nothing if the generated reply link is empty.
    51 	// Render nothing if the generated reply link is empty.
    50 	if ( empty( $comment_reply_link ) ) {
    52 	if ( empty( $comment_reply_link ) ) {
    51 		return;
    53 		return;
    52 	}
    54 	}
    53 
    55 
    54 	$classes = '';
    56 	$classes = array();
    55 	if ( isset( $attributes['textAlign'] ) ) {
    57 	if ( isset( $attributes['textAlign'] ) ) {
    56 		$classes .= 'has-text-align-' . $attributes['textAlign'];
    58 		$classes[] = 'has-text-align-' . $attributes['textAlign'];
       
    59 	}
       
    60 	if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
       
    61 		$classes[] = 'has-link-color';
    57 	}
    62 	}
    58 
    63 
    59 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
    64 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
    60 
    65 
    61 	return sprintf(
    66 	return sprintf(
    62 		'<div %1$s>%2$s</div>',
    67 		'<div %1$s>%2$s</div>',
    63 		$wrapper_attributes,
    68 		$wrapper_attributes,
    64 		$comment_reply_link
    69 		$comment_reply_link
    65 	);
    70 	);
    66 }
    71 }
    67 
    72 
    68 /**
    73 /**
    69  * Registers the `core/comment-reply-link` block on the server.
    74  * Registers the `core/comment-reply-link` block on the server.
       
    75  *
       
    76  * @since 6.0.0
    70  */
    77  */
    71 function register_block_core_comment_reply_link() {
    78 function register_block_core_comment_reply_link() {
    72 	register_block_type_from_metadata(
    79 	register_block_type_from_metadata(
    73 		__DIR__ . '/comment-reply-link',
    80 		__DIR__ . '/comment-reply-link',
    74 		array(
    81 		array(