Breakage on failed/empty RSS Feeds
-
I like that this is a simple plugin, and I don’t want to replace it, but I have a problem where the RSS Feeds I’m using don’t validate when they’re working properly, and they randomly fail completely (don’t ask), and I need to handle that gracefully.
I didn’t want to display an error message when the don’t ‘validate.’ I needed the error message to display only when the RSS Feeds are empty or fail.
The solution posted at https://ww.wp.xz.cn/support/topic/call-to-undefined-method-wp_errorenable_order_by_date/ didn’t work for me, so I fiddled with the code (novice PHP level), and this works for me.
The first and last lines here are repeated below, for ease of reference in the PHP file. The lines between are changed.
Original:
if ( $rss != "" && $rssFeed = get_rss_feed( $rss ) ) { $rssFeed->enable_order_by_date(false); $maxitems = $rssFeed->get_item_quantity( $feeds ); if ($maxitems == 0) return '<ul><li>Content not available at'.$rss .'.</li></ul>'; $rss_items = $rssFeed->get_items( 0, $maxitems ); $content = '<ul>';New:
if ( $rss != "" && $rssFeed = get_rss_feed( $rss ) ) { if( ! is_wp_error( $rssFeed ) ) { $maxitems = $rssFeed->get_item_quantity(3); $rss_items = $rssFeed->get_items(0, $maxitems); } if($maxitems == NULL) { return '<strong><em>Please forgive the inconvenience. Our product feeds are updating and will return in just a few minutes.</em></strong>'; } else { $rssFeed->enable_order_by_date(false); $maxitems = $rssFeed->get_item_quantity( $feeds ); $rss_items = $rssFeed->get_items( 0, $maxitems ); $content = '<ul>';My non-validated RSS Feeds still pull, and my pages load with the error message when the RSS Feeds fail completely, instead of breaking the page.
The topic ‘Breakage on failed/empty RSS Feeds’ is closed to new replies.