I’ve got an issue with author’s template. It works great and displays authors profiles as expected, but the issue is that you can see non-authors profiles also (contributors / subscribers, basically all registered users, including and admin) simply by substituting username in URL (www.mysite.com/author/subscribername).
Is there any simple way to fix it and show ‘authors’ profiles only and return ‘page not found’ for others?
In advance of your support, thank you.
Update:
Solution I’ve applied and will use (unless someone will advise how to amend the initial query). This returns proper ‘page not found’ page, including ‘page not found’ page title:
function tb_author_role_template( $templates="" )
{
global $wp_query;
$author = get_queried_object();
$role = $author->roles[0];
if($role == 'author')
{
$templates=locate_template(array("author.php",$templates),false);
} else { // error if not author
header( 'HTTP/1.0 404 Not Found' );
$templates = locate_template(array("404.php",$templates),false);
$wp_query->is_404 = true;
}
return $templates;
}
add_filter( 'author_template', 'tb_author_role_template' );