Like the blog? Get the book »

Mastering WordPress Post-Revisioning and Auto-Save Features

Mastering WordPress Post-Revisioning and Auto-Save Features

Not everyone loves the post-revisioning feature of WordPress. In fact, some people can’t stand it. On the one hand, it’s nice to have a library of post-draft revisions to drudge through if you should ever make a mistake. On the other hand, multiple copies of every post is a great way to bloat your database with otherwise useless information.

Then, to complicate matters, WordPress’ auto-save functionality seems to have a mind of its own, at times interfering in the revisioning process even when post-revisioning has been disabled. Taken together, these post-revisioning and auto-save features have been known to confuse and frustrate WordPress users.

In this article, I explain how to take full control of WordPress’ version-revision and auto-save functionality. We’ll explore how these features work, why they don’t, when they clash, and how to stop the madness once and for all.

WordPress AutoSave Feature

WordPress implemented the AutoSave feature in version 2.1. Its function is to periodically (every 60 seconds by default) and automatically save your post while you work. Aside from the occasional hiccup, AutoSave works great and is a genuine benefit to most WordPress users. Unlike version revisioning, AutoSave does not create a new database entry for every save. Instead, a single database entry is created for each post and is updated with each AutoSave cycle. AutoSave isn’t perfect, however, and many folks find the time interval between saves either too brief or too long. Fortunately, WordPress makes it easy to modify the autosave interval with a simple configuration trick:

define('AUTOSAVE_INTERVAL', 300); // in seconds

Simply specify your desired autosave interval (in seconds) and add to your wp-config.php file to enjoy immediate results.

If you are one of the rare individuals who prefers to write without the autosave feature, here is an easy way to turn it off:

function disable_autosave() {
	wp_deregister_script('autosave');
}
add_action('wp_print_scripts','disable_autosave');

Just add that slice of code to your theme’s functions.php and say goodbye to Autosave!

WordPress Post Revisioning Feature

WordPress implemented Post Revisioning (aka Version Revisioning) in version 2.6. Its function is to record changes made to your documents by storing unique revisions in the database. While this feature may benefit a few users, it is widely understood that most WordPress users have no need for this level of functionality. In my humble opinion, the revisioning “feature” is overkill and completely excessive. It should have been left out of the core (i.e., released as a plugin) or there should be an Admin option to completely disable it. Post revisioning creates extraneous database content and, in my experience, functions inconsistently and unpredictably. Fortunately, there is an easy way to disable it by adding the following line to your wp-config.php file:

define('WP_POST_REVISIONS',false);

Or, if you prefer to keep the versioning functionality but limit the number of allowed revisions, add the following line to your wp-config.php file:

define('WP_POST_REVISIONS',3);

There is even a way to clean up your database by deleting all post-revision data. Andrei Neculau shows us how via this handy little SQL command:

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'

That magical query will nuke all post-revisions and associated meta-data from the database.

AutoSave + Versioning = Chaos?

So far, everything presented in this article is fairly straightforward. At this point, I would like to discuss a persistent post-reversioning issue that continues to rear its ugly head even when post revisioning is disabled via the previously prescribed method. Apparently, there is no way to disable WordPress’ post-revisioning functionality. It continues to work behind the scenes even after setting the WP_POST_REVISIONS variable to false in the configuration file.

Why do I say this? Because I have experienced the following series of events with several different WordPress installations:

  1. Install WordPress
  2. Disable Post-Revisioning
  3. Write a post, save it, edit it
  4. Notice a message that says something like this:

There is an autosave of this page that is more recent than the version below.

I can see how the timestamp on an autosave may conflict with the actual post during post editing, but when the database is examined after receiving this message, multiple post revisions are usually found. Apparently, WordPress is still saving post revisions behind the scenes even when revisioning has been disabled. With revisioning disabled, an option to compare reversions will never be shown explicitly, but the comparative functionality continues to operate. Further, there is no way to examine a list of the unintended post revisions. They exist in the database, but not in the Admin area. Thus, to see and compare these revisions, you need to do it manually. Here is a recipe for doing so:

  • Log into a database interface like phpMyAdmin
  • Run the following SQL query:
SELECT * FROM `wp_posts` WHERE post_type = "revision"

If this query returns results, WordPress has been saving revisions without your consent. To delete these revisions and all of their post data, see the method prescribed above. To see and compare different revisions in the WordPress Admin before taking action, continue with the following steps (screenshot provided for clarity):

Screenshot: Post ID columns as seen via phpMyAdminPost ID columns as seen via phpMyAdmin
  • Determine the original post ID for each set of revisions
  • Determine the revision post ID of each individual revision
  • For each set of revisions that you would like to compare, enter the following URL in your browser’s address bar:
http://domain.tld/wp-admin/revision.php?action=diff&right=X&left=Y

Edit the domain to match your own, and then replace “X” and “Y” with the revision post IDs of any two revisions you would like to compare (order does not seem to matter).

Repeat these steps to compare as many revisions as is necessary. To view an individual revision, edit the following code with the ID of the desired revision and enter it into your browser’s address bar:

http://domain.tld/wp-admin/revision.php?revision=N

Once you have evaluated your autosaved revisions, they may be safely deleted, either all at once via the SQL query provided above, or else individually by simply clicking the delete button (the red “x” in phpMyAdmin) next to each revision in the wp_posts table.

Share your experience

I’m curious to know what other WordPress users think of the post-revisioning and auto-save features. Do you use them, and if so, how are they beneficial? Have you ever experienced unexpected or unexplainable behavior while writing a post while using post-revisioning functionality? It would also be interesting to find out how many people think the post-revisioning feature should have been included in the WordPress core.

15 responses

  1. I tried to get rid of the revisions via ‘define’ but it didn’t seem work. I’ll give it another shot, though. The revisioning system just gets into my way of posting. I use TextMate to write the posts and copy them afterwards. If I need revisions, I use svn. Thanks for the SQL to clean up all the entries I really don’t need.

  2. Volkan Gorgulu

    Hey Jeff,

    Great tutorial and I would really like to know the font you used on the image for writing “REVISION POST ID”, “ORIGINAL POST ID” ?

    • Hey Volkan,

      I decided to go with Bitstream’s “Freehand 575 BT” for tutorials and diagrams here at DiW. Its lowercase characters are a bit difficult to read, but the uppercase chars seem to work well.

  3. Good stuff! I’ve always used a plugin for revision control, which allowed me to limit the number of revisions globally and per entry, but I wasn’t aware that you could define a global setting in the wp-config.

    Most useful!

  4. I’ve seen the following used also:

    DELETE FROM wp_posts WHERE post_type = "revision";

    Which one is the better option?

    • That command removes the actual revisions (the saved copies of your posts), but doesn’t clean up after any of the associated data that is stored in the wp_term_relationships and wp_postmeta tables. The query provided in the article deletes all revision-related data, as well as the revisions themselves.

  5. Limiting Post Revisions to 3 on my personal blog. But finding it kind of annoying that there’s not UI to handle that stuff from the back-end … always forget about it first when I start a new WP blog.

  6. George Serradinho

    Some nice tips.

    Users must just remember to use their own prefix in from of the table name otherwise the SQL statements above will not work.

  7. wow, great article! i didn’t know such thinks like find post revisions in DB and acces to them via url

    thanks for share!

  8. This is a very similar post to mine that I did a few days ago on these features. I dislike the features as you will read in my blog post.

  9. great article…..

  10. I think post revisions are a great idea and should be an option, but you shouldn’t have to be a computer programmer to figure out how to access them. I find the above information totally confusing, and cannot find the proper post revisions in my database file.

    A pity programmers only know how to write code for programmers and not the rest of us.

  11. I think you’re right. Post revision would be better if implemented as plugin.

  12. Nacy Washington

    I am new at blogging and plan to go public with the site I have been practicing on soon. However there are some things I don’t understand. Autosave! When I get the pink message to view autosave and I do, then I don’t know what to do when I get there. If I want the autosave version, should I click on restore? I did something wrong yesterday and it got mad at me, sent me a Danger message, screen went black, typing started from somewhere in outer space, and told me I had better wake up and follow the white rabbit????Thought I had crashed my computer but thankfully it is still working.

Comments are closed for this post. Contact us with any critical information.
© 2009–2024 Digging Into WordPress Powered by WordPress Monzilla Media shapeSpace