No need for the_post and rewind_posts in author archives. #36

Merged
merged 2 commits into from Aug 27, 2012

Projects

None yet

2 participants

@kovshenin

We can get all the information we need about the author by using get_queried_object within is_author.

@kovshenin kovshenin No need for the_post and rewind_posts in author archives.
We can get all the information we need about the author by using get_queried_object within is_author.
dec5c61
@mfields
mfields commented Aug 24, 2012

Related #53

@mfields
mfields commented Aug 24, 2012

Nice! I like this a lot :)

One probablem with the code is that it is not compatible with WordPress 3.2. I did a little testing and it seems like the following works well in 3.2-trunk:

$author = get_queried_object();
if ( isset( $author->data ) )
    $author = $author->data;

Does anyone see issues with this approach?

One more thing to note: The return value of get_author_posts_url() is filterable in core, I think it is best to escape the value with esc_url() before passing to printf()'.

@kovshenin kovshenin Correct use of get_queried_object() for author archives.
The ->data object (used previously) stores the author data, but the WP_User class has the __get magic method that grants access to that data, so using get_queried_object() without ->data is correct, and compatible with 3.2, which does not use magic methods. Also url-escapes get_author_posts_url.
103ae2c
@kovshenin

@mfields thanks for the insight! I did need a break back then and it's good that you didn't merge. I dug into core this morning and turns out the get_queried_object returns a WP_User class which has a __get magic method since 3.3 I believe, so you can access things like $author->ID and $author->display_name without accessing the ->data object, even if you don't see them when doing var_dump or print_r on the $author object. The data object is used to "hide" these attributes behind the __get magic method, so accessing it directly would actually be wrong.

I added a commit to the branch to address this, checked on 3.2 and against current trunk, also escaping the author's posts URL, good catch!

@mfields mfields merged commit 800b9eb into Automattic:master Aug 27, 2012
@mfields
mfields commented Aug 27, 2012

@kovshenin Nice work on researching this! And thanks for trimming down the code in archive.php :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment