WordPress.org

Make WordPress Core

Ticket #16215: 16215-15.patch

File 16215-15.patch, 2.3 KB (added by azaozz, 5 years ago)
  • wp-admin/post.php

     
    154154                exit();
    155155        }
    156156
    157         //upgrade any old bad revision data (#16215)
    158         _wp_upgrade_revisions_of_post( $p );
    159 
    160157        $post_type = $post->post_type;
    161158        if ( 'post' == $post_type ) {
    162159                $parent_file = "edit.php";
  • wp-includes/revision.php

     
    434434 * @return array empty if no revisions
    435435 */
    436436function wp_get_post_revisions( $post_id = 0, $args = null ) {
     437        static $checked = array();
     438
    437439        $post = get_post( $post_id );
    438440        if ( ! $post || empty( $post->ID ) || ! wp_revisions_enabled( $post ) )
    439441                return array();
     
    445447        if ( ! $revisions = get_children( $args ) )
    446448                return array();
    447449
     450        if ( ! in_array( $post->ID, $checked ) ) {
     451                $checked[] = $post->ID;
     452
     453                // Check if the revisions have already been updated
     454                if ( 1 > _wp_get_post_revision_version( reset( $revisions ) ) )
     455                        return $revisions;
     456
     457                if ( _wp_upgrade_revisions_of_post( $post, $revisions ) )
     458                        return wp_get_post_revisions( $post, $args );
     459        }
     460
    448461        return $revisions;
    449462}
    450463
     
    564577 * @uses post_type_supports()
    565578 * @uses wp_get_post_revisions()
    566579 *
    567  * @param int|object $post_id Post ID or post object
    568  * @return true if success, false if problems
     580 * @param object Post object
     581 * @return bool true if the revisions were upgraded, false if problems
    569582 */
    570 function _wp_upgrade_revisions_of_post( $post ) {
     583function _wp_upgrade_revisions_of_post( $post, $revisions ) {
    571584        global $wpdb;
    572585
    573         $post = get_post( $post );
    574         if ( ! $post )
    575                 return false;
    576 
    577         if ( ! post_type_supports( $post->post_type, 'revisions' ) )
    578                 return false;
    579 
    580         $revisions = wp_get_post_revisions( $post->ID ); // array( 'order' => 'DESC', 'orderby' => 'date' ); // Always work from most recent to oldest
    581 
    582         if ( ! $first = reset( $revisions ) )
    583                 return true;
    584 
    585         // Check if the revisions have already been updated
    586         if ( preg_match( '/^\d+-(?:autosave|revision)-v\d+$/', $first->post_name ) )
    587                 return true;
    588 
    589586        // Add post option exclusively
    590587        $lock = "revision-upgrade-{$post->ID}";
    591588        $now = time();