Skip to content

Instantly share code, notes, and snippets.

@nathanrice
Last active October 13, 2015 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanrice/a87484f0f82706ef8328 to your computer and use it in GitHub Desktop.
Save nathanrice/a87484f0f82706ef8328 to your computer and use it in GitHub Desktop.
Custom fetch_feed() function
<?php
function cb_fetch_feed( $url ) {
require_once( ABSPATH . WPINC . '/class-feed.php' );
$feed = new SimplePie();
$feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' );
// We must manually overwrite $feed->sanitize because SimplePie's
// constructor sets it before we have a chance to set the sanitization class
$feed->sanitize = new WP_SimplePie_Sanitize_KSES();
$feed->set_cache_class( 'WP_Feed_Cache' );
$feed->set_file_class( 'WP_SimplePie_File' );
$feed->set_feed_url( $url );
$feed->set_stupidly_fast( true );
$feed->init();
$feed->set_output_encoding( get_option( 'blog_charset' ) );
$feed->handle_content_type();
if ( $feed->error() )
return new WP_Error( 'simplepie-error', $feed->error() );
return $feed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment