Take control over auto saves and post revisions

I have seen a lot of “turn of auto-save or clutter up your database”-type comments lately claiming the auto save function in WordPress will waste a lot of space in the database. In reality, this is not the case.

Auto saves

It seems like there is a common misconception amongst some WordPress users that for each auto save event, a new copy of the current post is stored in the database. This is not true. When WordPress first auto saves the current post you are working on, a new row is used in the database. After this, every subsequent auto save will overwrite this very same row. So at all time, only one row in the database is used by the auto saves function.

By default, WordPress has auto saves enabled and set to save every 60 seconds. You can change this behavior by defining the AUTOSAVE_INTERVAL constant in you wp-config.php file. This can be done in other files as well, but since this setting defines how your WordPress installation should behave, maybe that is the best place to put it.

To change the rate of auto saves you define the AUTOSAVE_INTERVAL  in seconds:

define('AUTOSAVE_INTERVAL', 60);

If you would like to disable it, set the number of seconds to an extremely high value like:

define('AUTOSAVE_INTERVAL' 86400); // One day

There are a lot of examples on the Internet where people are using the follow snippet:

wp_deregister_script('autosave');

THIS IS A BAD IDEA! It actually breaks functionality in the “New post” page of WordPress. This script is needed to initially save the post when you leave the Title field and hence generating the permalink.

Post revisions

A related function in WordPress is the revision management. By default each post can have an unlimited amount of revisions. New revisions are created each time you save your post. This function is always a lifesaver if you happen to remove something you previously had written or when your web browser or computer crashes.

By default, WordPress has auto post revisions enabled and the amount of post revisions set to “unlimited”. You can change this setting by defining the WP_POST_REVISIONS constant in your wp-config.php.

It can have three different values:

  • True or -1: Store all post revisions (default).
  • False or 0: Do not store any post revisions except the one used by auto save.
  • (int) > 0: Stores that many post revisions +1 for auto saves.

This example will store 3 post revisions +1 for the auto saves functionality:

define('WP_POST_REVISIONS', 3);

Do you need all revisions?

In most cases, the auto save functionality and post revisions is a good thing to have. But do you actually need an unlimited amount of post revisions? Post revisions will actually decrease the overall performance of WordPress, if there are A LOT of them. I personally prefer to have three post revisions stored in my database and the auto saves functionality enabled for those times when technology fails.

Leave a Reply

Your email address will not be published. Required fields are marked *