wp_widget_rss_process

Process RSS feed widget data and optionally retrieve feed items.

Description

(array) wp_widget_rss_process( (array) $widget_rss, (bool) $check_feed = true ); 

The feed widget can not have more than 20 items or it will reset back to the default, which is 10.

The resulting array has the feed title, feed url, feed link (from channel), feed items, error (if any), and whether to show summary, author, and date. All respectively in the order of the array elements.

Returns (array)

Parameters (2)

0. $widget_rss (array)
RSS widget feed data. Expects unescaped data.
1. $check_feed — Optional. (bool) => true
Optional, default is true. Whether to check feed for errors.

Usage

  1. if ( !function_exists( 'wp_widget_rss_process' ) ) { 
  2. require_once ABSPATH . WPINC . '/widgets.php'; 
  3.  
  4. // RSS widget feed data. Expects unescaped data. 
  5. $widget_rss = array(); 
  6.  
  7. // Optional, default is true. Whether to check feed for errors. 
  8. $check_feed = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_widget_rss_process($widget_rss, $check_feed); 
  12.  

Defined (1)

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

/wp-includes/widgets.php  
  1. function wp_widget_rss_process( $widget_rss, $check_feed = true ) { 
  2. $items = (int) $widget_rss['items']; 
  3. if ( $items < 1 || 20 < $items ) 
  4. $items = 10; 
  5. $url = esc_url_raw( strip_tags( $widget_rss['url'] ) ); 
  6. $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : ''; 
  7. $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0; 
  8. $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] :0; 
  9. $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0; 
  10.  
  11. if ( $check_feed ) { 
  12. $rss = fetch_feed($url); 
  13. $error = false; 
  14. $link = ''; 
  15. if ( is_wp_error($rss) ) { 
  16. $error = $rss->get_error_message(); 
  17. } else { 
  18. $link = esc_url(strip_tags($rss->get_permalink())); 
  19. while ( stristr($link, 'http') != $link ) 
  20. $link = substr($link, 1); 
  21.  
  22. $rss->__destruct(); 
  23. unset($rss); 
  24.  
  25. return compact( 'title', 'url', 'link', 'items', error, 'show_summary', 'show_author', 'show_date' );