How to delete transients written by fetch_feed()?

I’m using fetch_feed() to cache external rss sources displayed in a widget. in case the widget (or, more likely, the whole plugin) is deleted/deactivated, i want to manually delete all related transients.

In class-feed.php $filename is passed to the constructor of WP_Feed_Cache_Transient{}, which obviously handles the transients for fetch_feed. I just havent figured out how the variable is generated to store it with the widgets for later delete actions.

1 Answer
1

This data should be automatically deleted after 12 hours, that’s the default feed cache TTL.

So this kind of house cleaning, for data added by the WordPress transients API, might be unnecessary.

But let’s check out what kind of data is stored.

If you take for example the feed for your current question:

http://wordpress.stackexchange.com/feeds/question/172444

and fetch it with:

$feed = fetch_feed( 'http://wordpress.stackexchange.com/feeds/question/172444' );

then you would get 4 rows in the wp_options table:

  1. _transient_feed_mod_89d724e05be3479dcbee0fd481470c97
  2. _transient_timeout_feed_mod_89d724e05be3479dcbee0fd481470c97
  3. _transient_feed_89d724e05be3479dcbee0fd481470c97
  4. _transient_timeout_feed_89d724e05be3479dcbee0fd481

The _transient_timeout_* rows are automatically added by WordPress to know when to delete the transients.

Notice that:

echo $md5_of_feed_url = md5( 'http://wordpress.stackexchange.com/feeds/question/172444' );

is

89d724e05be3479dcbee0fd481470c97

So you would need to know the md5 of the feed url, to remove this data with the delete_transient() function:

delete_transient( 'feed_'     . $md5_of_feed_url ); 
delete_transient( 'feed_mod_' . $md5_of_feed_url ); 

Leave a Comment