Remove post revisions weekly via WP-Cron

Norcross Dec 18th, 2012functions file

Post revisions are something that, while I’m sure are useful for others, I’ve never found much use for them. They can add unnecessary bloat to the database, and confuse users who aren’t sure what to do with them. I cringe when I start cleaning up an existing site and I find thousands of post revisions in the database. Yes, you can limit or disable them in the config file, or use one of many plugins that will allow you to delete them. But that may be a drastic measure for some folks, who may want them for a short time person, or just one more thing for a user to remember (hint: they won’t).

A way around this is setting a cron job to go and clear out the revisions on a scheduled basis. This will happen in the background, without any user action. The group of functions below will add a new ‘weekly’ schedule for a cron job, then set itself to run on that schedule.

Now, you could go even further and modify the query to look for posts older than a certain date. Either way, this is a quick and easy way to keep things clean.

Comments are closed.