Max Number of Post Versions Supported

We are running a news site based on WP 3.5.1. Some editors complain that the WYSIWYG editor on the post editing page is not working properly for some posts. The editing buttons are not shown.

In some cases we need to update a post many times (like more than 500 times).
May it be the cause?
What will happen to these posts if I set WP_POST_REVISIONS to 10?
Will old versions be deleted automatically, or will they remain?

Related posts

2 comments

  1. You should set WP_POST_REVISIONS to a fixed number. If you don’t, WordPress will keep an unlimited number of revisions. See function wp_revisions_to_keep():

    function wp_revisions_to_keep( $post ) {
        $num = WP_POST_REVISIONS;
    
        if ( true === $num )
            $num = -1;
        else
            $num = intval( $num );
    
        if ( ! post_type_supports( $post->post_type, 'revisions' ) )
            $num = 0;
    
        return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
    }
    

    On the other hand … if you need such a high number of changes you should revisit the edit work flow. There are surely ways to get this number down.

  2. To address:

    What will happen to these posts if I set WP_POST_REVISIONS to 10?
    Will old versions be deleted automatically, or will they remain?

    You have this action:

    add_action( 'pre_post_update', 'wp_save_post_revision' );
    

    set by default in /wp-includes/default-filters.php.

    If you check the source of wp_save_post_revision() you can see that it will delete the remaining revisions of the current post:

    $delete = count($revisions) - WP_POST_REVISIONS;
    

    with wp_delete_post_revision() when the hook pre_post_update is activated for a given $post_id, except when it is performing an auto-saving.

    Here is the relevant part from the source of wp_save_post_revision():

    // 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' ) )
                    continue;
            wp_delete_post_revision( $revisions[$i]->ID );
    }
    

Comments are closed.