Php Wordpress-显示“;自定义作者角色名称";-已安装WP成员插件

Php Wordpress-显示“;自定义作者角色名称";-已安装WP成员插件,php,wordpress,Php,Wordpress,我试图显示自定义的作者名称,而不是使用WP_成员插件创建的名称。我在主题的function.php中使用了这个函数 function get_author_role_name(){ $role = get_the_author_meta('roles')['0']; echo esc_html($role); } 它工作正常,但它显示了角色的“slug”。我想显示的名称 示例名称:“我的自定义角色”,函数显示“我的自定义角色” 所以,我可以用空格“”替换“-”,我可以使用ucw

我试图显示自定义的作者名称,而不是使用WP_成员插件创建的名称。我在主题的function.php中使用了这个函数

function get_author_role_name(){
    $role = get_the_author_meta('roles')['0'];
    echo esc_html($role);
}
它工作正常,但它显示了角色的“slug”。我想显示的名称

示例名称:“我的自定义角色”,函数显示“我的自定义角色”

所以,我可以用空格“”替换“-”,我可以使用ucwords()函数,但是,有没有一个函数可以直接获取实名?我找不到它

谢谢

编辑-此处的解决方案:

function get_author_role_name(){
    $get_role = get_the_author_meta('roles')['0'];
    global $wp_roles;
    $role = $wp_roles->roles[$get_role]['name'];
    echo esc_html($role);
}
function get_author_role_name(){
    $get_role = get_the_author_meta('roles')['0'];
    global $wp_roles;
    $role = $wp_roles->roles[$get_role]['name'];
    echo esc_html($role);
}

基于以上链接,我编辑了我的函数,如下所示: