3 * Widget API: WP_Widget_RSS class
11 * Core class used to implement a RSS widget.
17 class WP_Widget_RSS extends WP_Widget {
20 * Sets up a new RSS widget instance.
25 public function __construct() {
27 'description' => __( 'Entries from any RSS or Atom feed.' ),
28 'customize_selective_refresh' => true,
30 $control_ops = array( 'width' => 400, 'height' => 200 );
31 parent::__construct( 'rss', __( 'RSS' ), $widget_ops, $control_ops );
35 * Outputs the content for the current RSS widget instance.
40 * @param array $args Display arguments including 'before_title', 'after_title',
41 * 'before_widget', and 'after_widget'.
42 * @param array $instance Settings for the current RSS widget instance.
44 public function widget( $args, $instance ) {
45 if ( isset($instance['error']) && $instance['error'] )
48 $url = ! empty( $instance['url'] ) ? $instance['url'] : '';
49 while ( stristr($url, 'http') != $url )
50 $url = substr($url, 1);
55 // self-url destruction sequence
56 if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) )
59 $rss = fetch_feed($url);
60 $title = $instance['title'];
64 if ( ! is_wp_error($rss) ) {
65 $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
67 $title = strip_tags( $rss->get_title() );
68 $link = strip_tags( $rss->get_permalink() );
69 while ( stristr($link, 'http') != $link )
70 $link = substr($link, 1);
74 $title = empty($desc) ? __('Unknown Feed') : $desc;
76 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
77 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
79 $url = strip_tags( $url );
80 $icon = includes_url( 'images/rss.png' );
82 $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>';
84 echo $args['before_widget'];
86 echo $args['before_title'] . $title . $args['after_title'];
88 wp_widget_rss_output( $rss, $instance );
89 echo $args['after_widget'];
91 if ( ! is_wp_error($rss) )
97 * Handles updating settings for the current RSS widget instance.
102 * @param array $new_instance New settings for this instance as input by the user via
104 * @param array $old_instance Old settings for this instance.
105 * @return array Updated settings to save.
107 public function update( $new_instance, $old_instance ) {
108 $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
109 return wp_widget_rss_process( $new_instance, $testurl );
113 * Outputs the settings form for the RSS widget.
118 * @param array $instance Current settings.
120 public function form( $instance ) {
121 if ( empty( $instance ) ) {
122 $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
124 $instance['number'] = $this->number;
126 wp_widget_rss_form( $instance );