Accessing the current author or user
The WordPress template hierarchy defines a number of templates that can be used to display archived posts for a specific user in your WordPress site: author.php, author-$nicename.php, and author-$id.php.
Example 1: Accessing the current author
The WOOF::author method can also return specific authors (users), but will return the current author when no arguments are supplied.
The examples above would be suitable in the author.php series of templates, where you would generally display information about the author of the posts above a list of those posts.
The current post author in single templates
The methods used above to access the current author in an author archive both have a logical fallback if you’re not currently viewing an author archive – if we’re currently in a single template, the method will return the author of the current post instead. This lets you use code like in line 8 below, for a single template:
Example 2: Author methods fallback
Note that you could also rewrite line 8 above to access the author on the post object too:
Example 3: Accessing the author directly on $the
The current logged-in user
Example 4: Accessing the current logged-in user
The WOOF::user can also return specific authors (users), but will return the current user (if a user is logged in) when no arguments are supplied.
How to check if a user is logged in
The examples above made the assumption that a user is indeed logged in. This is obviously never guaranteed and there’s a few ways to check if there is a current user. First there’s the more traditional way: