Make WordPress Core

Ticket #63611: wp_widget_rss_output-html-entities-fix.diff

File wp_widget_rss_output-html-entities-fix.diff, 1.9 KB (added by sachinrajcp123, 14 months ago)
Line 
1Index: src/wp-includes/widgets.php
2===================================================================
3--- src/wp-includes/widgets.php (revision 60000)
4+++ src/wp-includes/widgets.php (working copy)
5@@
6 function wp_widget_rss_output( $rss, $args = array() ) {
7 if ( is_string( $rss ) ) {
8 $rss = fetch_feed( $rss );
9 } elseif ( is_array( $rss ) && isset( $rss['url'] ) ) {
10 $args = $rss;
11 $rss = fetch_feed( $rss['url'] );
12 }
13
14 if ( is_wp_error( $rss ) ) {
15 if ( is_admin() || current_user_can( 'manage_options' ) ) {
16 echo '<p>' . sprintf( __( '<strong>RSS Error</strong>: %s' ), $rss->get_error_message() ) . '</p>';
17 }
18 return;
19 }
20
21 $default_args = array(
22 'show_author' => 0,
23 'show_date' => 0,
24 'show_summary' => 0,
25 );
26 $args = wp_parse_args( $args, $default_args );
27
28 $items = (int) $args['items'];
29 if ( $items < 1 || 20 < $items ) {
30 $items = 10;
31 }
32
33 $rss_items = $rss->get_items( 0, $items );
34
35 if ( empty( $rss_items ) ) {
36 echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>';
37 $rss->__destruct();
38 unset( $rss );
39 return;
40 }
41
42 echo '<ul>';
43 foreach ( $rss_items as $item ) {
44- $title = esc_html( trim( strip_tags( $item->get_title() ) ) );
45+ // Decode HTML entities first to avoid showing escaped HTML tags like &lt;em&gt;.
46+ $title = esc_html( trim( strip_tags( html_entity_decode( $item->get_title() ) ) ) );
47
48 if ( '' === $title ) {
49 $title = __( 'Untitled' );
50 }
51
52 $link = $item->get_link();
53 while ( stristr( $link, 'http' ) !== $link ) {
54 $link = substr( $link, 1 );
55 }
56 $link = esc_url( strip_tags( $link ) );
57
58 $desc = $item->get_description();
59 $desc = html_entity_decode( $desc, ENT_QUOTES, get_option( 'blog_charset' ) );
60 $desc = esc_attr( wp_trim_words( $desc, 55, ' [&hellip;]' ) );
61 $summary = '';
62 if ( $args['show_summary'] ) {
63 $summary = $desc;
64 }