forked from nalarfag/GWU_Builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGWUUsercap.php
57 lines (55 loc) · 1.82 KB
/
GWUUsercap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Created by PhpStorm.
* User: Ashley
* Date: 4/19/14
* Time: 10:39 AM
*/
Class GWUUsercap {
function GWUUsercap(){
add_filter( 'editable_roles', array(&$this,'editable_roles'));
add_filter('map_meta_cap', array(&$this,'map_meta_cap'),10,4);
}
//Remove 'Administrator' from the list of roles if the current user is not an admin
function editable_roles($roles){
if( isset( $roles['administrator']) && !current_user_can('administrator')){
unset($roles['administrator']);
}
return $roles;
}
//if someone is trying to edit or delete, dont allow
function map_meta_cap( $caps, $cap, $user_id, $args ){
switch ( $cap ){
case 'edit_user':
case 'remove_user':
case 'promote_user':
if( isset($args[0]) && $args[0] == $user_id )
break;
elseif( !isset($args[0]) )
$caps[] = 'do_not_allow';
$other = new WP_User( absint($args[0]) );
if( $other->has_cap( 'administrator' ) ){
if(!current_user_can('administrator')){
$caps[] = 'do_not_allow';
}
}
break;
case 'delete_user':
case 'delete_users':
if( !isset($args[0]) )
break;
$other = new WP_User( absint($args[0]) );
if( $other->has_cap( 'administrator' ) ){
if(!current_user_can('administrator')){
$caps[] = 'do_not_allow';
}
}
break;
default:
break;
}
return $caps;
}
}
$gwu_user_cap = new GWUUsercap();
?>