Tech Notes: Twitter Widget Pro not updating for Heart Internet users

I’ve had problems with the Twitter Widget Pro WordPress plugin not updating on several sites. I sat down and had a good trawl through the code tonight and it looks like it’s another ‘Heart Attack’ – a case of a Heart Internet feature preventing something from operating correctly.

Don’t get me wrong – I love my Heart Hosting and would highly recommend them, but if you’re hosting WordPress you need to know about this particular thing (and the WP-cron thing too!)

This same issue may apply to other hosts too, I’m not sure. If your Twitter Widget Pro isn’t updating then read on and find out.

Update 1:

Knocked up hastily, and it’s my first foray into modifying other people’s work, so I hope I’ve done a good job, but I’ve put together a modified version of 2.3.8 that fixes the problem, for me at least. I won’t promise to update this when the main plugin gets updated. Discussion seems to be ongoing about whether this issue deserves attention or not.

Heart Internet’s Security Feature

Heart Internet’s security is pretty good. That’s one of the things I like about them. But one of their features is that they don’t allow a website’s server process to make HTTP requests to it’s own website. By this I mean that a PHP script serving a page on the domain http://your-domain.com can not make an HTTP request to anywhere on http://your-domain.com

I’m not entirely sure what this prevents – my guess is that it stops you making a PHP script that calls itself and loops forever.

My Investigation

I’ve had problems with numerous installs of Twitter Widget Pro not updating tweets and I’ve discovered – I think – that it’s all down to a problem with my hosting and the plugin’s use of TLC Transients. This MAY (or may not) also be the cause of other people’s lack of updates.

The behaviour I was seeing was that I appeared to have different versions of my tweet stream “cached” and I could flick between the different cached versions by changing the settings. So, for example, with one lot of widget settings I might see Tweets A, B and C. With a different set of widget settings I would see Tweets C, D and E. Changing the widget’s settings between the two brought up to two different cached lists. BUT…when I posted a new Tweet NEITHER cached list of Tweets got updated.

I checked the database and noted a few timestamps in transient values in there and then went and checked the code.

TWP uses a hash of the widget options as a key for the transient “cache” of fetched Tweets. See line 710 of the plugin in the _getTweets function:

$key = 'twp_' . md5( $this->_getFeedUrl( $widgetOptions ) );

So that explains why different Tweet settings have different cached lists of Tweets, and how I can switch between them.

But why are they never updating?

Well, I’ve not done a too-thorough inspection of the code but TLC transients seems to use a “loopback” URL to fetch the cached list of Tweets without holding up the user – similar to how WP-Cron works. When scheduled it does:

NOW…my hosting company don’t actually allow me to make these “loopback” HTTP requests. So, all my installed instances of TWP are broken.

Options for me seem to be:

The TWP developer make use of TLC Transients optional

I could put some hack in that deletes the transients every now and then. I DO have WP-Cron working (via a Unix cron job), so I could setup a job to clear the transients from the database using that.

I could use another plugin.

I know that TLC Transients is a clever way of making some big efficiencies. And I know that my hosting issue is probably a rare thing. But I could really use some feedback on whether TLC Transients will continue to be used or not, or if I have to consider one of the other options.

Hi, yes all working great now 🙂 Your modified version is fine, WordPress was getting its knickers in a twist and didn’t remove all the old settings, so in the widget area it was still trying to pull in an old feed.

I did change expires_in, in the wp-twitter-widget.php to the example below