Snippets

Make CSS drop-down menus work on touch devices

CSS drop-down menus are very popular on sites with a hierarchy of pages. They let you get to where you want to go without having to navigate the pages in that hierarchy. But pure-CSS menus suffer a problem: touch devices often can't show the drop-down, because they don't have "hover" and clicking on the top level link goes there. This snippet offers a way around that.

MySQL backups emailed via Python, cron and cPanel

In a previous post, I outlined how I got my MySQL database backup emailed to me regularly from my shared hosting server. About a week later, I ditched that method because I wanted to change it to send my backups to GMail, but the email headers made those emails look like spam so GMail was ditching them. Instead, I rewrote the backup script in Python.

Extend notification emails in wp-e-commerce

The wp-e-commerce shopping cart plugin is probably the most popular cart plugin for WordPress, but it isn't always the most easily customised; in fact, theming it can be a nightmare. One little niggle I had to fix recently was that the notification emails don't include relevant purchase information such as which shipping method was selected, or the per-item comments from the purchaser (e.g. a message to be included inside a book flap).

Conditionally disable Pages Children in WordPress

Whilst WordPress might be a very easy tool for managing website content, and is making great inroads into the CMS market, it isn't very convenient for editing large numbers of pages on a very large website. That's where the Pages Children plugin comes to the rescue, breaking the page administration lists down into a nice, manageable hierarchy. But it doesn't play nice with another great WordPress plugin, Role Scoper, which is also likely to be installed on large websites. Hooks to the rescue!

MySQL backups emailed via cron and cPanel

If you have a website hosted by a hosting service, and it uses a MySQL database, and you rely on regular backups of that database, maybe you need to handle that yourself. If the database is small enough, it might just pay to have cron email you a backup of the database periodically, which is easy enough to set up on a hosting account with cPanel as the control panel.

Feature sniffing Internet Explorer

Pretty much all web developers should know by now that browser sniffing is evil. If you don't know why, you should definitely read Richard Cornford's excellent treatise Browser Detection (and What to Do Instead). Feature detection, where you look for the specific feature you want to use, is much safer; taken to the extreme, it can end up like the rather clever Modernizr project. But what if you really do just want to know if your code has the misfortune to be running on IE7?

Filter documents in WordPress media library

The WordPress media library has a few nice features for managing uploaded files. One thing it doesn't do is make it easy to find documents. It makes it easy to filter all the files to list only the images, or video, or even audio files, but not documents like PDFs, Word documents, spreadsheets etc. But adding a Documents link to the media library is just a few lines of code away.