admin管理员组文章数量:1425240
I have a snippet in my functions.php that removes the admin role from the "change role to" drop down menu in the users listing screen, so that editors who can list users and manage roles won't be able to turn another user into an admin. The code below works perfectly.
function isa_pre_user_query($user_search) {
$user = wp_get_current_user();
if (!current_user_can('administrator')) { // Is Not Administrator - Remove Administrator
global $wpdb;
$user_search->query_where =
str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.ID IN (
SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
WHERE {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}capabilities'
AND {$wpdb->usermeta}.meta_value NOT LIKE '%administrator%')",
$user_search->query_where
);
}
}
add_action('pre_user_query','isa_pre_user_query');
Now, my question is, how can I also have the Editor role removed from that drop down, so that Editors cannot create other editors? I want to remove both the Admin and the Editor role from that drop-down menu, and restrict the role choices only to Author, Contributor and Subscriber.
Any ideas?
I have a snippet in my functions.php that removes the admin role from the "change role to" drop down menu in the users listing screen, so that editors who can list users and manage roles won't be able to turn another user into an admin. The code below works perfectly.
function isa_pre_user_query($user_search) {
$user = wp_get_current_user();
if (!current_user_can('administrator')) { // Is Not Administrator - Remove Administrator
global $wpdb;
$user_search->query_where =
str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.ID IN (
SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
WHERE {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}capabilities'
AND {$wpdb->usermeta}.meta_value NOT LIKE '%administrator%')",
$user_search->query_where
);
}
}
add_action('pre_user_query','isa_pre_user_query');
Now, my question is, how can I also have the Editor role removed from that drop down, so that Editors cannot create other editors? I want to remove both the Admin and the Editor role from that drop-down menu, and restrict the role choices only to Author, Contributor and Subscriber.
Any ideas?
Share Improve this question asked May 28, 2015 at 14:09 Ismael LatorreIsmael Latorre 451 silver badge7 bronze badges 2 |1 Answer
Reset to default 7Try using below code to remove administrator and editor option from drop down. Use
editable_roles
filter
function wdm_user_role_dropdown($all_roles) {
global $pagenow;
if( current_user_can('editor') && $pagenow == 'user-edit.php' ) {
// if current user is editor AND current page is edit user page
unset($all_roles['administrator']);
unset($all_roles['editor']);
}
return $all_roles;
}
add_filter('editable_roles','wdm_user_role_dropdown');
本文标签: Remove admin AND editor from the quotchange role toquot menu in user listing
版权声明:本文标题:Remove admin AND editor from the "change role to" menu in user listing 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745408184a2657344.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
NOT LIKE '$administrator%' OR '%editor%'
– flomei Commented May 28, 2015 at 14:51