WordPress Plugin: Versioning
After losing a significant amount of writing work earlier tonight due to some WordPress bug (or maybe user error; who knows), I decided that all of my posts should be versioned.
I save my work constantly, so it’s dumb that accidentally saving a truncated post should wipe out hours and hours of work.
So I searched around on the internet and found the WordPress Versioning Plugin, which I downloaded and immediately installed.
Unfortunately, the plugin didn’t work.
So I’ve been tinkering around with it for a few hours, and I’ve fixed it.
You can download the new plugin module here:
http://benjismith.net/files/wp-versioning.tar.gz
Here are the changes I made:
Bugs Fixed:
- The PHP was coded with the assumption that REGISTER_GLOBALS would be set to TRUE. That’s a dumb assumption, so I changed the code to use the $HTTP_GET_VARS global array.
- For any querystring parameters, I’m now using mysql_escape_chars() to prevent SQL injection attacks.
Better UI:
- More aesthetically-pleasing table layout.
- Betterly-named column headers
- Snapshots are now displayed in a format that preserves both the html markup and the newlines in the post, making it a little easier to choose which snapshot to rollback to.
New Features:
- It’s now possible to delete snapshots, to keep from clogging up the database with a bunch of unnecessary snapshots
I’ve decided to call the new version 19.2 (which, you’ve got to admit, is a significant upgrade from the original author’s 1.0 Beta version).
At some point, I may implement a better visual diff, so that sequential snapshots are easier to differentiate. For now, I’m not too concerned. I’m just happy that my posts will no longer suffer from mistaken deletions, either due to bugs in the WordPress software itself or because of one of those pesky ‘Problem Between Chair And Keyboard’ bugs.
If you have any questions, let me know.










February 27th, 2007 at 7:56 am
I just wanted to say thanks for updating this plugin. I just installed it and tested it. You should post this to the plugin repository over at the wordpress page.
If you decide to revisit this plugin and work on it some more I did notice that when you delete a post and then go in and delete all revisions of the post it still leaves a reference to it in the revisioning management page. It doesn’t affect its functionality though so I’m happy :)
February 27th, 2007 at 6:44 pm
I have to agree–it works perfectly in 2.0.4 (with the exception of the minor bug Scott reported).
I can’t thank you enough for updating this plugin!
March 3rd, 2007 at 5:58 pm
No problemo. I’m glad it worked out well for you guys.
March 9th, 2007 at 9:39 am
Thanks a lot, this will surely prove to be extremely useful!
I’ve installed the plugin and found the admin part works perfectly. No sweat. Excuse my ignorance here, but is there any easy way I could go about displaying the different versions of a post to visitors?
March 11th, 2007 at 8:14 pm
Mike says:
“is there any easy way I could go about displaying the different versions of a post to visitors?”
Not really. The way the versioning works is that, every time you make an edit, it saves a copy to the versioning table. Then, to revert, it copies an older version back into the live database.
But the blog pages visible to the user are always rendered from WordPress’s core tables. If you wanted to display data from the versioning table to the user, you’d have to hack into the core WordPress functionality.
March 12th, 2007 at 5:26 am
I see.
Presumably though I could run a standalone SQL query to gather the data (not the most elegant option) in a template file? I’ll pop my programming hat on and see what I come up with.
Thanks for your response, the plugin is working beautifully.
Mike
April 12th, 2007 at 3:19 am
hi,
I am getting this error on wp2.0.10 when clicking ‘Choose Rollback Snapshot’ in the admin area:
Could not successfully run query (SELECT * FROM wp_versions WHERE post_ID = ORDER BY post_version DESC ) from DB: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘ORDER BY post_version DESC’ at line 1
Also, how can I diff two versions?
Thanks.
———
http://www.tinyways.com
April 18th, 2007 at 12:52 pm
Hi!
I tried using this plugin for the first time, and got this error the first time I clicked “Choose Rollback Snapshot”:
Could not successfully run query (SELECT * FROM wp_versions WHERE post_ID = ORDER BY post_version DESC ) from DB: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘ORDER BY post_version DESC’ at line 1
It looks like the Post ID is getting stripped out for some reason…
Thoughts?
Jeff
April 18th, 2007 at 1:17 pm
Hmm… Replacing “$HTTP_GET_VARS” with “$_GET” fixes that problem, but then I get “no records found.” I just checked the database, and there’s nothing in the “wp_versions” table :(
April 18th, 2007 at 2:10 pm
Hey, me again…
Looks like the problems had to do with the big “INSERT” query in “versioning_19.2.php” … It tries to insert the value “Array” for the “post_category” field, and an empty string into the “menu_order” field. These both expect integers. I hardcoded these with zeros (because I HAD to get it working NOW). This seems to work, but obviously will not correctly save the category and menu order info - not that I really care for my purposes - namely disaster mitigation :)