WP_Widget_RSS

Core class used to implement a RSS widget.

Defined (1)

The class is defined in the following location(s).

/wp-includes/widgets/class-wp-widget-rss.php  
  1. class WP_Widget_RSS extends WP_Widget { 
  2.  
  3. /** 
  4. * Sets up a new RSS widget instance. 
  5. * @since 2.8.0 
  6. * @access public 
  7. */ 
  8. public function __construct() { 
  9. $widget_ops = array( 
  10. 'description' => __( 'Entries from any RSS or Atom feed.' ),  
  11. 'customize_selective_refresh' => true,  
  12. ); 
  13. $control_ops = array( 'width' => 400, 'height' => 200 ); 
  14. parent::__construct( 'rss', __( 'RSS' ), $widget_ops, $control_ops ); 
  15.  
  16. /** 
  17. * Outputs the content for the current RSS widget instance. 
  18. * @since 2.8.0 
  19. * @access public 
  20. * @param array $args Display arguments including 'before_title', 'after_title',  
  21. * 'before_widget', and 'after_widget'. 
  22. * @param array $instance Settings for the current RSS widget instance. 
  23. */ 
  24. public function widget( $args, $instance ) { 
  25. if ( isset($instance['error']) && $instance['error'] ) 
  26. return; 
  27.  
  28. $url = ! empty( $instance['url'] ) ? $instance['url'] : ''; 
  29. while ( stristr($url, 'http') != $url ) 
  30. $url = substr($url, 1); 
  31.  
  32. if ( empty($url) ) 
  33. return; 
  34.  
  35. // self-url destruction sequence 
  36. if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) ) 
  37. return; 
  38.  
  39. $rss = fetch_feed($url); 
  40. $title = $instance['title']; 
  41. $desc = ''; 
  42. $link = ''; 
  43.  
  44. if ( ! is_wp_error($rss) ) { 
  45. $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset')))); 
  46. if ( empty($title) ) 
  47. $title = strip_tags( $rss->get_title() ); 
  48. $link = strip_tags( $rss->get_permalink() ); 
  49. while ( stristr($link, 'http') != $link ) 
  50. $link = substr($link, 1); 
  51.  
  52. if ( empty($title) ) 
  53. $title = empty($desc) ? __('Unknown Feed') : $desc; 
  54.  
  55. /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ 
  56. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 
  57.  
  58. $url = strip_tags( $url ); 
  59. $icon = includes_url( 'images/rss.png' ); 
  60. if ( $title ) 
  61. $title = '<a class="rsswidget" href="' . esc_url( $url ) . '"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="' . esc_url( $icon ) . '" alt="RSS" /></a> <a class="rsswidget" href="' . esc_url( $link ) . '">'. esc_html( $title ) . '</a>'; 
  62.  
  63. echo $args['before_widget']; 
  64. if ( $title ) { 
  65. echo $args['before_title'] . $title . $args['after_title']; 
  66. wp_widget_rss_output( $rss, $instance ); 
  67. echo $args['after_widget']; 
  68.  
  69. if ( ! is_wp_error($rss) ) 
  70. $rss->__destruct(); 
  71. unset($rss); 
  72.  
  73. /** 
  74. * Handles updating settings for the current RSS widget instance. 
  75. * @since 2.8.0 
  76. * @access public 
  77. * @param array $new_instance New settings for this instance as input by the user via 
  78. * WP_Widget::form(). 
  79. * @param array $old_instance Old settings for this instance. 
  80. * @return array Updated settings to save. 
  81. */ 
  82. public function update( $new_instance, $old_instance ) { 
  83. $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) ); 
  84. return wp_widget_rss_process( $new_instance, $testurl ); 
  85.  
  86. /** 
  87. * Outputs the settings form for the RSS widget. 
  88. * @since 2.8.0 
  89. * @access public 
  90. * @param array $instance Current settings. 
  91. */ 
  92. public function form( $instance ) { 
  93. if ( empty( $instance ) ) { 
  94. $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 ); 
  95. $instance['number'] = $this->number; 
  96.  
  97. wp_widget_rss_form( $instance );