| @@ -14,13 +14,18 @@ | ||
| 14 | 14 | * |
| 15 | 15 | * @return string Returns the block content with received rss items. |
| 16 | 16 | */ |
| 17 | 17 | function gutenberg_render_block_core_rss( $attributes ) { |
| 18 | - if ( in_array( untrailingslashit( $attributes['feedURL'] ), array( site_url(), home_url() ), true ) ) { | |
| 18 | + $feed_url = $attributes['feedURL'] ?? null; | |
| 19 | + if ( ! is_string( $feed_url ) ) { | |
| 20 | + return ''; | |
| 21 | + } | |
| 22 | + | |
| 23 | + if ( in_array( untrailingslashit( $feed_url ), array( site_url(), home_url() ), true ) ) { | |
| 19 | 24 | return '<div class="components-placeholder"><div class="notice notice-error">' . __( 'Adding an RSS feed to this site’s homepage is not supported, as it could lead to a loop that slows down your site. Try using another block, like the <strong>Latest Posts</strong> block, to list posts from the site.' ) . '</div></div>'; |
| 20 | 25 | } |
| 21 | 26 | |
| 22 | - $rss = fetch_feed( $attributes['feedURL'] ); | |
| 27 | + $rss = fetch_feed( $feed_url ); | |
| 23 | 28 | |
| 24 | 29 | if ( is_wp_error( $rss ) ) { |
| 25 | 30 | return '<div class="components-placeholder"><div class="notice notice-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $rss->get_error_message() ) . '</div></div>'; |
| 26 | 31 | } |
| @@ -32,9 +37,10 @@ | ||
| 32 | 37 | $rss_items = $rss->get_items( 0, $attributes['itemsToShow'] ); |
| 33 | 38 | $list_items = ''; |
| 34 | 39 | |
| 35 | 40 | $open_in_new_tab = ! empty( $attributes['openInNewTab'] ); |
| 36 | - $rel = ! empty( $attributes['rel'] ) ? trim( $attributes['rel'] ) : ''; | |
| 41 | + $rel_attr = $attributes['rel'] ?? null; | |
| 42 | + $rel = is_string( $rel_attr ) && '' !== $rel_attr ? trim( $rel_attr ) : ''; | |
| 37 | 43 | |
| 38 | 44 | $link_attributes = ''; |
| 39 | 45 | |
| 40 | 46 | if ( $open_in_new_tab ) { |
| @@ -96,9 +102,9 @@ | ||
| 96 | 102 | $excerpt = html_entity_decode( $description, ENT_QUOTES, get_option( 'blog_charset' ) ); |
| 97 | 103 | $excerpt = esc_attr( wp_trim_words( $excerpt, $attributes['excerptLength'], ' […]' ) ); |
| 98 | 104 | |
| 99 | 105 | // Change existing [...] to […]. |
| 100 | - if ( '[...]' === substr( $excerpt, -5 ) ) { | |
| 106 | + if ( str_ends_with( $excerpt, '[...]' ) ) { | |
| 101 | 107 | $excerpt = substr( $excerpt, 0, -5 ) . '[…]'; |
| 102 | 108 | } |
| 103 | 109 | |
| 104 | 110 | $excerpt = '<div class="wp-block-rss__item-excerpt">' . esc_html( $excerpt ) . '</div>'; |