Tag Archives: revisions

Disabling WordPress Auto-Save and Revision Saving

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:

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:

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

< ?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.

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