Skip to content

Conversation

@rebeccahum
Copy link
Contributor

As per #351, the author archive posts page title did not reflect the correct author. This patch solves the issue!

@philipjohn philipjohn merged commit 51f890f into Automattic:master Oct 13, 2017
@philipjohn philipjohn added this to the 3.3 milestone Apr 7, 2018
@SeanDS
Copy link

SeanDS commented May 3, 2018

I think this is actually not fixing the underlying problem. The problem is that the query doesn't contain the author requested. I think the problem is in fix_author_page. Sometimes the query is for an author id (?author=[id]), sometimes it is for an author name (/author/authorname). Both must be checked.

I have forked CAP for my own purposes, so my code is slightly different and will need adapted, but this works for me. In fix_author_page, replace...

		$author_name = sanitize_title( get_query_var( 'author_name' ) );
		if ( ! $author_name ) {
			return;
		}

...with

		$author_id = absint( get_query_var( 'author' ) );
		$author_name = sanitize_title( get_query_var( 'author_name' ) );

		if ( isset( $author_id ) ) {
			// get author by id
			$author = get_user_by( 'id', $author_id );
		} elseif ( isset( $author_name ) ) {
			// get author by specified name
			$author = get_user_by( 'login', $author_name );
		} else {
			// no query variable was specified; not much we can do
			return;
		}

(need to change get_user_by to whatever CAP uses to get coauthors)

This means that the $authordata variable is an author object and therefore the last block in the function works as intended. I think this should mean the get_the_archive_title filter won't be needed.

@stoniestbirch
Copy link

stoniestbirch commented Jul 19, 2018

This actually breaks get_the_archive_title() for other types of archives.

It should be this:

 public function filter_author_archive_title($title) {
         if ( is_author() ) {
             $author = sanitize_user( get_query_var( 'author_name' ) );
             /* translators: Author archive title. 1: Author name */
             $title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . $author . '</span>' );
         }
         return $title;
     }

@TheCrowned
Copy link
Contributor

Hi Daniel,
thanks for reporting this! The issue was already fixed in #535 - it has not yet been released as a public update on WordPress.org, but the master branch of this repository contains the fix :)

rebeccahum pushed a commit that referenced this pull request Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants