WordPress使用的函数名为get_editable_roles
, 它(我认为)用于确定特定用户可以编辑哪些角色。此函数的源如下所示:
function get_editable_roles() {
global $wp_roles;
$all_roles = $wp_roles->roles;
$editable_roles = apply_filters(\'editable_roles\', $all_roles);
return $editable_roles;
}
因此,看起来您可以挂接到*editable\\u roles*过滤器中,以获取您要查找的内容。类似这样:
function wpse_80220_filter( $roles ) {
$current_user = wp_get_current_user();
if ( in_array( \'editor\', $current_user->roles ) ) {
unset( $roles[\'administrator\'] );
}
return $roles;
}
add_filter( \'editable_roles\', \'wpse_80220_filter\' );
我还没有测试上面的任何代码,但请使用它,并让我知道它是否成功!