fetch_feed

The timeline below displays how wordpress function fetch_feed has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Builds SimplePie object based on RSS or Atom feed from URL.
 *
 * @since 2.8.0
 *
 * @param string|string[] $url URL of feed to retrieve. If an array of URLs, the feeds are merged
 *                             using SimplePie's multifeed feature.
 *                             See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
 * @return SimplePie|WP_Error SimplePie object on success or WP_Error object on failure.
 */
function fetch_feed($url)
{
    if (!class_exists('SimplePie', false)) {
        require_once ABSPATH . WPINC . '/class-simplepie.php';
    }
    require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.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();
    // Register the cache handler using the recommended method for SimplePie 1.3 or later.
    if (method_exists('SimplePie_Cache', 'register')) {
        SimplePie_Cache::register('wp_transient', 'WP_Feed_Cache_Transient');
        $feed->set_cache_location('wp_transient');
    } else {
        // Back-compat for SimplePie 1.2.x.
        require_once ABSPATH . WPINC . '/class-wp-feed-cache.php';
        $feed->set_cache_class('WP_Feed_Cache');
    }
    $feed->set_file_class('WP_SimplePie_File');
    $feed->set_feed_url($url);
    /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
    $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
    /**
     * Fires just before processing the SimplePie feed object.
     *
     * @since 3.0.0
     *
     * @param SimplePie       $feed SimplePie feed object (passed by reference).
     * @param string|string[] $url  URL of feed or array of URLs of feeds to retrieve.
     */
    do_action_ref_array('wp_feed_options', array(&$feed, $url));
    $feed->init();
    $feed->set_output_encoding(get_option('blog_charset'));
    if ($feed->error()) {
        return new WP_Error('simplepie-error', $feed->error());
    }
    return $feed;
}

WordPress Version: 6.1

/**
 * Builds SimplePie object based on RSS or Atom feed from URL.
 *
 * @since 2.8.0
 *
 * @param string|string[] $url URL of feed to retrieve. If an array of URLs, the feeds are merged
 *                             using SimplePie's multifeed feature.
 *                             See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
 * @return SimplePie|WP_Error SimplePie object on success or WP_Error object on failure.
 */
function fetch_feed($url)
{
    if (!class_exists('SimplePie', false)) {
        require_once ABSPATH . WPINC . '/class-simplepie.php';
    }
    require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.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();
    // Register the cache handler using the recommended method for SimplePie 1.3 or later.
    if (method_exists('SimplePie_Cache', 'register')) {
        SimplePie_Cache::register('wp_transient', 'WP_Feed_Cache_Transient');
        $feed->set_cache_location('wp_transient');
    } else {
        // Back-compat for SimplePie 1.2.x.
        require_once ABSPATH . WPINC . '/class-wp-feed-cache.php';
        $feed->set_cache_class('WP_Feed_Cache');
    }
    $feed->set_file_class('WP_SimplePie_File');
    $feed->set_feed_url($url);
    /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
    $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
    /**
     * Fires just before processing the SimplePie feed object.
     *
     * @since 3.0.0
     *
     * @param SimplePie       $feed SimplePie feed object (passed by reference).
     * @param string|string[] $url  URL of feed or array of URLs of feeds to retrieve.
     */
    do_action_ref_array('wp_feed_options', array(&$feed, $url));
    $feed->init();
    $feed->set_output_encoding(get_option('blog_charset'));
    if ($feed->error()) {
        return new WP_Error('simplepie-error', $feed->error());
    }
    return $feed;
}

WordPress Version: 5.8

/**
 * Build SimplePie object based on RSS or Atom feed from URL.
 *
 * @since 2.8.0
 *
 * @param string|string[] $url URL of feed to retrieve. If an array of URLs, the feeds are merged
 *                             using SimplePie's multifeed feature.
 *                             See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
 * @return SimplePie|WP_Error SimplePie object on success or WP_Error object on failure.
 */
function fetch_feed($url)
{
    if (!class_exists('SimplePie', false)) {
        require_once ABSPATH . WPINC . '/class-simplepie.php';
    }
    require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.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();
    // Register the cache handler using the recommended method for SimplePie 1.3 or later.
    if (method_exists('SimplePie_Cache', 'register')) {
        SimplePie_Cache::register('wp_transient', 'WP_Feed_Cache_Transient');
        $feed->set_cache_location('wp_transient');
    } else {
        // Back-compat for SimplePie 1.2.x.
        require_once ABSPATH . WPINC . '/class-wp-feed-cache.php';
        $feed->set_cache_class('WP_Feed_Cache');
    }
    $feed->set_file_class('WP_SimplePie_File');
    $feed->set_feed_url($url);
    /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
    $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
    /**
     * Fires just before processing the SimplePie feed object.
     *
     * @since 3.0.0
     *
     * @param SimplePie       $feed SimplePie feed object (passed by reference).
     * @param string|string[] $url  URL of feed or array of URLs of feeds to retrieve.
     */
    do_action_ref_array('wp_feed_options', array(&$feed, $url));
    $feed->init();
    $feed->set_output_encoding(get_option('blog_charset'));
    if ($feed->error()) {
        return new WP_Error('simplepie-error', $feed->error());
    }
    return $feed;
}

WordPress Version: 5.6

/**
 * Build SimplePie object based on RSS or Atom feed from URL.
 *
 * @since 2.8.0
 *
 * @param string|string[] $url URL of feed to retrieve. If an array of URLs, the feeds are merged
 *                             using SimplePie's multifeed feature.
 *                             See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
 * @return SimplePie|WP_Error SimplePie object on success or WP_Error object on failure.
 */
function fetch_feed($url)
{
    if (!class_exists('SimplePie', false)) {
        require_once ABSPATH . WPINC . '/class-simplepie.php';
    }
    require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.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();
    // Register the cache handler using the recommended method for SimplePie 1.3 or later.
    if (method_exists('SimplePie_Cache', 'register')) {
        SimplePie_Cache::register('wp_transient', 'WP_Feed_Cache_Transient');
        $feed->set_cache_location('wp_transient');
    } else {
        // Back-compat for SimplePie 1.2.x.
        require_once ABSPATH . WPINC . '/class-wp-feed-cache.php';
        $feed->set_cache_class('WP_Feed_Cache');
    }
    $feed->set_file_class('WP_SimplePie_File');
    $feed->set_feed_url($url);
    /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
    $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
    /**
     * Fires just before processing the SimplePie feed object.
     *
     * @since 3.0.0
     *
     * @param SimplePie       $feed SimplePie feed object (passed by reference).
     * @param string|string[] $url  URL of feed or array of URLs of feeds to retrieve.
     */
    do_action_ref_array('wp_feed_options', array(&$feed, $url));
    $feed->init();
    $feed->set_output_encoding(get_option('blog_charset'));
    if ($feed->error()) {
        return new WP_Error('simplepie-error', $feed->error());
    }
    return $feed;
}

WordPress Version: 5.4

/**
 * Build SimplePie object based on RSS or Atom feed from URL.
 *
 * @since 2.8.0
 *
 * @param string|string[] $url URL of feed to retrieve. If an array of URLs, the feeds are merged
 *                             using SimplePie's multifeed feature.
 *                             See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
 * @return SimplePie|WP_Error SimplePie object on success or WP_Error object on failure.
 */
function fetch_feed($url)
{
    if (!class_exists('SimplePie', false)) {
        require_once ABSPATH . WPINC . '/class-simplepie.php';
    }
    require_once ABSPATH . WPINC . '/class-wp-feed-cache.php';
    require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.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);
    /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
    $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
    /**
     * Fires just before processing the SimplePie feed object.
     *
     * @since 3.0.0
     *
     * @param SimplePie       $feed SimplePie feed object (passed by reference).
     * @param string|string[] $url  URL of feed or array of URLs of feeds to retrieve.
     */
    do_action_ref_array('wp_feed_options', array(&$feed, $url));
    $feed->init();
    $feed->set_output_encoding(get_option('blog_charset'));
    if ($feed->error()) {
        return new WP_Error('simplepie-error', $feed->error());
    }
    return $feed;
}

WordPress Version: 5.1

/**
 * Build SimplePie object based on RSS or Atom feed from URL.
 *
 * @since 2.8.0
 *
 * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged
 * using SimplePie's multifeed feature.
 * See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
 *
 * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success
 */
function fetch_feed($url)
{
    if (!class_exists('SimplePie', false)) {
        require_once ABSPATH . WPINC . '/class-simplepie.php';
    }
    require_once ABSPATH . WPINC . '/class-wp-feed-cache.php';
    require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.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);
    /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
    $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
    /**
     * Fires just before processing the SimplePie feed object.
     *
     * @since 3.0.0
     *
     * @param object $feed SimplePie feed object (passed by reference).
     * @param mixed  $url  URL of feed to retrieve. If an array of URLs, the feeds are merged.
     */
    do_action_ref_array('wp_feed_options', array(&$feed, $url));
    $feed->init();
    $feed->set_output_encoding(get_option('blog_charset'));
    if ($feed->error()) {
        return new WP_Error('simplepie-error', $feed->error());
    }
    return $feed;
}

WordPress Version: 4.9

/**
 * Build SimplePie object based on RSS or Atom feed from URL.
 *
 * @since 2.8.0
 *
 * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged
 * using SimplePie's multifeed feature.
 * See also {@link ​http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
 *
 * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success
 */
function fetch_feed($url)
{
    if (!class_exists('SimplePie', false)) {
        require_once ABSPATH . WPINC . '/class-simplepie.php';
    }
    require_once ABSPATH . WPINC . '/class-wp-feed-cache.php';
    require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.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);
    /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
    $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
    /**
     * Fires just before processing the SimplePie feed object.
     *
     * @since 3.0.0
     *
     * @param object $feed SimplePie feed object (passed by reference).
     * @param mixed  $url  URL of feed to retrieve. If an array of URLs, the feeds are merged.
     */
    do_action_ref_array('wp_feed_options', array(&$feed, $url));
    $feed->init();
    $feed->set_output_encoding(get_option('blog_charset'));
    if ($feed->error()) {
        return new WP_Error('simplepie-error', $feed->error());
    }
    return $feed;
}

WordPress Version: 7.1

/**
 * Build SimplePie object based on RSS or Atom feed from URL.
 *
 * @since 2.8.0
 *
 * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged
 * using SimplePie's multifeed feature.
 * See also {@link ​http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
 *
 * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success
 */
function fetch_feed($url)
{
    if (!class_exists('SimplePie', false)) {
        require_once ABSPATH . WPINC . '/class-simplepie.php';
    }
    require_once ABSPATH . WPINC . '/class-wp-feed-cache.php';
    require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.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);
    /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
    $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
    /**
     * Fires just before processing the SimplePie feed object.
     *
     * @since 3.0.0
     *
     * @param object &$feed SimplePie feed object, passed by reference.
     * @param mixed  $url   URL of feed to retrieve. If an array of URLs, the feeds are merged.
     */
    do_action_ref_array('wp_feed_options', array(&$feed, $url));
    $feed->init();
    $feed->set_output_encoding(get_option('blog_charset'));
    if ($feed->error()) {
        return new WP_Error('simplepie-error', $feed->error());
    }
    return $feed;
}

WordPress Version: 4.7

/**
 * Build SimplePie object based on RSS or Atom feed from URL.
 *
 * @since 2.8.0
 *
 * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged
 * using SimplePie's multifeed feature.
 * See also {@link ​http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
 *
 * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success
 */
function fetch_feed($url)
{
    if (!class_exists('SimplePie', false)) {
        require_once ABSPATH . WPINC . '/class-simplepie.php';
    }
    require_once ABSPATH . WPINC . '/class-wp-feed-cache.php';
    require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php';
    require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.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);
    /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
    $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
    /**
     * Fires just before processing the SimplePie feed object.
     *
     * @since 3.0.0
     *
     * @param object &$feed SimplePie feed object, passed by reference.
     * @param mixed  $url   URL of feed to retrieve. If an array of URLs, the feeds are merged.
     */
    do_action_ref_array('wp_feed_options', array(&$feed, $url));
    $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;
}

WordPress Version: 4.3

/**
 * Build SimplePie object based on RSS or Atom feed from URL.
 *
 * @since 2.8.0
 *
 * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged
 * using SimplePie's multifeed feature.
 * See also {@link ​http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
 *
 * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success
 */
function 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);
    /** This filter is documented in wp-includes/class-feed.php */
    $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
    /**
     * Fires just before processing the SimplePie feed object.
     *
     * @since 3.0.0
     *
     * @param object &$feed SimplePie feed object, passed by reference.
     * @param mixed  $url   URL of feed to retrieve. If an array of URLs, the feeds are merged.
     */
    do_action_ref_array('wp_feed_options', array(&$feed, $url));
    $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;
}

WordPress Version: 3.9

/**
 * Build SimplePie object based on RSS or Atom feed from URL.
 *
 * @since 2.8.0
 *
 * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged
 * using SimplePie's multifeed feature.
 * See also {@link ​http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
 *
 * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success
 */
function 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);
    /** This filter is documented in wp-includes/class-feed.php */
    $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
    /**
     * Fires just before processing the SimplePie feed object.
     *
     * @since 3.0.0
     *
     * @param object &$feed SimplePie feed object, passed by reference.
     * @param mixed  $url   URL of feed to retrieve. If an array of URLs, the feeds are merged.
     */
    do_action_ref_array('wp_feed_options', array(&$feed, $url));
    $feed->init();
    $feed->handle_content_type();
    if ($feed->error()) {
        return new WP_Error('simplepie-error', $feed->error());
    }
    return $feed;
}

WordPress Version: 3.7

/**
 * Build SimplePie object based on RSS or Atom feed from URL.
 *
 * @since 2.8
 *
 * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged
 * using SimplePie's multifeed feature.
 * See also {@link ​http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
 *
 * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success
 */
function 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_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
    do_action_ref_array('wp_feed_options', array(&$feed, $url));
    $feed->init();
    $feed->handle_content_type();
    if ($feed->error()) {
        return new WP_Error('simplepie-error', $feed->error());
    }
    return $feed;
}