[wp-trac] [WordPress Trac] #44183: BUG in get_the_archive_title() when get author
WordPress Trac
noreply at wordpress.org
Tue May 22 02:39:49 UTC 2018
#44183: BUG in get_the_archive_title() when get author
--------------------------+-----------------------------
Reporter: Tkama | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
On author archive page with no posts [https://wp-kama.com/filecode/wp-
includes/general-template.php#L1465 get_the_archive_title()] don't display
author name - it return empty string. Example: https://wp-
kama.com/author/vladlu
It is because `get_the_author()` which need global var `$authordata`, but
this var is empty if user dont have any posts...
{{{
} elseif ( is_author() ) {
/* translators: Author archive title. 1: Author name */
$title = sprintf( __( 'Author: %s' ), '<span
class="vcard">' . get_the_author() . '</span>' );
} elseif ( is_year() ) {
}}}
We need to think about the way to fix this. Maybe good solution is to set
global $authordata for request with no posts in [https://wp-
kama.com/filecode/wp-includes/class-wp.php#L558 WP::register_globals()].
Something like this:
{{{
if ( $wp_query->is_author() ){
if( isset( $wp_query->post ) )
$GLOBALS['authordata'] = get_userdata(
$wp_query->post->post_author );
else
$GLOBALS['authordata'] = get_userdata(
get_queried_object()->ID );
}
}}}
-
One more notice: it's better to use `esc_html()` for `get_the_author()` in
`get_the_archive_title()`.
{{{
} elseif ( is_author() ) {
/* translators: Author archive title. 1: Author name */
$title = sprintf( __( 'Author: %s' ), '<span
class="vcard">' . esc_html( get_the_author() ) . '</span>' );
} elseif ( is_year() ) {
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44183>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list