更改:
$user_roles = $current_user->roles;
使用
$user = new WP_User( $user_id );
$user_roles = $user->roles;
$user\\u id应该是您试图获取的角色的实际用户id。
Update,
抱歉,我刚刚阅读了作者模板部分,请尝试以下操作:
//first get the current author whos page you are viewing
if(isset($_GET[\'author_name\']))
$curauth = get_user_by(\'slug\', $author_name);
else
$curauth = get_userdata(intval($author));
//then get the user object with roles
$user = new WP_User( $$curauth->ID );
$user_roles = $user->roles;
....