Skip to content

Commit

Permalink
RSS block: check for description field before rendering excerpt (#66985)
Browse files Browse the repository at this point in the history
* Check for description before passing to html_entity_decode
* Check author field

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2024
1 parent d0a190b commit 160482d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/block-library/src/rss/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,20 @@ function render_block_core_rss( $attributes ) {
$author = $item->get_author();
if ( is_object( $author ) ) {
$author = $author->get_name();
$author = '<span class="wp-block-rss__item-author">' . sprintf(
/* translators: byline. %s: author. */
__( 'by %s' ),
esc_html( strip_tags( $author ) )
) . '</span>';
if ( ! empty( $author ) ) {
$author = '<span class="wp-block-rss__item-author">' . sprintf(
/* translators: byline. %s: author. */
__( 'by %s' ),
esc_html( strip_tags( $author ) )
) . '</span>';
}
}
}

$excerpt = '';
if ( $attributes['displayExcerpt'] ) {
$excerpt = html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) );
$excerpt = '';
$description = $item->get_description();
if ( $attributes['displayExcerpt'] && ! empty( $description ) ) {
$excerpt = html_entity_decode( $description, ENT_QUOTES, get_option( 'blog_charset' ) );
$excerpt = esc_attr( wp_trim_words( $excerpt, $attributes['excerptLength'], ' [&hellip;]' ) );

// Change existing [...] to [&hellip;].
Expand Down

0 comments on commit 160482d

Please sign in to comment.