Disabling WordPress Auto-Save and Revision Saving Tags:, , ,

When writing a post, I don’t often write it all in one go, then before I publish it, I save it and preview it, generally more than once.

WordPress has 2 Great ( or not ) features, Auto-Save, and Revisions.

When writing my last post Clean Dynamic Directory Listing with PHP I have some example code wrapped in <pre> tags and WordPress auto-validates code, which is a handy feature, but not here where I was trying to enter my example.
So after several saves, and eventually getting in to my mySQL database to fix it and seeing that for hat this time only having 22 posts/pages, my database shows 199 records!

Showing 199 Rows!

Showing 199 Rows!

To get directly to the point, some handy shortcut links:
Disable Auto-Saving
Disable Saving Revisions
Final code
Cleaning up the Database


Ok.. I’m no prude, I have plenty of server space and mySQL storage, and the POST data isn’t exactly huge, but still Thats crazy! And before you ask, No I am not one of those people that go and delete all my old or unimportant emails!
 

Disable WordPress Auto-Saving my Posts!

So, I looked in to it and found people hacking their wp-ajax.php and post.php and thought, Oh Hell No! That is going to break every time I update WP, and who knows what else.

So.. a little bit of digging in to my code and found what I needed.

Open your WordPress Config File:

/wp-config.php

And after the first set of functions I added this line:

12
define( 'AUTOSAVE_INTERVAL', 900 );

By Default this value is set to 60 (seconds), 600 equals 1 Hour, 900 equals 1 1/2 hours, you can go higher, but i figure 1 1/2 hours in my case is good.

Disable WordPress Revisions!

I dont need or want 10 revisions of my posts, I am the only one editing them and this is not a Wiki! One Post, One Revision!

In the WordPress Config File:

/wp-config.php

And after the first set of functions I added this line:

13
define( 'WP_POST_REVISIONS', 0 );

By Default this value is On (1), but turn it off by setting it to Off (0) ( Zero ).

Sheldons revised WP-CONFIG.PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
< ?php
// ** MySQL settings ** //
define('DB_NAME', '*database*');    // The name of the database
define('DB_USER', '*username*');     // Your MySQL username
define('DB_PASSWORD', '*password*'); // ...and password
define('DB_HOST', 'localhost');    // 99% chance you won't need to change this value
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
 
// TURN OFF AUTO-SAVE AND SAVING REVISIONS
// THEY ARE MAKING A GOOD AWEFL MESS OF MY DB AND MESSING UP SETTINGS WHEN WRITING!
define( 'AUTOSAVE_INTERVAL', 600 ); // 60= 1 HOUR.
define ('WP_POST_REVISIONS', 0);    //  TURN OFF POST REVISIONS.

Cleaning up those extra 175 records!

Ok, I have disabled Auto-Saving and Saving Revisions, I am now a happy fella!
But what about those 100’s of old records?

A simple mySQL Query will fix those !
In your wp-config.php file, Right at the bottom after the “require_once(ABSPATH . ‘wp-settings.php’);” Paste this Query, Load any page in your site ONCE and then remove the line.

37
mysql_query("DELETE FROM `wp_posts` WHERE `post_status` = 'revision'");

This will Delete all those Auto-Saves and Revisions :)

Now Showing 22 Records!

Now Showing 22 Records!

Please post your Questions, Comments and Concerns!

Note: Back up your SQL database first! This is working good on my version of WordPress 2.6 with a few MOD's.
All consideration and Care, but no responsibility - Sheldon

Related posts:

  1. Virtual Web Hosting on OSX Leopard
  2. Tremor WordPress Theme
  3. Installing PHP5 and mySQL on Mac OSX Leopard
  4. Using PHP exec to backup mySQL databases.
  5. Controlling Input with Mootools Javascript

16 Responses to “Disabling WordPress Auto-Save and Revision Saving”

  1. WPRemixx Admin 11/08/2008 01:47am

    Sheldon, well done man. That is going into my code snippet vault. I was hoping someone would come up with a plugin or some sort of solution to this problem. Your's was clean and elegant and best of all, it appears to work perfectly. I only say "appears to work" because I just did it 30 seconds ago and so far so good. Just the SQL alone was worth the post. Nice work, and thank you.
  2. Sheldon 28/08/2008 09:00am

    Thanks to Pepe, I have updated the mysql Query.
    mysql_query("DELETE FROM `wp_posts` WHERE `post_status` = 'revision'");
  3. Robert 01/09/2008 06:05pm

    Thanks, very suscinct and understandable instructions.
    To those arguing about deleting old mail, etc.: you guys are mediocrity and inefficiency hand in hand.
  4. Ovidiu 22/01/2009 09:32pm

    are you sure its

    define( 'WP_POST_REVISIONS', 0 ); and not

    define( 'WP_POST_REVISIONS', false ); or will both work?

    also you have a calculation error, if 60=60 seconds then 600 are not 1 hour like you wrote but 10 minutes :-)
  5. Sheldon 27/01/2009 08:45pm

    Hi Ovidiu,

    Good work on spotting that time/math error ;)

    Both Zero and False will work, where false returns a boolean of 0, where True == 1.
  6. Saurooon 05/02/2009 01:45am

    Hi there,
    not bad...

    Have a nice day
    Saurooon
  7. Kevin Kelly 20/03/2009 02:48pm

    Great, thanks!
  8. Hobosic 23/03/2009 12:41am

    Hello,
    Thanks for article. Everytime like to read you.

    Thanks
    Hobosic
  9. Buy Acai Berry 28/03/2009 02:27am

    I don't normally leave comments, but I really enjoyed your post. It helpd me alot.
  10. RaiulBaztepo 30/03/2009 08:55pm

    Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I'v just started to learn this language ;)
    See you!
    Your, Raiul Baztepo
  11. walnutz 05/06/2009 08:14pm

    great tips dude, how about

    define('AUTOSAVE_INTERVAL', 86400); //1 day
  12. sandrar 11/09/2009 02:34am

    Hi! I was surfing and found your blog post... nice! I love your blog. :) Cheers! Sandra. R.
  13. bruhaspati 13/10/2009 02:12am

    i was looking for this since a week as i was trying to build posts with permalinks whose content changes daily.
    i dont want to save revisions of same post daily which will occupy lots of database, though autosave is fine with me
    thanks anyway

Subscribe Via Email Notify me of followup comments via e-mail