Wordpress 角色显示名称 [英] Wordpress Role Display Name
问题描述
我正在寻找一种简洁的方法来获取 Wordpress 角色显示名称.
I am looking for a neat way to get the Wordpress role display name.
当您添加角色(例如 add_role( 'special', 'A Special Role');
)时,您可以设置显示名称.
When you add the role (e.g. add_role( 'special', 'A Special Role');
), you get to set a display name.
当您获得角色(例如 get_role( 'special' );
)时,返回的角色对象仅具有名称和功能对象.
When you get the role (e.g. get_role( 'special' );
) the role object returned simply has the name and the capabilities object.
WP_Role Object(
[name] => special
[capabilities] => Array() )
并且没有显示名称.显示名称在 WP Admin 后端(users.php 和 user-edit.php)中使用,但它是一个兔子窝……而且我还没有找到可以返回它的函数.您可以很容易地在 wp-options
表的 wp_user_roles
行中看到它 - 当然我不需要去那里?
And no display name. The display name is used all over the WP Admin back-end (users.php and user-edit.php), but it's a rabbit warren ... and I haven't been able to find a function that will return it. You can readily see it in the wp_user_roles
row in the wp-options
table - surely I don't need to go there?
推荐答案
如果您运行的是非英语 WordPress 站点并希望显示正确的(已翻译的)角色名称,就像它出现在所有 WordPress 管理页面中一样,以下是方法去做:
If you are running a non-english WordPress site and want to display the proper (translated) Role name, as it appears in all WordPress administration pages, here's how to do it:
global $wp_roles;
echo translate_user_role( $wp_roles->roles[ $role ]['name'] );
其中 $role
是角色名称(即原始问题中的 'special'
).
where $role
is the role name (i.e. 'special'
in the original question).
注意:translate_user_role 是一个 WordPress 核心功能,没有详细说明.
Note: translate_user_role is a WordPress core not-so-documented function.
这篇关于Wordpress 角色显示名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!