Created
March 28, 2014 04:26
-
-
Save dsebao/9825415 to your computer and use it in GitHub Desktop.
Let editors manage users in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// let editor manage users | |
$edit_editor = get_role('editor'); // Get the user role | |
$edit_editor->add_cap('list_users'); | |
$edit_editor->add_cap('create_users'); | |
$edit_editor->add_cap('delete_users'); | |
// hide admin from user list | |
add_action('pre_user_query','isa_pre_user_query'); | |
function isa_pre_user_query($user_search) { | |
$user = wp_get_current_user(); | |
if ($user->ID!=1) { // Is not administrator, remove administrator | |
global $wpdb; | |
$user_search->query_where = str_replace('WHERE 1=1', | |
"WHERE 1=1 AND {$wpdb->users}.ID<>1",$user_search->query_where); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment