WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/23/2008 03:27:56 PM (11 years ago)
Author:
ryan
Message:

Allow defining the number of revisions to save. Props mdawaffe. see #6775

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r7985 r7987  
    30193019        return;
    30203020
     3021    // WP_POST_REVISIONS = 0, false
    30213022    if ( !constant('WP_POST_REVISIONS') )
    30223023        return;
     
    30283029        return;
    30293030
    3030     return _wp_put_revision( $post );
     3031    $return = _wp_put_revision( $post );
     3032
     3033    // WP_POST_REVISIONS = true (default), -1
     3034    if ( !is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 )
     3035        return $return;
     3036
     3037    // all revisions and (possibly) one autosave
     3038    $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
     3039
     3040    // WP_POST_REVISIONS = (int) (# of autasaves to save)
     3041    $delete = count($revisions) - WP_POST_REVISIONS;
     3042
     3043    if ( $delete < 1 )
     3044        return $return;
     3045
     3046    $revisions = array_slice( $revisions, 0, $delete );
     3047
     3048    for ( $i = 0; isset($revisions[$i]); $i++ ) {
     3049        if ( false !== strpos( $revisions[$i]->post_name, 'autosave' ) )
     3050            continue;
     3051        wp_delete_revision( $revisions[$i]->ID );
     3052    }
     3053
     3054    return $return;
    30313055}
    30323056
     
    32263250 * @return array empty if no revisions
    32273251 */
    3228 function wp_get_post_revisions( $post_id = 0 ) {
     3252function wp_get_post_revisions( $post_id = 0, $args = null ) {
    32293253    if ( !constant('WP_POST_REVISIONS') )
    32303254        return array();
    32313255    if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) )
    32323256        return array();
    3233     if ( !$revisions = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) ) )
     3257
     3258    $defaults = array( 'order' => 'DESC', 'orderby' => 'date' );
     3259    $args = wp_parse_args( $args, $defaults );
     3260    $args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) );
     3261
     3262    if ( !$revisions = get_children( $args ) )
    32343263        return array();
    32353264    return $revisions;
Note: See TracChangeset for help on using the changeset viewer.