Make WordPress Core

Changeset 24708


Ignore:
Timestamp:
07/15/2013 11:01:27 PM (12 years ago)
Author:
markjaquith
Message:

Improvements to output of revisions author data.

  • Do not output "false" if avatars are disabled. props ocean90.
  • Cache the author data separately to cut down on calls to get_the_author_meta() and get_avatar(). props nacin.

Fixes #24743.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/revision.php

    r24671 r24708  
    6464function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
    6565    $post = get_post( $post );
    66     $revisions = array();
     66    $revisions = $authors = array();
    6767    $now_gmt = time();
    6868
    6969    $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC' ) );
     70    $show_avatars = get_option( 'show_avatars' );
    7071
    7172    cache_users( wp_list_pluck( $revisions, 'post_author' ) );
     
    8283            "restore-post_{$revision->ID}"
    8384        );
     85
     86        if ( ! isset( $authors[ $revision->post_author ] ) ) {
     87            $authors[ $revision->post_author ] = array(
     88                'id' => (int) $revision->post_author,
     89                'avatar' => $show_avatars ? get_avatar( $revision->post_author, 24 ) : '',
     90                'name' => get_the_author_meta( 'display_name', $revision->post_author ),
     91            );
     92        }
     93
    8494        $revisions[ $revision->ID ] = array(
    85             'id'           => $revision->ID,
    86             'title'        => get_the_title( $post->ID ),
    87             'author' => array(
    88                 'id'     => (int) $revision->post_author,
    89                 'avatar' => get_avatar( $revision->post_author, 24 ),
    90                 'name'   => get_the_author_meta( 'display_name', $revision->post_author ),
    91             ),
    92             'date'         => date_i18n( __( 'M j, Y @ G:i' ), $modified ),
    93             'dateShort'    => date_i18n( _x( 'j M @ G:i', 'revision date short format' ), $modified ),
    94             'timeAgo'      => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
    95             'autosave'     => wp_is_post_autosave( $revision ),
    96             'current'      => $revision->post_modified_gmt === $post->post_modified_gmt,
    97             'restoreUrl'   => urldecode( $restore_link ),
     95            'id'         => $revision->ID,
     96            'title'      => get_the_title( $post->ID ),
     97            'author'     => $authors[ $revision->post_author ],
     98            'date'       => date_i18n( __( 'M j, Y @ G:i' ), $modified ),
     99            'dateShort'  => date_i18n( _x( 'j M @ G:i', 'revision date short format' ), $modified ),
     100            'timeAgo'    => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
     101            'autosave'   => wp_is_post_autosave( $revision ),
     102            'current'    => $revision->post_modified_gmt === $post->post_modified_gmt,
     103            'restoreUrl' => urldecode( $restore_link ),
    98104        );
    99105    }
Note: See TracChangeset for help on using the changeset viewer.