1

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

7

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 ); 
10
  • 1
    Thanks @birgire for explaining it in detail. I learn more here everyday than any other place. :)
    – Robert hue
    Dec 16, 2014 at 18:22
  • 1
    Thanks @Roberthue, you're welcome. I'm also learning lots of great stuff from this site everyday, this is a great place for WordPress devs ;-)
    – birgire
    Dec 16, 2014 at 18:32
  • thanks @birgire – exactly the answer i was looking for! one more question: does transient_feed_mod* contain the timestamp the feed was fetched? Dec 16, 2014 at 19:00
  • 1
    great. yes, it contains the value of time(), i.e. the Unix timestamp. I updated the answer with the corresponding delete functions.
    – birgire
    Dec 16, 2014 at 19:38
  • as i see now, in case you pass an array to fetch_feed(), for each element (preferably containing an url) these four transients are generated separately. Dec 16, 2014 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.