Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#34516 closed defect (bug) (fixed)

wp_get_document_title() and post type archives by author

Reported by: greenshady's profile greenshady Owned by: obenland's profile obenland
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.4
Component: Themes Keywords: has-patch
Focuses: template Cc:

Description

Previously, wp_title() ran a check when is_author() like so:

if ( is_author() && ! is_post_type_archive() ) {
	$author = get_queried_object();
	if ( $author ) {
		$title = $author->display_name;
	}
}

This made sense when viewing a post type archive by author like example.com/?post_type=post_type&author=author_nicename.

However, wp_get_document_title() doesn't check this:

} elseif ( is_author() && $author = get_queried_object() ) {
	$title['title'] = $author->display_name;

The following notice is now given on post type archives by author:

Notice: Undefined property: stdClass::$display_name in C:\xampp\htdocs\wp-includes\general-template.php on line 875

This is because the queried object is actually the post type object rather than the author/user object.

Attachments (3)

34516.diff (628 bytes) - added by greenshady 11 years ago.
34516.2.diff (2.0 KB) - added by obenland 11 years ago.
34516.3.diff (2.6 KB) - added by obenland 11 years ago.

Download all attachments as: .zip

Change History (10)

#1 @greenshady
11 years ago

Note that this was fixed for wp_title() in [28251].

@greenshady
11 years ago

#2 @obenland
11 years ago

  • Component changed from General to Themes
  • Focuses template added
  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.4
  • Owner set to obenland
  • Status changed from new to accepted

#3 @obenland
11 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 35700:

Template: Get the author name directly from $authordata.

Since [25574] $authordata gets set up in WP::register_globals() - no need
to take a detour over the queried object.

Props greenshady for initial patch.
Fixes #34516.

#4 @ocean90
11 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

@obenland: $authordata doesn't get set up if $wp_query->post is empty, means empty author archives will have an empty 'title' part.

@obenland
11 years ago

#5 @obenland
11 years ago

34516.2.diff reverts [35700] and reorders template checks to be in line with WP_Query::get_queried_object().

At some point we should double-check and update get_body_class(), get_the_archive_title() etc.

This ticket was mentioned in Slack in #core by wonderboymusic. View the logs.


11 years ago

@obenland
11 years ago

#7 @obenland
11 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 35706:

Template: Use template-loader.php as cononical source of truth for conditional ordering.

Reverts [35700] which didn't account for author archives without posts.
Determination of the correct title is now based on the same order of
conditionals that template loader uses to select the right template.

H/t ocean90.
Fixes #34516.

Note: See TracTickets for help on using tickets.