Last active
April 6, 2018 01:28
-
-
Save spartie17/690e6b806a4ca56ad219263672baf44f to your computer and use it in GitHub Desktop.
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
// GIVE additional capabilities to 'Manager' | |
function additional_role_caps( $caps ) { | |
$user = wp_get_current_user(); | |
if ( in_array( 'manager', (array) $user->roles ) ) { | |
$caps[ 'edit_theme_options' ] = true; | |
$caps[ 'list_users' ] = true; | |
$caps[ 'create_users' ] = true; | |
$caps[ 'delete_users' ] = true; | |
$caps[ 'edit_users' ] = true; | |
$caps[ 'promote_users' ] = true; | |
} | |
return $caps; | |
} | |
add_filter( 'user_has_cap', 'additional_role_caps' ); |
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
// CREATE new role based on Editor | |
add_action('init', 'cloneUserRole'); | |
function cloneUserRole() { | |
global $wp_roles; | |
if (!isset($wp_roles)) | |
$wp_roles = new WP_Roles(); | |
$auth = $wp_roles->get_role('editor'); | |
$wp_roles->add_role('manager', 'Manager', $auth->capabilities); | |
} |
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
remove_role( 'author' ); |
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
// REMOVE 'Administrator' from the list of roles if the current user is not an admin | |
function remove_admin( $roles ){ | |
if( !current_user_can('administrator') ){ | |
unset( $roles['administrator']); | |
unset( $roles['manager']); | |
} | |
return $roles; | |
} | |
add_action('editable_roles','remove_admin'); |
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
// REMOVE Admin user 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