WordPress Plugin – Post Revision Display

October 7, 2008 · 17 comments

in general

One of the profs using UCalgaryBlogs.ca was asking if there was a way to show the “audit trail” for a blog posts. If she’s having students write stuff, and needs it in by a given date (say, an assignment deadline), she’d like a way to know if a post was saved before the deadline, or updated after it. It’s easy for people to futz around with the “published on” date for a post…

So, I did some poking around, looking for plugins or tricks to expose the revision display list without having to send the prof to the blog’s admin UI every time she wanted to look at the info.

I couldn’t find anything, so I asked a question on the WordPress support forum. On a tip from Otto42, I poked around with the wp_list_post_revisions() function. Looks exactly like what I need. So it was pretty simple to write a basic plugin that adds a Filter such that the list gets generated and appended to every post displayed on a blog that uses the plugin. If you’re logged in, and have proper privileges, you’ll also get a link to view the revisions directly. If not, you just get to see that the revisions exist.

I had to copy the wp_list_post_revisions() function and modify it a bit in the plugin, so it behaved as needed. Nothing too major, but the WordPress function relies on echo to dump the list directly, and I needed to modify it to return a string to append to the blog post. Easy peasy.

And so, post-revision-display is born. Install and activate it on your blog, and your posts will automagically generate and display the list of revisions as an audit trail, with no futzing about with themes and hardcoding stuff. Here’s what the audit trail looks like:

Download the plugin here (for now – I’m trying to get it added to WordPress.org/extend/plugins…)

{ 1 trackback }

UCalgary Blogs - displaying post revisions
October 7, 2008 at 12:00 pm

{ 16 comments… read them below or add one }

1 Steve Dembo October 7, 2008 at 11:54 am

Way cool, and pretty useful for teachers using this with students. It’s a favorite feature of Google Docs, makes perfect sense for blogs as well.

Nice job!

Reply

2 Scott Leslie October 7, 2008 at 11:56 am

Nice one D’Arcy. As usual, you lead the way, the rest of us follow – I’ve been futzing around trying to write a couple of plugins but not making much effort; this renews my confidence that maybe I can do it. Way to go. Very useful.

Reply

3 dnorman October 7, 2008 at 12:08 pm

I’d be surprised if there wasn’t a checkbox option in a future version of WordPress to provide the same functionality, but in the meantime, this should do the trick.

@scott hey, if I can write a working WordPress plugin, ANYONE can do it! :-)

Reply

4 Rob Wall October 7, 2008 at 12:20 pm

“I had to copy the wp_list_post_revisions() function and modify it a bit in the plugin, so it behaved as needed. Nothing too major, but the WordPress function relies on echo to dump the list directly, and I needed to modify it to return a string to append to the blog post. Easy peasy.”

You have a very geeky sense of “easy”. I’m living in the same dimension so I get it, but others might dispute your use of the word.

But a sweet hack, nonetheless. Thanks for sharing it with the world.

Reply

5 dnorman October 7, 2008 at 12:31 pm

@rob – anything that consists almost exclusively of selective copy-and-paste operations, followed by minor tweakage, gets classified as easy. I didn’t have to actually write new code, just grabbed bits from a few other places and mixed them together until it worked :-)

Reply

6 Boris Mann October 7, 2008 at 2:21 pm

Sounds like a good thing to write a patch for the core version (the function you had to copy).

Reply

7 Chris L October 7, 2008 at 2:38 pm

Nice. I’d never seen that function before! Too bad the system doesn’t keep copies of revisions so they could be viewed…

Reply

8 dnorman October 7, 2008 at 2:59 pm

@boris – perhaps. I think the revisions stuff is still a bit fresh, so it’s likely to mature a bit. maybe a separate method ala get_post_ID() and the_post_ID() (or whatever) that returns rather than echoes…

@chris – it does keep each revision. If you have privs, you can see links to each one, and can even use a visual diff to compare them. Very cool stuff.

Reply

9 Jim October 7, 2008 at 9:55 pm

Wait a second…two posts from Brian Lamb today and you are authoring WordPress plugins? Damn this is a good day for the right Reverend.

Rock on, D’Arcy!

Reply

10 Susan October 8, 2008 at 4:11 pm

Wow, that’s a nice feature!

Reply

11 thorswitch October 17, 2008 at 1:14 am

I tried to send this through your contact form, but I didn’t look like it went though, so please excuse me if you get the message twice :)

Hi! I installed your post revision display plugin, but need to temporarily deactivate it because I’m still trying to get all my pages and stuff working right – meaning I’m saving and resaving them quite frequently, leading to a long trail of revision links.

The problem I’ve run into, though, is that even after deactivating and deleting the plugin, the lists of the revisions are still showing up on the pages and posts, and I cannot figure out how to delete them. I even went in and deleted the “revision.php” file and that didn’t help.

I plan to reinstall it once I finish getting everything set up, but do you have any suggestions as to how I can remove it until I’m ready for it to track things?

Thanks for a great plugin – I love the idea!

kriselda

Reply

12 dnorman October 17, 2008 at 7:07 am

@kriselda – I’m not sure what’s going on – could it be a cache issue? are you using wp-super-cache? I haven’t seen the persistent audit trails after deactivation. I’ll take a look to see what I can find out! Glad you like the plugin, and I’m sorry it’s causing you some grief.

Reply

13 thorswitch October 18, 2008 at 7:21 am

Thanks for the quick reply. I do have wp-super-cache on, so I emptied the cache and also flushed my browser cache to make sure the problem was there, and it didn’t change anything.

Here’s what’s happening currently. I deactivated the plugin, and the post revision dates are no longer showing up on the live versions of the pages. However, Even on posts I created after deactivating the plugin, the “-Post Revisions” link on the main menu for managing posts and pages is still there, and it is still tracking every change.

Just for a test, I reactivated the plugin briefly, and when it was activated, all of the revision dates were again displayed on the live pages. After deactivating it, it once again removed the revisions from the live page, but is still keeping track of changes.

So, the two main issues at the moment are that I need it to stop tracking the revisions until I’m ready to open up the site (I end up making a lot of edits to posts and pages as I try to figure out the best way for embedding media and arranging content – once I’m ready to open up, I won’t be doing that any more) and I also need to figure out how to remove the revisions dates it’s already tracked, so that when I do reactivate the plugin, I won’t end up with this massive list on my posts and pages.

Thanks again for any ideas you might have – I hope this maybe gives you some better information to work with. Let me know if you need to know anything else :)

Kriselda

Reply

14 dnorman October 21, 2008 at 2:53 pm

@thorswitch I’ve done some testing, and can’t reproduce the persistent-audit-trail-after-deactivating issue. When I deactivate the plugin, the audit trails on each post and page disappear immediately. I’m guessing it’s a caching issue – either through WP-Super-Cache or browser caching?

Reply

15 Robert January 8, 2009 at 1:29 pm

Is it possible to have the links to the post revisions be available to users that are not logged in (e.g., the general public) instead of just the list?

Thanks

Reply

16 dnorman January 8, 2009 at 3:55 pm

The links show up only if a user has permission to view revisions – I’m not sure what the lowest user role that allows that is, but I don’t believe the anonymous (i.e., non-user) account can see that. I’ve got no idea how to enable that…

Reply

Leave a Comment

Previous post:

Next post: