Make WordPress Core

Ticket #34560: 34560.15.diff

File 34560.15.diff, 2.7 KB (added by mikeyarce, 4 years ago)
  • wp-admin/includes/meta-boxes.php

     
    13861386
    13871387        $publish_callback_args = array( '__back_compat_meta_box' => true );
    13881388        if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' != $post->post_status ) {
    1389                 $revisions = wp_get_post_revisions( $post->ID );
     1389                $revisions = wp_get_post_revisions( $post->ID, array( 'fields' => 'ids' ) );
    13901390
    13911391                // We should aim to show the revisions meta box only when there are revisions.
    13921392                if ( count( $revisions ) > 1 ) {
     
    13931393                        reset( $revisions ); // Reset pointer for key()
    13941394                        $publish_callback_args = array(
    13951395                                'revisions_count'        => count( $revisions ),
    1396                                 'revision_id'            => key( $revisions ),
     1396                                'revision_id'            => array_shift( $revisions ),
    13971397                                '__back_compat_meta_box' => true,
    13981398                        );
    13991399                        add_meta_box( 'revisionsdiv', __( 'Revisions' ), 'post_revisions_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
  • wp-includes/revision.php

     
    219219/**
    220220 * Retrieve the autosaved data of the specified post.
    221221 *
    222  * Returns a post object containing the information that was autosaved for the
     222 * Returns an object containing the information that was autosaved for the
    223223 * specified post. If the optional $user_id is passed, returns the autosave for that user
    224224 * otherwise returns the latest autosave.
    225225 *
     
    230230 * @return WP_Post|false The autosaved data or false on failure or when no autosave exists.
    231231 */
    232232function wp_get_post_autosave( $post_id, $user_id = 0 ) {
    233         $revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );
     233        global $wpdb;
    234234
    235         foreach ( $revisions as $revision ) {
    236                 if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) {
    237                         if ( $user_id && $user_id != $revision->post_author ) {
    238                                 continue;
    239                         }
     235        $autosave_name = $post_id . '-autosave-v1';
     236        $user_id_query = ( 0 !== $user_id ) ? "AND post_author = $user_id" : null;
    240237
    241                         return $revision;
    242                 }
     238        // Construct the autosave query
     239        $autosave_query = "
     240                SELECT *
     241                FROM $wpdb->posts
     242                WHERE post_parent = %d
     243                AND post_type = 'revision'
     244                AND post_status = 'inherit'
     245                AND post_name   = %s " . $user_id_query . "
     246                ORDER BY post_date DESC
     247                LIMIT 1";
     248
     249        $autosave = $wpdb->get_results(
     250                $wpdb->prepare(
     251                        $autosave_query,
     252                        $post_id,
     253                        $autosave_name
     254                )
     255        );
     256       
     257        if ( ! $autosave  ) {
     258                return false;
    243259        }
    244260
    245         return false;
     261        return $autosave[0];
    246262}
    247263
    248264/**