Quite sure there isn't a way baked in to do this, but anyone have any ideas on how I would get something like this done? I want to turn autorevisions off and ONLY have a revision created when a button is clicked (probably custom button placed in the meta box). Would be a super useful way to do more of a version control scenario with the posts instead of revisions every time you fix a spelling error.

For instance, could we use this and tie it to a button click?

 * Saves an already existing post as a post revision.
 * Typically used immediately prior to post updates.
 * @package WordPress
 * @subpackage Post_Revisions
 * @since 2.6.0
 * @uses _wp_put_post_revision()
 * @param int $post_id The ID of the post to save as a revision.
 * @return mixed Null or 0 if error, new revision ID, if success.
function wp_save_post_revision( $post_id ) {
    // We do autosaves manually with wp_create_post_autosave()
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )

    // WP_POST_REVISIONS = 0, false
    if ( ! WP_POST_REVISIONS )

    if ( !$post = get_post( $post_id, ARRAY_A ) )

    if ( !post_type_supports($post['post_type'], 'revisions') )

    $return = _wp_put_post_revision( $post );

    // WP_POST_REVISIONS = true (default), -1
    if ( !is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 )
        return $return;

    // all revisions and (possibly) one autosave
    $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );

    // WP_POST_REVISIONS = (int) (# of autosaves to save)
    $delete = count($revisions) - WP_POST_REVISIONS;

    if ( $delete < 1 )
        return $return;

    $revisions = array_slice( $revisions, 0, $delete );

    for ( $i = 0; isset($revisions[$i]); $i++ ) {
        if ( false !== strpos( $revisions[$i]->post_name, 'autosave' ) )
        wp_delete_post_revision( $revisions[$i]->ID );

    return $return;

Would love to hear what you experts have to say!


UPDATE: It seems as if this will be the way to go: remove_action('pre_post_update', 'wp_save_post_revision');

But I'm having trouble tying that to a specific button.. I don't want to disable revisions completely, and I don't want it to apply every time any button is pressed, just momentarily when this button is pressed.

Thanks for your input!


1 Answer 1


This is not yet a complete answer, for lack of time, though I'll try to return later with a more complete example but I just wanted to add a couple of notes. Possibly someone else will jump in soon.

To get the ball rolling...


Yes this is entirely possible, you can create this functionality and in your snippet you'll see some of the relevant hooks you need to be working with.

add_action('_wp_put_post_revision', 'your_function");

Found in ../wp-includes/post.php along with other relevant hooks relating to revisions.


To add a Save Revision button next to or on top of the Publish button you would use the following hook;

add_action( 'post_submitbox_misc_actions', 'custom_button' );

function custom_button(){
        $html  = '<div id="major-publishing-actions" style="overflow:hidden">';
        $html .= '<div id="publishing-action">';
        $html .= '<input type="submit" accesskey="p" tabindex="5" value="Customize Me!" class="button-primary" id="custom" name="publish">';
        $html .= '</div>';
        $html .= '</div>';
        echo $html;

That's a working example and the html formatting (divs, id's, etc) are there to preserve some kind of consistent UI experience but feel free to change any of that to your liking, especially if you want a custom look and feel or special padding, margins and so forth.

PS. Try and attempt, regardless of the outcome, to write your own function hooking onto _wp_put_post_revision in conjunction with the custom button hook above. Paste your results in the meantime.

  • Hmmmm, above is what I've cobbled together so far.. It certainly creates a revision, but so does hitting the regular "update" button... But I guess that get's me half there perhaps? What say you userabuser?
    – Ryan
    Oct 17, 2012 at 20:38
  • It also seems like something simple like this would be useful, but I'm unable to produce any results with it either: remove_action('pre_post_update', 'wp_save_post_revision');// stop revisions add_action('pre_post_update', 'wp_save_post_revision');// enable revisions again
    – Ryan
    Oct 24, 2012 at 7:04
  • Man, I am really struggling with this one. Any other tips you might offer? Thanks!
    – Ryan
    Oct 28, 2012 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.