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:
parent
4e934c9e02
commit
24553b2f03
|
@ -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 ) {
|
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
|
||||||
$post = get_post( $post );
|
$post = get_post( $post );
|
||||||
$revisions = array();
|
$revisions = $authors = array();
|
||||||
$now_gmt = time();
|
$now_gmt = time();
|
||||||
|
|
||||||
$revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC' ) );
|
$revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC' ) );
|
||||||
|
$show_avatars = get_option( 'show_avatars' );
|
||||||
|
|
||||||
cache_users( wp_list_pluck( $revisions, 'post_author' ) );
|
cache_users( wp_list_pluck( $revisions, 'post_author' ) );
|
||||||
|
|
||||||
|
@ -81,20 +82,25 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null
|
||||||
),
|
),
|
||||||
"restore-post_{$revision->ID}"
|
"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(
|
$revisions[ $revision->ID ] = array(
|
||||||
'id' => $revision->ID,
|
'id' => $revision->ID,
|
||||||
'title' => get_the_title( $post->ID ),
|
'title' => get_the_title( $post->ID ),
|
||||||
'author' => array(
|
'author' => $authors[ $revision->post_author ],
|
||||||
'id' => (int) $revision->post_author,
|
'date' => date_i18n( __( 'M j, Y @ G:i' ), $modified ),
|
||||||
'avatar' => get_avatar( $revision->post_author, 24 ),
|
'dateShort' => date_i18n( _x( 'j M @ G:i', 'revision date short format' ), $modified ),
|
||||||
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
|
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
|
||||||
),
|
'autosave' => wp_is_post_autosave( $revision ),
|
||||||
'date' => date_i18n( __( 'M j, Y @ G:i' ), $modified ),
|
'current' => $revision->post_modified_gmt === $post->post_modified_gmt,
|
||||||
'dateShort' => date_i18n( _x( 'j M @ G:i', 'revision date short format' ), $modified ),
|
'restoreUrl' => urldecode( $restore_link ),
|
||||||
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
|
|
||||||
'autosave' => wp_is_post_autosave( $revision ),
|
|
||||||
'current' => $revision->post_modified_gmt === $post->post_modified_gmt,
|
|
||||||
'restoreUrl' => urldecode( $restore_link ),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue