Changeset 51445 for branches/5.8/src/wp-includes/blocks/post-excerpt.php
- Timestamp:
- 07/15/2021 09:12:39 PM (4 years ago)
- Location:
- branches/5.8
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.8
-
branches/5.8/src/wp-includes/blocks/post-excerpt.php
r50929 r51445 19 19 } 20 20 21 $more_text = isset( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . $attributes['moreText'] . '</a>' : ''; 22 23 $filter_excerpt_length = function() use ( $attributes ) { 24 return isset( $attributes['wordCount'] ) ? $attributes['wordCount'] : 55; 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>' : ''; 22 $filter_excerpt_more = function( $more ) use ( $more_text ) { 23 return empty( $more_text ) ? $more : ''; 25 24 }; 26 add_filter( 27 'excerpt_length', 28 $filter_excerpt_length 29 ); 30 25 /** 26 * Some themes might use `excerpt_more` filter to handle the 27 * `more` link displayed after a trimmed excerpt. Since the 28 * block has a `more text` attribute we have to check and 29 * override if needed the return value from this filter. 30 * So if the block's attribute is not empty override the 31 * `excerpt_more` filter and return nothing. This will 32 * result in showing only one `read more` link at a time. 33 */ 34 add_filter( 'excerpt_more', $filter_excerpt_more ); 31 35 $classes = ''; 32 36 if ( isset( $attributes['textAlign'] ) ) { 33 $classes .= 'has-text-align-' . $attributes['textAlign'];37 $classes .= "has-text-align-{$attributes['textAlign']}"; 34 38 } 35 39 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); 36 40 37 $content = '<p class="wp-block-post-excerpt__excerpt">' . get_the_excerpt( $block->context['postId'] ); 38 if ( ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'] ) { 41 $content = '<p class="wp-block-post-excerpt__excerpt">' . get_the_excerpt( $block->context['postId'] ); 42 $show_more_on_new_line = ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine']; 43 if ( $show_more_on_new_line && ! empty( $more_text ) ) { 39 44 $content .= '</p><p class="wp-block-post-excerpt__more-text">' . $more_text . '</p>'; 40 45 } else { 41 46 $content .= " $more_text</p>"; 42 47 } 43 44 remove_filter( 45 'excerpt_length', 46 $filter_excerpt_length 47 ); 48 48 remove_filter( 'excerpt_more', $filter_excerpt_more ); 49 49 return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $content ); 50 50 }
Note: See TracChangeset
for help on using the changeset viewer.