bbpress.php
2.81 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* Support for bbPress user roles and capabilities
*
* Project: User Role Editor WordPress plugin
* Author: Vladimir Garagulya
* Author email: vladimir@shinephp.com
* Author URI: http://shinephp.com
*
**/
class URE_bbPress {
protected $bbpress_detected = false;
public function __construct() {
add_action('plugins_loaded', array($this, 'detect_bbpress'), 8 );
}
// end of __construct()
public function detect_bbpress() {
$this->bbpress_detected = false;
if ( function_exists('bbp_filter_blog_editable_roles') ) {
$this->bbpress_detected = true; // bbPress plugin is installed and active
}
}
// end of detect_bbpress()
public function is_active() {
return $this->bbpress_detected;
}
// end of is_active()
/**
* Exclude roles created by bbPress
*
* @global array $wp_roles
* @return array
*/
public function get_roles() {
$wp_roles = wp_roles();
if ($this->bbpress_detected) {
$roles = bbp_filter_blog_editable_roles( $wp_roles->roles ); // exclude bbPress roles
} else {
$roles = $wp_roles->roles;
}
return $roles;
}
// end of get_roles()
/**
* Get full list user capabilities created by bbPress
*
* @return array
*/
public function get_caps() {
if ( $this->bbpress_detected ) {
$caps = array_keys( bbp_get_caps_for_role( bbp_get_keymaster_role() ) );
} else {
$caps = array();
}
return $caps;
}
// end of get_caps()
/**
* Return empty array in order do not include bbPress roles into selectable lists: supported by Pro version only
* @return array
*/
public function get_bbp_editable_roles() {
$all_bbp_roles = array();
return $all_bbp_roles;
}
// end of get_bbp_editable_roles()
/**
* Return bbPress roles found at $roles array. Used to exclude bbPress roles from processing as free version should not support them
*
* @param array $roles
* @return array
*/
public function extract_bbp_roles($roles) {
$user_bbp_roles = array();
if ( $this->bbpress_detected ) {
$all_bbp_roles = array_keys( bbp_get_dynamic_roles() );
foreach( $roles as $role ) {
if ( in_array( $role, $all_bbp_roles ) ) {
$user_bbp_roles[] = $role;
}
}
}
return $user_bbp_roles;
}
// end of extract_bbp_roles()
}
// end of URE_bbPress class