wp/wp-includes/blocks/post-excerpt.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    16 function render_block_core_post_excerpt( $attributes, $content, $block ) {
    16 function render_block_core_post_excerpt( $attributes, $content, $block ) {
    17 	if ( ! isset( $block->context['postId'] ) ) {
    17 	if ( ! isset( $block->context['postId'] ) ) {
    18 		return '';
    18 		return '';
    19 	}
    19 	}
    20 
    20 
    21 	$more_text           = ! empty( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . $attributes['moreText'] . '</a>' : '';
    21 	$excerpt = get_the_excerpt();
       
    22 
       
    23 	if ( empty( $excerpt ) ) {
       
    24 		return '';
       
    25 	}
       
    26 
       
    27 	$more_text           = ! empty( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . wp_kses_post( $attributes['moreText'] ) . '</a>' : '';
    22 	$filter_excerpt_more = function( $more ) use ( $more_text ) {
    28 	$filter_excerpt_more = function( $more ) use ( $more_text ) {
    23 		return empty( $more_text ) ? $more : '';
    29 		return empty( $more_text ) ? $more : '';
    24 	};
    30 	};
    25 	/**
    31 	/**
    26 	 * Some themes might use `excerpt_more` filter to handle the
    32 	 * Some themes might use `excerpt_more` filter to handle the
    36 	if ( isset( $attributes['textAlign'] ) ) {
    42 	if ( isset( $attributes['textAlign'] ) ) {
    37 		$classes .= "has-text-align-{$attributes['textAlign']}";
    43 		$classes .= "has-text-align-{$attributes['textAlign']}";
    38 	}
    44 	}
    39 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
    45 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
    40 
    46 
    41 	$content               = '<p class="wp-block-post-excerpt__excerpt">' . get_the_excerpt( $block->context['postId'] );
    47 	$content               = '<p class="wp-block-post-excerpt__excerpt">' . $excerpt;
    42 	$show_more_on_new_line = ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'];
    48 	$show_more_on_new_line = ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'];
    43 	if ( $show_more_on_new_line && ! empty( $more_text ) ) {
    49 	if ( $show_more_on_new_line && ! empty( $more_text ) ) {
    44 		$content .= '</p><p class="wp-block-post-excerpt__more-text">' . $more_text . '</p>';
    50 		$content .= '</p><p class="wp-block-post-excerpt__more-text">' . $more_text . '</p>';
    45 	} else {
    51 	} else {
    46 		$content .= " $more_text</p>";
    52 		$content .= " $more_text</p>";