Ticket #6775: 6775.6.diff

File 6775.6.diff, 2.0 kB (added by mdawaffe, 5 months ago)
  • wp-includes/post.php

    old new  
    30183018        if ( @constant( 'DOING_AUTOSAVE' ) ) 
    30193019                return; 
    30203020 
     3021        // WP_POST_REVISIONS = 0, false 
    30213022        if ( !constant('WP_POST_REVISIONS') ) 
    30223023                return; 
    30233024 
     
    30273028        if ( !in_array( $post['post_type'], array( 'post', 'page' ) ) ) 
    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 
    30333057/** 
     
    32253249 * @param int|object $post_id post ID or post object 
    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; 
    32363265}