$authordata
is not available before the first post is set up (before the first the_post();
).
But all the data you need are already there on an author archive: in get_queried_object()
.
It is a WP_User Object
on the author archive.
print '<pre>' . htmlspecialchars( print_r( get_queried_object(), TRUE ) ) . '</pre>';
Result:
WP_User Object
(
[data] => stdClass Object
(
[ID] => 2
[user_login] => toscho
[user_pass] => $P$BO6.B4TIhxnKspIlxXHJCqa.M4I3v01
[user_nicename] => toscho
[user_email] => [email protected]
[user_url] =>
[user_registered] => 2011-12-25 15:20:12
[user_activation_key] =>
[user_status] => 0
[display_name] => toscho
)
[ID] => 2
[caps] => Array
(
=> 1
)
[cap_key] => test_capabilities
[roles] => Array
(
[0] => author
)
[allcaps] => Array
(
[upload_files] => 1
[edit_posts] => 1
[edit_published_posts] => 1
[publish_posts] => 1
[read] => 1
[level_2] => 1
[level_1] => 1
[level_0] => 1
[delete_posts] => 1
[delete_published_posts] => 1
=> 1
)
[filter] =>
)
So this will print the current author’s first role:
! empty ( get_queried_object()->roles )
and print ucfirst( get_queried_object()->roles[0] );