Category Archives: Wordpress

Transients are a great tool for the WordPress developer. They allow you to easily save temporary data with their own expiry time – simply pass the transients data into the easy-to-use API and it will sort everything out for you. Caching made simple.

Unfortunately, using transients is not without its downsides and recent experiences have shown a couple of issues that any developer should be aware of.

But first I need to explain how transients work.

Transients were not introduced until version 2.8 of WordPress and make use of the WordPress options table (usually named wp_options) to store their data. There aren’t enough fields in this table for the transients to be stored as one record so, instead, it’s split over 2.

Each transient is given, by the developer, a unique name. This is prefixed by either _transient_ or _transient_timeout_ and used as the option_name field. The option_value field is the transient value and the expiry time respectively. You can also store and access network wide transients and these have _site further prefixed to the beginning of the transient name.

So, let’s say you create a transient named ‘test’. Two records will be added to your options table. The first record will be named _transient_test and will have a value of whatever you wished to store in the transient. The second record will be named _transient_timeout_test and the value will be the timestamp of when it expires.

The exception to this rule is if you create a transient that is not set to timeout. In this case only the first record will be created.

If you were creating a network-wide transient then the names would be  _site_transient_test and _site_transient_timeout_test.

How to use Transients

There are 3 simple commands – set_transient, get_transient and delete_transient. The latter two have just one parameter – the transient name.

set_transient, in comparison, has 3 parameters – the transient name, the contents to store and the timeout (in seconds). Set the timeout to 0 for it to never expire.

set_transient and delete_transient both return true or false, depending on their success. get_transient returns the transient content or false if it wasn’t found.

Network-wide transients are handled by the commands set_site_transient, get_site_transient and delete_site_transient. All parameters and return values are as the non-network equivalent.

Problem #1: Transient Name Lengths

The option_name field in the options table has a record length of 64 characters. So, taking into account the prefixes added to the transient name, a transient name can only be a maximum of 45 characters (or 40 characters for network transients). The problem here is that WordPress doesn’t check. It doesn’t fail either – it creates the transients but simply truncates the name. And because each of the transient record pairs has a different length prefix then they each end up with a different name – this means the transient can’t be retrieved.

The Solution

  • WordPress are aware of this and a Trac ticket is open to prevent this from happening. I have updated the ticket myself to ensure they’re aware of the 40 limit for network transients (suggesting that the limit should be a uniform 40 to avoid confusion).
  • The Codex already makes mention of the 45 character limit for set_transient but didn’t mention the 40 limit for set_site_transient. I have now updated the appropriate page to reflect this.

Problem #2: Housekeeping

When you attempt to get a transient and it’s expired WordPress will automatically remove that transient from the table. However, if that transient is never accessed again then it will not be removed.

Why would this happen? Let’s say a plugin uses transients to cache some data. The transient name may be a unique name which represents the options requested – that way, if the user changes the options the, now incorrect, cached data is not used. However, the old transient will never be re-accessed.

To give you an idea of the scale of this I’ve heard one user has over 250,000 transients in his database which have expired.

The Solution

Conclusion

Transients are a powerful and useful tool for the WordPress developer. However, be aware of their limitations and tread carefully!

I’m one of those who are guilty of writing plugins that generate transient names longer than the limit and of generating transients that won’t be accessed once they’ve expired. Now I know all of the above the way I use the transient system has changed.

VineI’m happy to announce the release of a new WordPress plugin – Artiss Vine Embed.

Just days after Vine released details of how to embed one of their videos into a site, this plugin makes the experience incredibly easy. With both a shortcode for embedding into posts and pages as well as a widget for sidebars it couldn’t be easier.

I’m already working on the next release which will introduce a simple administration screen for setting default options. After that expect responsive video options, amongst other things.

Remarkably this plugin wasn’t the first at WordPress.org to introduce Vine videos (beaten by 2 days!) but it’s already the most feature rich.

Recently my WordPress plugin, Artiss YouTube Embed, was bought by a third party – a company named Applian Technologies Inc. They wanted the existing user base to help promote their video software products.

What happened, unsurprisingly, was that the plugin was re-branded and released with links to their site. This included a “download bar” – a series of 3 links which appear under each video. This was switched on by default but could be easily switched off in the settings screen.

The first 2 links allow you to easily download the video and convert it to MP3. The last link was to the companies product page (initially this wasn’t a nofollow link but I advised the company to add this in so they don’t affect user’s SEO). To add benefit they’ve create an affiliate scheme – simply sign up and enter your affiliate ID and you can make 30% off any sales generated from this link. I’ve done just that and have left this download bar on.

By adding their own corporate identity to the plugin – still provided free of charge and supported – they were able to take off my administrator side advertising, as well as requests for donations, etc, that were in the instructions.

Unfortunately, it’s been met with complaints. And they’re not mild either. Some advised people to avoid the plugin at all costs because of the supposed “under-handed” way this has happened.

One user got particularly vocal complaining that it broke WordPress guidelines and had complained, asking others to do the same too. The result – on Friday the plugin was removed from WordPress.org. No-one told Applian that this had happened, however they’d already contacted WordPress pro-actively to see if there was any merit in the complaints. They were told it broke the rules but it’s not clear. Indeed, they received replies from 2 different staff at WordPress and were given different answers. If begs the question – if they can’t decided amongst themselves, how are we supposed to interpret it? Here’s the guidelines it’s apparently fallen foul of…

The plugin must not embed external links on the public site (like a “powered by” link) without explicitly asking the user’s permission.

So if your plugin is designed to add links to a site and it does so once activated, does this break their guidelines? If this is the case then there’s a LOT of plugins that should be removed. including their own Jetpack plugin. I understand it for the commercial link but the rather useful “Download the video” link? If, as a developer, we want to add something later that we think would be beneficial, we have to leave it switched off and hope the users bother to switch it on? Basically, it’s a bit “fuzzy”. Applian are now changing the plugin to be “opt in” in future but are making changes elsewhere to promote the links further.

But, personally, I don’t get the complaints. It adds some links, which you can switch off. Ok, that last one broke guidelines and was removed. The addition of the links, though, are mentioned in the change log and shown in the screenshots – it’s hardly been hidden. I’m not sure what people want – a high quality plugin for free, with free support and they’re surprised when the developer adds something to promote their company?

Also, I’m shocked by the surprise some of these users are expressing at finding these links. They’re running a website, which they say is important, but happily update plugins, ignoring the change log, and obviously don’t test on them on their site beforehand (after all plugins can cause websites to break) and then complain at some supposed “under hand” sneaky tactic. 

In the meantime, I think there are some people who need to wind their neck inOf course, all of this are my own opinion and not those of the new owners, who have been remarkable good about it, answering all complaints and even asking for assistance on improving wording, etc, to avoid mis-understanding. Probably not surprisingly no-one has offered to help them – I’ve always been of the opinion that you shouldn’t complain about something unless you’re prepared to offer alternatives.

Update 1

The above has been modified as half was written before some of the events occurred, and the other afterwards. As a result the post was a bit inconsistent so has been re-worded to more accurately reflect my own, eventual, feelings on the subject.

Artiss.co.uk website screenshotThis has been a great year for Artiss.co.uk. It kicked off with a spanking new design, provided by Solostream and heavily modified by myself.

I’d also like to take this opportunity to mention my hosting company, Tsohost, who have been fantastic. They’re the first value-for-money host that I’ve come across that are actually any good. Their support is brilliant and I’ve hardly had any down-time.

Visitor rates are up, thanks particularly to the regular competitions that have been run. The buy cialis online competitions are run via my own software, and I’ve made some major changes to this in the last few months, keeping away from those pesky spammers but also ensuring accuracy of the information captured (there’s nothing worse than not being unable to get hold of a prize winner!).

There have been 155 published articles 2012 (at the time of writing this, and not including this one). That works out at 5 every 12 days – not bad, considering they were virtually all written by me ;) 57 of those articles were reviews.

Top 5 Articles

The top 5 articles written in 2012 were…

  1. Installing CyanogenMod 7 on a Lenovo A1
  2. ProductTesting.uk.com and why you should avoid them
  3. How to Change the Samsung Galaxy S2′s Volume Settings
  4. The Problem with Samsung Kies
  5. Raspberry Pi Case Review
  6. Ecocamel Jetstorm Shower Head Review

The top 5 articles of 2012, but written before 2012, were…

  1. Samsung NP300E5A-A01DX Laptop Review
  2. How To Use the Android 4 Roboto Font On Your Website
  3. Creative WP-300 Bluetooth Headphones review
  4. Creative Zen Style M300 review
  5. Tracking Internet Usage on Android

2013

For the last few years a new year has brought about another design change – for 2013 this won’t be the case as I’m more than happy with the site. However, that isn’t to say changes aren’t afoot.

My work with WordPress – in particular the plugins that I write – sit uneasily on the site alongside the product reviews. However, they bring in a lot of visitors to the site. Never-the-less, my mind has been made up – in 2013 they will be split. I’ll be launching a new, sister site soon that will house all my WordPress plugins, the matching support forum, etc. This will allow each site to target the appropriate audience (this site is mainly aimed at the UK, whereas my plugins are world-wide).

This will bring down visitor rates to this site and make it less attractive to advertisers. However, due to my restrictive conditions on advertising I doubt that will change much – companies are only interested in getting their product promoted, no matter what the cost to the site that does the promotion for them. This is not acceptable to me so I will continue to push people away unless it’s fair to all parties.

Artiss.co.uk will also get a spring clean once the appropriate WordPress sections of the site are moved – with lots of “tweaks” over the year a few bugs and visual issues have occurred on the site which will get resolved in one big go.

2013 will definitely see a review of the Nexus 4 (as mine is on order) and I’ll get around to reviewing my Nexus 7. But that’s about as much as I can guarantee, article wise.

And Finally…

So that’s my review of this year and a sneak preview as to what’s coming up. I hope everyone has a great 2013.

A number of my WordPress plugins make use of transients to cache data. However, I’ve had a number of people – mainly relating to Artiss YouTube Embed – highlight the large number of entries this is creating in their Options table. In the case of that plugin I implemented an option that allowed you to clear old transients down and even list the number stored.

Today I had a chance to investigate it further and found a large number of transients that had expired still in my Options table.

So I did what any good WordPress developer would do – went staight to “the horses mouth”. In this case, WordPress Core developer Andrew Nacin.

He confirmed my suspicions – that WordPress doesn’t housekeep transients unless you attempt to access them and they’ve expired. In other words, if you don’t access it then the expired transient remains. In the case of YouTube Embed the transient name is based upon the video parameters – so if you change an option it will generate a new transient name (as it should – you want the video code to update if you’ve changed one of the parameters). Unfortunately, the previous one is no longer accessed and, hence, never gets deleted.

Thankfully, there is hope on the cialis sale horizon – a WordPress ticket is already open to add better housekeeping and Andrew has asked me to nudge him in January so that he can get it included in WordPress 3.6. I’ll certainly be doing that.

Update 1

Rather than be patient and wait for the change I have, instead, created a plugin that will do exactly what was proposed in the aforementioned ticket. I’ve also taken an opportunity to improve on it further by optimising the Options table each time housekeeping is performed.

Top
%d bloggers like this: