Make WordPress Core

Ticket #34560: 34560.11.diff

File 34560.11.diff, 4.2 KB (added by adamsilverstein, 7 years ago)

Refresh of .8 patch against trunk

  • src/wp-admin/edit-form-advanced.php

     
    217217
    218218$publish_callback_args = null;
    219219if ( post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status ) {
    220         $revisions = wp_get_post_revisions( $post_ID );
    221220
     221        require_once( ABSPATH . 'wp-admin/includes/class-wp-revisions.php' );
     222        global $wp_revisions;
     223
    222224        // We should aim to show the revisions metabox only when there are revisions.
    223         if ( count( $revisions ) > 1 ) {
    224                 reset( $revisions ); // Reset pointer for key()
    225                 $publish_callback_args = array( 'revisions_count' => count( $revisions ), 'revision_id' => key( $revisions ) );
     225        if ( $wp_revisions->revisions_count > 1 ) {
     226                $publish_callback_args = array(
     227                        'revisions_count' => $wp_revisions->revisions_count,
     228                        'revision_id'     => $wp_revisions->last_revision_id,
     229                );
    226230                add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core');
    227231        }
    228232}
  • src/wp-includes/post-template.php

     
    16501650 * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
    16511651 */
    16521652function wp_post_revision_title_expanded( $revision, $link = true ) {
    1653         if ( !$revision = get_post( $revision ) )
    1654                 return $revision;
    16551653
    16561654        if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
    16571655                return false;
     
    16631661        $gravatar = get_avatar( $revision->post_author, 24 );
    16641662
    16651663        $date = date_i18n( $datef, strtotime( $revision->post_modified ) );
    1666         if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
     1664        if ( $link && $link = admin_url( sprintf( 'revision.php?revision=%d&action=edit', $revision->ID ) ) )
    16671665                $date = "<a href='$link'>$date</a>";
    16681666
    16691667        $revision_date_author = sprintf(
     
    17111709        if ( ! $post = get_post( $post_id ) )
    17121710                return;
    17131711
     1712        if ( ! current_user_can( 'read_post', $post->ID ) )
     1713                return;
     1714
    17141715        // $args array with (parent, format, right, left, type) deprecated since 3.6
    17151716        if ( is_array( $type ) ) {
    17161717                $type = ! empty( $type['type'] ) ? $type['type']  : $type;
     
    17171718                _deprecated_argument( __FUNCTION__, '3.6' );
    17181719        }
    17191720
    1720         if ( ! $revisions = wp_get_post_revisions( $post->ID ) )
     1721        require_once( ABSPATH . 'wp-admin/includes/class-wp-revisions.php' );
     1722        global $wp_revisions;
     1723
     1724        if ( ! $revisions = $wp_revisions->revisions_details ) {
    17211725                return;
     1726        }
    17221727
    17231728        $rows = '';
    17241729        foreach ( $revisions as $revision ) {
    1725                 if ( ! current_user_can( 'read_post', $revision->ID ) )
    1726                         continue;
    1727 
    17281730                $is_autosave = wp_is_post_autosave( $revision );
    17291731                if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) )
    17301732                        continue;
  • src/wp-includes/revision.php

     
    225225 * @return WP_Post|false The autosaved data or false on failure or when no autosave exists.
    226226 */
    227227function wp_get_post_autosave( $post_id, $user_id = 0 ) {
    228         $revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );
     228        global $wpdb;
    229229
    230         foreach ( $revisions as $revision ) {
    231                 if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) {
    232                         if ( $user_id && $user_id != $revision->post_author )
    233                                 continue;
     230        // Contruct the autosave query.
     231        $autosave_query = "
     232                SELECT *
     233                FROM $wpdb->posts
     234                WHERE post_parent = %d
     235                AND   post_type   = 'revision'
     236                AND   post_status = 'inherit'
     237                AND   post_name   = %s
     238                AND   post_author = %s
     239                LIMIT 1";
    234240
    235                         return $revision;
    236                 }
     241        $autosave_details = $wpdb->get_results(
     242                $wpdb->prepare(
     243                        $autosave_query,
     244                        $post_id,
     245                        $post_id . '-autosave-v1',
     246                        ( 0 !== $user_id ) ? $user_id : get_current_user_id()
     247                )
     248        );
     249
     250        if ( empty( $autosave_details ) ) {
     251                return false;
    237252        }
    238253
    239         return false;
     254        return $autosave_details[0];
    240255}
    241256
    242257/**