WordPress Tutorial: Managing WordPress Auto-save and Post Revision Control

Teli Adlam —  August 4, 2008

WordPress Revisions Example One of the hot new features of 2.6 is post/page revision management. This is a splendid feature for multi-author blogs because it allows you to see what was changed in a post, by whom and when. Unfortunately, this is a bit overboard for single author bloggers who truly don’t need to keep a running tally of every single revision.

Since WordPress developers didn’t disable this feature by default or provide a distinct option under Settings, it will require a bit of file editing or installation of a plugin to properly manage.

Disabling or Limiting Post Revision Control

There is a section in the Codex which deals with the revision management, but for someone who is not well versed in structuring PHP statements or setting constant variables, it falls into the not particularly helpful category. That’s where this tutorial comes in.

Before we get started, you’ll be making edits to your wp-config.php file, so it’s important for you to make a back up copy and save it in a safe place. Also, make sure that you edit the file only using a plain text editor (such as Notepad) or an editor developed specifically for HTML/PHP editing (such as Dreamweaver in code view). With that out of the way, let’s get started.

Completely Disable Post Revisions

If you’d rather not have to deal with any revisions at all, then you can completely disable the feature by adding the following code in your wp-config.php file–just make sure it falls between the opening ‘<?php‘ and closing ‘?>‘.*

define('WP_POST_REVISIONS',false);

Limit the Number of Saved Revisions

Now, if you’d rather have some level of revision management, but would like to limit the number of revisions saved. Rather than using ‘false’, simply add the number of revisions you’d like to have saved–old revisions beyond the number specified will simply be deleted. Again, this code is to be placed somewhere between the opening <?php and closing ?>.*

define('WP_POST_REVISIONS',6);

Now, to be certain, this will not fix the post ID issue if you’re averse to having it climb each time a new revision is saved. This is more along the lines of saving storage space.

*As a general rule of thumb, I add any preference changes just before the closing ‘?>‘ with a comment about what the function does.

Example:
<?php
>>WP config file stuff
/* DISABLE POST REVISIONS */
define('WP_POST_REVISIONS',false);
?>

Disabling Post Revisions with a Plugin

In general, I don’t recommend plugins unless it’s completely necessary. But, if you don’t feel like mucking around with PHP or your files, then you can also turn off your post revisions with a handy little plugin.

Actually, it’s three little plugins. You have the option of downloading the disable auto-save (not entirely recommended), disable post revisions, or disable both (again, not entirely recommended) plugins.

Understanding Revision Control and Auto-save

Revision control basically tracks the changes made to a post and saves previous versions for you to revert back to if necessary. Auto-save just saves the post periodically so you don’t loose the content should a catastrophe happen, like your browser freezing or your computer randomly shutting down, prior to manually saving.

While each revision is stored in its own database table, the auto-save is only stored once with previous versions being overwritten by the new auto-saved content. So, if you’re worried about your database growing to massive proportions because of auto-save, you can stop worrying. And trust me, auto-save is not a feature you want to disable; it only takes one arduously crafted blog post lost into the ether for you figure that out. :)

One option, rather than completely disabling the feature, is to reset the frequency. By default, WordPress will auto-save a post every minute (60 seconds). To delay this, simply add the following code to your wp-config.php file:

define('AUTOSAVE_INTERVAL',600);

The number, 600 in the example, represents the number of seconds WordPress should wait between auto-saves. So, the above example would set WordPress to auto-save the post every 10 minutes.

Deleting Excess Post Revisions

Chances are you’ve already upgraded to the latest version of WordPress and made a whole lot of edits to some of your previous blog entries which resulted in a database filled with revisions. Basically, your DB has fluffy data that isn’t quite necessary and you’re wondering how to get rid of it.

Well, with a quick and dirty DB query of course. Please note, this should not be attempted if you do not feel comfortable running DB queries in any way and you should always make a back up and test the query first before actually deleting anything.

(This tutorial assumes you’ll be using phpMyAdmin as your MySQL manager.)

Step 1: Log into your phpMyAdmin panel
Step 2: Click on the SQL tab which should bring you to a page with the SQL query box
Step 3: Type the following query (courtesy of Andrei Neculau), making the appropriate changes for your WP installation’s table prefix, and hit the Go button:
DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID=b.object_id) LEFT JOIN wp_postmeta c ON (a.ID=c.post_id) WHERE a.post_type='revision';

SQL query example

Bear in mind that this will delete all revisions from every post including all of its meta data.

Teli Adlam

Posts

16 responses to WordPress Tutorial: Managing WordPress Auto-save and Post Revision Control

  1. Why don’t you like plugins? It seems a better approach to handlethe problem than directly editing the WP files which get overwritten when upgrading.

    of course BEST option is for WordPress to just fix this and offer native settings to handle.

  2. Why don’t you like plugins? It seems a better approach to handlethe problem than directly editing the WP files which get overwritten when upgrading.

    Let me respond to the second part of your statement first: In this particular case, the file should not be overwritten if the upgrade is handled properly. The wp-config.php is one of the files which should remain intact throughout every upgrade of WordPress. If WP makes any changes to that file in future versions, then those changes need to be transferred to your original wp-config.php file before upgrading, however, it should not be overwritten to start fresh.

    As for the reason I don’t necessarily recommend plugins in every situation is because it’s too easy for it to become too many plugins to reasonably manage. Plugins are a bit riskier because some may not be coded well and use too many resources and some may not even be properly maintained so they’re broken and useless when upgrading. If the blogger has become too dependent on the plugin, what will become of the blog when the plugin is deactivated?

    I’m not an advocate for not using any plugins–this blog is running more than a few–merely an advocate for choosing the plugins you use wisely. If it can be easily done without modifying WP core files (which are the ones overwritten in an upgrade), I recommend that route over installing a plugin. ;)

    ~ Teli

  3. Thanks for posting this great information. I only have one minor nit pick on your otherwise excellent instructions. Note the typo error in excerpt from above where:

    “define(‘WP_POST_REVISION’,false);”

    should be:

    “define(‘WP_POST_REVISIONS’,false);”

    The first reference was correct but those newbies using the second will end up with considerable head scratching. I also prefer not to use the plug-in.

    EXCERPT FOLLOWS:
    .
    .
    .
    Example:
    >WP config file stuff
    /* DISABLE POST REVISIONS */
    define(‘WP_POST_REVISION’,false);
    ?>

  4. Hi whmitty,
    I don’t consider it a nitpick at all; it’s an astute observation and I appreciate you bringing the error to my attention. I’ve gone ahead and corrected it in the entry. :)

    ~ Teli

  5. 1.) The plugin link that you have put here throws error for me.

    2.) I changed my wp-config file to include “define(‘WP_POST_REVISIONS’,false);” soon after the release of 2.6 since I doubted it will bloat my database but still sometimes when I go back to edit an old post, I get the suggestion “There is an autosave of this page that is more recent than the version below. View the autosave.” Thanx for the info. Now I have to reset the autosave time limit also.

  6. This was an interesting article, I went through the observations made by Raj and whmitty, they made good observations. I work in a company where there is too much focus on coding everything by hand. I have been pushing for open source products for qute some time now and trying to introduce them in our work flow.

  7. I got the same errors as Raj, but I managed to fix it when i upgraded to 2.6, might be worth giving it a shot mate..

  8. I had the same problem as raj too it worked in 2.6 but I had problems with it,testing 2.7 probably cos its not ready.

  9. Deborah Bradley January 2, 2009 at 12:22 pm

    Youre correct on saying that “choose your plugins wisely”, I’ve been dependent on plugins on most of my blogs before but found out that most of those plugins were having problem when I updated wordpress.

  10. Thank you very much for the great tutorial. I’m accustomed to tinkering with files but the database is always a little scarier for me, so thanks so much for taking the time to spell it out for the terrified!
    E.

  11. Thanks for this tutorial, i was tinkering with the database to delete unused revision directly through the post table and accidentally deleted the latest post. Anyone doing such deletion should be careful which one to delete.

    But I think adding 2 lines into the config file is the best way to go as Teli said, somethings plugins are not well written and not supported when WP upgrades.

  12. Many thanks for the SQL query. I had noticed the codex piece yesterday and though it was a good idea to disable the post revisions (I’m a crap at spelling, so I make quite a few edits after hitting publish).
    Today, I was looking at the mySQL database and realised that my quick skim over it was going to be a problem with all the revisions. So I’ve now disabled them, plus deleted all the old ones :)

  13. As a follow up to yesterday. I also run a team blog and after checking if anyone used the post-revision feature and discovering no-one did, I deleted all the revisions from the database.
    I managed to remove 19258 rows and decrease the database size down from 132mb to 69mb!

  14. Thanks for that great and very usefull post!
    That was exactly what i was looking for.

  15. Thanks so much for this. I’ve been wondering how to get rid of Post Revisions. Worked like a shot!

  16. Thank you so much for the code to change the Autosave interval. I think you just saved me from going prematurely gray with a very demanding and impatient client. Cheers!

    Damia