这是我的剧本列出了所有的角色..。
function all_the__roles() {
global $wp_roles;
$the_roles = $wp_roles->get_names();
$roles = '';
$role_count = '';
foreach($the_roles as $role) {
$roles .= $role . '<br />';
$role_count++;
}
return $roles;
}
echo all_the__roles();如果我将return $roles;更改为return $role_count;,则得到角色数。
有没有一种方法,我可以有这两种方式,而不必编写一个额外的单独的函数?我想列出角色和以及数字角色。所以输出可以是这样的:
Administrator
Editor
Client
3干杯。
发布于 2019-03-09 08:31:56
请试试这个
function all_the__roles() {
global $wp_roles;
$the_roles = $wp_roles->get_names();
$roles = '';
$role_count = 0;
foreach($the_roles as $role) {
$roles .= $role . '<br />';
$role_count++;
}
if($role_count > 0){
$roles .= $role_count . '<br />';
}
return $roles;
}
echo all_the__roles();https://stackoverflow.com/questions/55075400
复制相似问题