Skip to content

Instantly share code, notes, and snippets.

@cgrymala
Last active December 17, 2015 05:38
Show Gist options
  • Save cgrymala/7f873100bdba7dde47a3 to your computer and use it in GitHub Desktop.
Save cgrymala/7f873100bdba7dde47a3 to your computer and use it in GitHub Desktop.
Instantiating a SimplePie object in WordPress
/* Create the SimplePie object */
$this->feed = new SimplePie();
/* Set the URL of the feed you're retrieving */
$this->feed->set_feed_url( $this->source );
/* Tell SimplePie to cache the feed using WordPress' cache class */
$this->feed->set_cache_class( 'WP_Feed_Cache' );
/* Tell SimplePie to use the WordPress class for retrieving feed files */
$this->feed->set_file_class( 'WP_SimplePie_File' );
/* Tell SimplePie how long to cache the feed data in the WordPress database */
$this->feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 43200, $this->source ) );
/* Run any other functions or filters that WordPress normally runs on feeds */
do_action_ref_array( 'wp_feed_options', array( &$this->feed, $this->source ) );
/* Initiate the SimplePie instance */
$this->feed->init();
/* Tell SimplePie to send the feed MIME headers */
$this->feed->handle_content_type();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment