Last active
October 13, 2015 17:46
-
-
Save nathanrice/a87484f0f82706ef8328 to your computer and use it in GitHub Desktop.
Custom fetch_feed() function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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