/**
  * Remove all the feed transients attached to our links.  Originally
  * this removed "MagpieRSS" and "SimplePie" feed options/transients by 
  * direct sql.  This had to be changed for VIP compatibility.  
  * 
  * It looks like the SimplePie RSS is the only currently used method for 
  * feed retrieval (on current systems, ie. local environment and most likely
  * VIP platform), so we are looping through the links that are part of FWP's
  * syndication, and clears their transient.
  * 
  * It looks like Magpie's options are stored simply too, so we added
  * support to remove its options/caches as well for any of our links.
  */
 function clear_cache()
 {
     // Set our counters
     $simplepies = $magpies = 0;
     // Grab all our links
     $links = FeedWordPress::syndicated_links();
     if (!empty($links) && is_array($links)) {
         foreach ($links as $link) {
             $link_hash = md5($link->link_rss);
             $magpie_option = 'rss_' . $link_hash;
             if (get_option($magpie_option)) {
                 // It's a MagpieRSS feed, clear the options
                 delete_option($magpie_option);
                 delete_option($magpie_option . '_ts');
                 // clear timestamp as well
                 $magpies++;
             } else {
                 // It's a SimplePie object, use its methods
                 $trans = new WP_Feed_Cache_Transient('', $link_hash, '');
                 $trans->unlink();
                 $simplepies++;
             }
         }
     }
     return $magpies + $simplepies;
 }
/**
 * Checks to see if all of the feed url in $check_urls are cached.
 *
 * If $check_urls is empty, look for the rss feed url found in the dashboard
 * widget optios of $widget_id. If cached, call $callback, a function that
 * echoes out output for this widget. If not cache, echo a "Loading..." stub
 * which is later replaced by AJAX call (see top of /wp-admin/index.php)
 *
 * @since 2.5.0
 *
 * @param string $widget_id
 * @param callback $callback
 * @param array $check_urls RSS feeds
 * @return bool False on failure. True on success.
 */
function wp_dashboard_cached_rss_widget($widget_id, $callback, $check_urls = array())
{
    $loading = '<p class="widget-loading">' . __('Loading&#8230;') . '</p>';
    if (empty($check_urls)) {
        $widgets = get_option('dashboard_widget_options');
        if (empty($widgets[$widget_id]['url'])) {
            echo $loading;
            return false;
        }
        $check_urls = array($widgets[$widget_id]['url']);
    }
    include_once ABSPATH . WPINC . '/class-feed.php';
    foreach ($check_urls as $check_url) {
        $cache = new WP_Feed_Cache_Transient('', md5($check_url), '');
        if (!$cache->load()) {
            echo $loading;
            return false;
        }
    }
    if ($callback && is_callable($callback)) {
        $args = array_slice(func_get_args(), 2);
        array_unshift($args, $widget_id);
        call_user_func_array($callback, $args);
    }
    return true;
}