Snippets

sessionStorage with expiry time

Session storage is a very handy tool for caching content fragments retrieved via AJAX. Once we've pulled the content once, and stuffed it into session storage, we can access it again quickly without the overhead of a round trip to the server. But what if we want to limit the age of that content, so that it expires before it gets too stale?

WooCommerce quantity fields without spinners

WooCommerce uses HTML5 number fields for shop quantities, because they restrict the characters you can enter, and Safari on iPad/iPhone conveniently shows the number keyboard. Webkit and Opera/Presto add spinners (up/down arrows) to HTML5 number fields. WooCommerce also adds +/- buttons surrounding qty fields, because IE and Firefox don't add spinners. WooCommerce then uses CSS to hide the spinners on Webkit:

Use WP Migrate DB Pro and keep your development environment settings

I've been using the fabulous WP Migrate DB Pro since June; it makes it really easy to duplicate the data from one WordPress website onto another, something that developers need to do frequently, and it handles the problems of moving serialised data from one server to another without breaking it. When pulling data from a production server to a development or test environment, it also (by design) replaces all your settings, which might mean that test emails go to your clients -- can anyone say, "Dear Rich Bastard?" Thankfully, it also offers a couple of save-your-backside solutions.

Replace query argument pagination with WordPress paged pretty URLs

When integrating non-WordPress PHP software into WordPress, sometimes the two butt heads over little things; pagination is one such thing. WordPress likes to move pagination into the pretty URL and out of query parameters. If your non-WordPress software generates content with URLs that have page= in query parameters, that means a redirect each time such a URL is fetched. A little regular expression magic can help fix that, with some assembly required.

WordPress WP_DEBUG_LOG without E_STRICT

As Debugging in WordPress explains, it's easy to get good debugging information into a debug.log file while developing WordPress plugins and themes. Unfortunately, it sets the PHP error reporting level to E_ALL, which includes E_STRICT and can throw so much noise into the log that you can't find the useful information. What we need is a way to turn on the debug log but specify the error reporting level.

WooCommerce add to cart with quantity and AJAX

WooCommerce is a great e-commerce plugin for WordPress. It has some very nice basic features, but it's also easy to customise and extend. On single product pages, you can add to cart with a quantity other than just one, and on the purchase page you can add to cart via AJAX without leaving the page. Wouldn't it be nice to add to cart with both quantity and AJAX?

Events Manager Pro and required user fields

Events Manager + Events Manager Pro is a great plugin team for taking bookings for events on WordPress websites. One hitch I've struck is that if you as webmaster need to edit a user, and the user hasn't filled in all their details, Events Manager Pro won't let you save without filling in all of its required fields (basically, address details). And of course, the chances are that you won't know what those fields should contain.

Stop users from submitting Gravity Forms form twice

A common problem with input forms is that users get impatient and click the submit button twice. This can lead to double (or triple, or quadruple!) form submissions, which can really mess things up (especially if you've added a billing step to your form!) Stopping it can be surprisingly complex, but here's a simple piece of browser script that will prevent most users from making multiple submissions with Gravity Forms.