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.

git-svn-id: http://core.svn.wordpress.org/trunk@24708 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Mark Jaquith 2013-07-15 23:01:27 +00:00
parent 4e934c9e02
commit 24553b2f03
1 changed files with 20 additions and 14 deletions

View File

@ -63,10 +63,11 @@ function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
$post = get_post( $post );
$revisions = array();
$revisions = $authors = array();
$now_gmt = time();
$revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC' ) );
$show_avatars = get_option( 'show_avatars' );
cache_users( wp_list_pluck( $revisions, 'post_author' ) );
@ -81,14 +82,19 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null
),
"restore-post_{$revision->ID}"
);
if ( ! isset( $authors[ $revision->post_author ] ) ) {
$authors[ $revision->post_author ] = array(
'id' => (int) $revision->post_author,
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 24 ) : '',
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
);
}
$revisions[ $revision->ID ] = array(
'id' => $revision->ID,
'title' => get_the_title( $post->ID ),
'author' => array(
'id' => (int) $revision->post_author,
'avatar' => get_avatar( $revision->post_author, 24 ),
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
),
'author' => $authors[ $revision->post_author ],
'date' => date_i18n( __( 'M j, Y @ G:i' ), $modified ),
'dateShort' => date_i18n( _x( 'j M @ G:i', 'revision date short format' ), $modified ),
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),