_s: Simplify author template.

Set up author data for the author template immediately, rather than
waiting for the first the_post() call.
This removes the need to call the_post() and rewind_posts() in an
author template to print information about the author.

Fixes #346.
This commit is contained in:
obenland 2013-12-21 00:00:25 -08:00
parent 678e136006
commit a156f2cbab
2 changed files with 21 additions and 9 deletions

View file

@ -66,3 +66,24 @@ function _s_wp_title( $title, $sep ) {
return $title;
}
add_filter( 'wp_title', '_s_wp_title', 10, 2 );
/**
* Sets the authordata global when viewing an author archive.
*
* This provides backwards compatibility with
* http://core.trac.wordpress.org/changeset/25574
*
* It removes the need to call the_post() and rewind_posts() in an author
* template to print information about the author.
*
* @global WP_Query $wp_query WordPress Query object.
* @return void
*/
function _s_setup_author() {
global $wp_query;
if ( $wp_query->is_author() && isset( $wp_query->post ) ) {
$GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author );
}
}
add_action( 'wp', '_s_setup_author' );