info@workbox.com (877) 473-9016

Blog

WordPress Pages: Versioning, Drafts and Revisions

Thursday, January 13, 2011
Content Management SystemsTechnologyWeb DesignWordPress Plugins

WordPress has become a standard content management system for many corporate websites, and for good reason – it’s powerful, easy to use and it’s free! However, since it was built to be a blogging system, rather than a “real” CMS, WordPress lacks some features that many organizations require to be able to manage their content properly.

    Specifically, WordPress out-of-the-box lacks:

  • A revision system – Functionality that allows editors to view previous versions of pages, and roll back to one of them instantly.
  • Preview/draft features for “pages” – Most people use the “pages” functionality in WP-ADMIN to create the content pages that establish the main site structure (About Us, Products, Services, etc.). Unfortunately, you can’t make a change to a page that’s already live without publishing this change, or making the page “dead” when you have it in preview mode (ugh!).

We’re sure we’re not alone in tackling these issues, but we thought our readers would like to see our solution.

Revisions & Version Control

Here’s a screenshot of the version control section of the page editor UI:

 

    So, this system allows editors to do the following things:

  • Store all previous versions of page/record.
  • Compare any 2 versions, which is facilitated by color-coding the differences.
  • Restore any version.

Preview Feature

    For the pages preview feature, here’s our solution architecture:

  • In wp-config.php disable the autosave (set autosave time to 10,000 seconds) and WordPress’ versioning default
    define(‘WP_POST_REVISIONS’, 0);
    define( ‘AUTOSAVE_INTERVAL’, 10000 );
  • Replace the standard WP block that contains the save/publish buttons with our own block.
  • Create a table where we will store versions of pages. Only title and content fields are versioned.
  • At the bottom of the page users will see a large form & table supporting roll-backs, version comparison, etc. (see screenshot above).
  • When users hit the Save Draft button, the page does not get updated. Instead this new revision gets stored in our table with a special flag. The next time a user goes to edit the page, the system checks if this page has a draft. If it does, the system serves the draft and allows the user to edit/preview/publish it.
  • With our solution, when you hit Preview, the record does not get saved into the database (as was the case with WordPress’ default implementation). Instead the title and content gets submitted into a form, and passed to a new window (with the address of the page on the frontend). A special function then replaces the actual values of title and content with the values from the form (i.e. the draft values).

We hope you find this useful! Also, we would love to get any feedback or other ideas you may have for this particular WordPress content management issue.

Yours, Gleb Aksyutchenko