Version Description
Download this release
Release Info
Developer | shinephp |
Plugin | User Role Editor |
Version | 4.61 |
Comparing to | |
See all releases |
Code changes from version 4.60.2 to 4.61
- includes/classes/ajax-processor.php +20 -15
- includes/classes/assign-role.php +9 -8
- includes/classes/base-lib.php +62 -58
- includes/classes/bbpress.php +9 -9
- includes/classes/capabilities-groups-manager.php +147 -67
- includes/classes/capabilities.php +12 -11
- includes/classes/capability.php +47 -33
- includes/classes/editor.php +1 -1
- includes/classes/tools.php +12 -8
- includes/classes/user-role-editor.php +2 -1
- js/settings.js +10 -2
- js/ure.js +7 -0
- readme.txt +17 -7
- user-role-editor.php +4 -4
includes/classes/ajax-processor.php
CHANGED
@@ -31,7 +31,7 @@ class URE_Ajax_Processor {
|
|
31 |
|
32 |
protected function get_action() {
|
33 |
$action = $this->lib->get_request_var( 'sub_action', 'post' );
|
34 |
-
if (empty($action)) {
|
35 |
$action = $this->lib->get_request_var( 'sub_action', 'get' );
|
36 |
}
|
37 |
|
@@ -42,7 +42,7 @@ class URE_Ajax_Processor {
|
|
42 |
|
43 |
protected function get_required_cap() {
|
44 |
|
45 |
-
if ($this->action=='grant_roles' || $this->action=='get_user_roles') {
|
46 |
$cap = 'promote_users';
|
47 |
} else {
|
48 |
$cap = URE_Own_Capabilities::get_key_capability();
|
@@ -55,8 +55,8 @@ class URE_Ajax_Processor {
|
|
55 |
|
56 |
protected function valid_nonce() {
|
57 |
|
58 |
-
if ( !isset($_REQUEST['wp_nonce']) || !wp_verify_nonce( $_REQUEST['wp_nonce'], 'user-role-editor' ) ) {
|
59 |
-
echo json_encode(array('result'=>'error', 'message'=>'URE: Wrong or expired request'));
|
60 |
return false;
|
61 |
} else {
|
62 |
return true;
|
@@ -89,7 +89,7 @@ class URE_Ajax_Processor {
|
|
89 |
'role_id'=>$response['role_id'],
|
90 |
'role_name'=>$response['role_name'],
|
91 |
'message'=>$response['message']
|
92 |
-
|
93 |
|
94 |
return $answer;
|
95 |
}
|
@@ -106,7 +106,7 @@ class URE_Ajax_Processor {
|
|
106 |
'role_id'=>$response['role_id'],
|
107 |
'role_name'=>$response['role_name'],
|
108 |
'message'=>$response['message']
|
109 |
-
|
110 |
|
111 |
return $answer;
|
112 |
}
|
@@ -177,7 +177,7 @@ class URE_Ajax_Processor {
|
|
177 |
'message'=>$response['message'],
|
178 |
'role_id'=> $response['role_id'],
|
179 |
'role_name'=>$response['role_name']
|
180 |
-
|
181 |
|
182 |
return $answer;
|
183 |
}
|
@@ -197,24 +197,29 @@ class URE_Ajax_Processor {
|
|
197 |
protected function get_users_without_role() {
|
198 |
|
199 |
$new_role = $this->lib->get_request_var( 'new_role', 'post' );
|
200 |
-
if (empty($new_role)) {
|
201 |
$answer = array('result'=>'error', 'message'=>'Provide new role');
|
202 |
return $answer;
|
203 |
}
|
204 |
|
205 |
$assign_role = $this->lib->get_assign_role();
|
206 |
-
if ($new_role==='no_rights') {
|
207 |
$assign_role->create_no_rights_role();
|
208 |
}
|
209 |
|
210 |
$wp_roles = wp_roles();
|
211 |
-
if (!isset($wp_roles->roles[$new_role])) {
|
212 |
$answer = array('result'=>'error', 'message'=>'Selected new role does not exist');
|
213 |
return $answer;
|
214 |
}
|
215 |
|
216 |
$users = $assign_role->get_users_without_role();
|
217 |
-
$answer = array(
|
|
|
|
|
|
|
|
|
|
|
218 |
|
219 |
return $answer;
|
220 |
}
|
@@ -244,19 +249,19 @@ class URE_Ajax_Processor {
|
|
244 |
protected function get_role_caps() {
|
245 |
|
246 |
$role = $this->lib->get_request_var('role', 'post' );
|
247 |
-
if (empty($role)) {
|
248 |
$answer = array('result'=>'error', 'message'=>'Provide role ID');
|
249 |
return $answer;
|
250 |
}
|
251 |
|
252 |
$wp_roles = wp_roles();
|
253 |
-
if (!isset($wp_roles->roles[$role])) {
|
254 |
$answer = array('result'=>'error', 'message'=>'Requested role does not exist');
|
255 |
return $answer;
|
256 |
}
|
257 |
|
258 |
$active_items = URE_Role_Additional_Options::get_active_items();
|
259 |
-
if (isset($active_items[$role])) {
|
260 |
$role_options = $active_items[$role];
|
261 |
} else {
|
262 |
$role_options = array();
|
@@ -299,7 +304,7 @@ class URE_Ajax_Processor {
|
|
299 |
|
300 |
protected function _dispatch() {
|
301 |
|
302 |
-
switch ($this->action) {
|
303 |
case 'update_role':
|
304 |
$answer = $this->update_role();
|
305 |
break;
|
31 |
|
32 |
protected function get_action() {
|
33 |
$action = $this->lib->get_request_var( 'sub_action', 'post' );
|
34 |
+
if ( empty( $action ) ) {
|
35 |
$action = $this->lib->get_request_var( 'sub_action', 'get' );
|
36 |
}
|
37 |
|
42 |
|
43 |
protected function get_required_cap() {
|
44 |
|
45 |
+
if ( $this->action=='grant_roles' || $this->action=='get_user_roles' ) {
|
46 |
$cap = 'promote_users';
|
47 |
} else {
|
48 |
$cap = URE_Own_Capabilities::get_key_capability();
|
55 |
|
56 |
protected function valid_nonce() {
|
57 |
|
58 |
+
if ( !isset( $_REQUEST['wp_nonce'] ) || !wp_verify_nonce( $_REQUEST['wp_nonce'], 'user-role-editor' ) ) {
|
59 |
+
echo json_encode( array('result'=>'error', 'message'=>'URE: Wrong or expired request') );
|
60 |
return false;
|
61 |
} else {
|
62 |
return true;
|
89 |
'role_id'=>$response['role_id'],
|
90 |
'role_name'=>$response['role_name'],
|
91 |
'message'=>$response['message']
|
92 |
+
);
|
93 |
|
94 |
return $answer;
|
95 |
}
|
106 |
'role_id'=>$response['role_id'],
|
107 |
'role_name'=>$response['role_name'],
|
108 |
'message'=>$response['message']
|
109 |
+
);
|
110 |
|
111 |
return $answer;
|
112 |
}
|
177 |
'message'=>$response['message'],
|
178 |
'role_id'=> $response['role_id'],
|
179 |
'role_name'=>$response['role_name']
|
180 |
+
);
|
181 |
|
182 |
return $answer;
|
183 |
}
|
197 |
protected function get_users_without_role() {
|
198 |
|
199 |
$new_role = $this->lib->get_request_var( 'new_role', 'post' );
|
200 |
+
if ( empty( $new_role ) ) {
|
201 |
$answer = array('result'=>'error', 'message'=>'Provide new role');
|
202 |
return $answer;
|
203 |
}
|
204 |
|
205 |
$assign_role = $this->lib->get_assign_role();
|
206 |
+
if ( $new_role==='no_rights') {
|
207 |
$assign_role->create_no_rights_role();
|
208 |
}
|
209 |
|
210 |
$wp_roles = wp_roles();
|
211 |
+
if ( !isset( $wp_roles->roles[$new_role] ) ) {
|
212 |
$answer = array('result'=>'error', 'message'=>'Selected new role does not exist');
|
213 |
return $answer;
|
214 |
}
|
215 |
|
216 |
$users = $assign_role->get_users_without_role();
|
217 |
+
$answer = array(
|
218 |
+
'result'=>'success',
|
219 |
+
'users'=>$users,
|
220 |
+
'new_role'=>$new_role,
|
221 |
+
'message'=>'success'
|
222 |
+
);
|
223 |
|
224 |
return $answer;
|
225 |
}
|
249 |
protected function get_role_caps() {
|
250 |
|
251 |
$role = $this->lib->get_request_var('role', 'post' );
|
252 |
+
if ( empty( $role ) ) {
|
253 |
$answer = array('result'=>'error', 'message'=>'Provide role ID');
|
254 |
return $answer;
|
255 |
}
|
256 |
|
257 |
$wp_roles = wp_roles();
|
258 |
+
if ( !isset( $wp_roles->roles[$role] ) ) {
|
259 |
$answer = array('result'=>'error', 'message'=>'Requested role does not exist');
|
260 |
return $answer;
|
261 |
}
|
262 |
|
263 |
$active_items = URE_Role_Additional_Options::get_active_items();
|
264 |
+
if ( isset( $active_items[$role] ) ) {
|
265 |
$role_options = $active_items[$role];
|
266 |
} else {
|
267 |
$role_options = array();
|
304 |
|
305 |
protected function _dispatch() {
|
306 |
|
307 |
+
switch ( $this->action ) {
|
308 |
case 'update_role':
|
309 |
$answer = $this->update_role();
|
310 |
break;
|
includes/classes/assign-role.php
CHANGED
@@ -33,17 +33,18 @@ class URE_Assign_Role {
|
|
33 |
$role_name = 'No rights';
|
34 |
|
35 |
$wp_roles = wp_roles();
|
36 |
-
if (isset($wp_roles->roles[$role_id])) {
|
37 |
return;
|
38 |
}
|
39 |
|
40 |
-
add_role($role_id, $role_name, array());
|
41 |
|
42 |
}
|
43 |
// end of create_no_rights_role()
|
44 |
|
45 |
|
46 |
private function count_quick_or_thoroughly() {
|
|
|
47 |
$quick_count = true;
|
48 |
if ( defined('URE_COUNT_USERS_WITHOUT_ROLE_THOROUGHLY') && URE_COUNT_USERS_WITHOUT_ROLE_THOROUGHLY ) {
|
49 |
$quick_count = false;
|
@@ -54,7 +55,7 @@ class URE_Assign_Role {
|
|
54 |
}
|
55 |
}
|
56 |
|
57 |
-
$quick_count = apply_filters('ure_count_users_without_role_quick', $quick_count);
|
58 |
|
59 |
return $quick_count;
|
60 |
}
|
@@ -66,7 +67,7 @@ class URE_Assign_Role {
|
|
66 |
|
67 |
$usermeta = $wpdb->usermeta;
|
68 |
$id = get_current_blog_id();
|
69 |
-
$blog_prefix = $wpdb->get_blog_prefix($id);
|
70 |
$where = "WHERE NOT EXISTS (SELECT user_id from {$usermeta} ".
|
71 |
"WHERE user_id=users.ID AND meta_key='{$blog_prefix}capabilities') OR ".
|
72 |
"EXISTS (SELECT user_id FROM {$usermeta} ".
|
@@ -117,8 +118,8 @@ class URE_Assign_Role {
|
|
117 |
$users_quant = get_transient('ure_users_without_role');
|
118 |
if (empty($users_quant)) {
|
119 |
$query = $this->get_users_count_query();
|
120 |
-
$users_quant = $wpdb->get_var($query);
|
121 |
-
set_transient('ure_users_without_role', $users_quant, 15);
|
122 |
}
|
123 |
|
124 |
return $users_quant;
|
@@ -141,7 +142,7 @@ class URE_Assign_Role {
|
|
141 |
{$where}
|
142 |
LIMIT 0, {$top_limit}";
|
143 |
}
|
144 |
-
$users0 = $wpdb->get_col($query);
|
145 |
|
146 |
return $users0;
|
147 |
}
|
@@ -160,7 +161,7 @@ class URE_Assign_Role {
|
|
160 |
<input type="button" name="move_from_no_role<?php echo $button_number;?>" id="move_from_no_role<?php echo $button_number;?>" class="button"
|
161 |
value="Without role (<?php echo $users_quant;?>)" onclick="ure_move_users_from_no_role_dialog()">
|
162 |
<?php
|
163 |
-
if (self::$counter==0) {
|
164 |
?>
|
165 |
<div id="move_from_no_role_dialog" class="ure-dialog">
|
166 |
<div id="move_from_no_role_content" style="padding: 10px;"></div>
|
33 |
$role_name = 'No rights';
|
34 |
|
35 |
$wp_roles = wp_roles();
|
36 |
+
if ( isset( $wp_roles->roles[$role_id] ) ) {
|
37 |
return;
|
38 |
}
|
39 |
|
40 |
+
add_role( $role_id, $role_name, array() );
|
41 |
|
42 |
}
|
43 |
// end of create_no_rights_role()
|
44 |
|
45 |
|
46 |
private function count_quick_or_thoroughly() {
|
47 |
+
|
48 |
$quick_count = true;
|
49 |
if ( defined('URE_COUNT_USERS_WITHOUT_ROLE_THOROUGHLY') && URE_COUNT_USERS_WITHOUT_ROLE_THOROUGHLY ) {
|
50 |
$quick_count = false;
|
55 |
}
|
56 |
}
|
57 |
|
58 |
+
$quick_count = apply_filters('ure_count_users_without_role_quick', $quick_count );
|
59 |
|
60 |
return $quick_count;
|
61 |
}
|
67 |
|
68 |
$usermeta = $wpdb->usermeta;
|
69 |
$id = get_current_blog_id();
|
70 |
+
$blog_prefix = $wpdb->get_blog_prefix( $id );
|
71 |
$where = "WHERE NOT EXISTS (SELECT user_id from {$usermeta} ".
|
72 |
"WHERE user_id=users.ID AND meta_key='{$blog_prefix}capabilities') OR ".
|
73 |
"EXISTS (SELECT user_id FROM {$usermeta} ".
|
118 |
$users_quant = get_transient('ure_users_without_role');
|
119 |
if (empty($users_quant)) {
|
120 |
$query = $this->get_users_count_query();
|
121 |
+
$users_quant = $wpdb->get_var( $query );
|
122 |
+
set_transient('ure_users_without_role', $users_quant, 15 );
|
123 |
}
|
124 |
|
125 |
return $users_quant;
|
142 |
{$where}
|
143 |
LIMIT 0, {$top_limit}";
|
144 |
}
|
145 |
+
$users0 = $wpdb->get_col( $query );
|
146 |
|
147 |
return $users0;
|
148 |
}
|
161 |
<input type="button" name="move_from_no_role<?php echo $button_number;?>" id="move_from_no_role<?php echo $button_number;?>" class="button"
|
162 |
value="Without role (<?php echo $users_quant;?>)" onclick="ure_move_users_from_no_role_dialog()">
|
163 |
<?php
|
164 |
+
if ( self::$counter==0 ) {
|
165 |
?>
|
166 |
<div id="move_from_no_role_dialog" class="ure-dialog">
|
167 |
<div id="move_from_no_role_content" style="padding: 10px;"></div>
|
includes/classes/base-lib.php
CHANGED
@@ -21,9 +21,9 @@ class URE_Base_Lib {
|
|
21 |
protected $main_blog_id = 0;
|
22 |
|
23 |
|
24 |
-
public static function get_instance($options_id = '') {
|
25 |
-
if (self::$instance===null) {
|
26 |
-
self::$instance = new URE_Base_Lib($options_id);
|
27 |
}
|
28 |
|
29 |
return self::$instance;
|
@@ -35,7 +35,7 @@ class URE_Base_Lib {
|
|
35 |
* class constructor
|
36 |
* @param string $options_id to save/retrieve plugin options to/from wp_option DB table
|
37 |
*/
|
38 |
-
protected function __construct($options_id) {
|
39 |
|
40 |
$this->multisite = function_exists( 'is_multisite' ) && is_multisite();
|
41 |
if ( $this->multisite ) {
|
@@ -49,10 +49,10 @@ class URE_Base_Lib {
|
|
49 |
// end of __construct()
|
50 |
|
51 |
|
52 |
-
public function get($property_name) {
|
53 |
|
54 |
-
if (!property_exists($this, $property_name)) {
|
55 |
-
syslog(LOG_ERR, 'Lib class does not have such property '. $property_name);
|
56 |
return null;
|
57 |
}
|
58 |
|
@@ -61,10 +61,10 @@ class URE_Base_Lib {
|
|
61 |
// end of get_property()
|
62 |
|
63 |
|
64 |
-
public function set($property_name, $property_value) {
|
65 |
|
66 |
-
if (!property_exists($this, $property_name)) {
|
67 |
-
syslog(LOG_ERR, 'Lib class does not have such property '. $property_name);
|
68 |
}
|
69 |
|
70 |
$this->$property_name = $property_value;
|
@@ -75,7 +75,7 @@ class URE_Base_Lib {
|
|
75 |
public function get_main_site() {
|
76 |
global $current_site;
|
77 |
|
78 |
-
$blog_id = is_object($current_site) ? $current_site->blog_id : null;
|
79 |
|
80 |
return $blog_id;
|
81 |
}
|
@@ -99,10 +99,10 @@ class URE_Base_Lib {
|
|
99 |
* @param string $message message text
|
100 |
* @param string $error_style message div CSS style
|
101 |
*/
|
102 |
-
public function show_message($message, $error_style = false) {
|
103 |
|
104 |
-
if ($message) {
|
105 |
-
if ($error_style) {
|
106 |
echo '<div id="message" class="error">';
|
107 |
} else {
|
108 |
echo '<div id="message" class="updated fade">';
|
@@ -121,21 +121,21 @@ class URE_Base_Lib {
|
|
121 |
* @param string $var_type variable type to provide value checking
|
122 |
* @return mix variable value from request
|
123 |
*/
|
124 |
-
public function get_request_var($var_name, $request_type = 'request', $var_type = 'string') {
|
125 |
|
126 |
$result = 0;
|
127 |
-
$request_type = strtolower($request_type);
|
128 |
-
switch ($request_type) {
|
129 |
case 'get': {
|
130 |
-
if (isset($_GET[$var_name])) {
|
131 |
-
$result = filter_var($_GET[$var_name], FILTER_SANITIZE_STRING);
|
132 |
}
|
133 |
break;
|
134 |
}
|
135 |
case 'post': {
|
136 |
-
if (isset($_POST[$var_name])) {
|
137 |
-
if ($var_type!='checkbox') {
|
138 |
-
$result = filter_var($_POST[$var_name], FILTER_SANITIZE_STRING);
|
139 |
} else {
|
140 |
$result = 1;
|
141 |
}
|
@@ -143,8 +143,8 @@ class URE_Base_Lib {
|
|
143 |
break;
|
144 |
}
|
145 |
case 'request': {
|
146 |
-
if (isset($_REQUEST[$var_name])) {
|
147 |
-
$result = filter_var($_REQUEST[$var_name], FILTER_SANITIZE_STRING);
|
148 |
}
|
149 |
break;
|
150 |
}
|
@@ -153,12 +153,12 @@ class URE_Base_Lib {
|
|
153 |
}
|
154 |
}
|
155 |
|
156 |
-
if ($result) {
|
157 |
-
if ($var_type == 'int' && !is_numeric($result)) {
|
158 |
$result = 0;
|
159 |
}
|
160 |
-
if ($var_type != 'int') {
|
161 |
-
$result = esc_attr($result);
|
162 |
}
|
163 |
}
|
164 |
|
@@ -170,14 +170,14 @@ class URE_Base_Lib {
|
|
170 |
/**
|
171 |
* returns option value for option with name in $option_name
|
172 |
*/
|
173 |
-
public function get_option($option_name, $default = false) {
|
174 |
|
175 |
-
if (isset($this->options[$option_name])) {
|
176 |
$value = $this->options[$option_name];
|
177 |
} else {
|
178 |
$value = $default;
|
179 |
}
|
180 |
-
$value = apply_filters('ure_get_option_'. $option_name, $value);
|
181 |
|
182 |
return $value;
|
183 |
}
|
@@ -187,53 +187,56 @@ class URE_Base_Lib {
|
|
187 |
/**
|
188 |
* puts option value according to $option_name option name into options array property
|
189 |
*/
|
190 |
-
public function put_option($option_name, $option_value, $flush_options = false) {
|
191 |
|
192 |
$this->options[$option_name] = $option_value;
|
193 |
-
if ($flush_options) {
|
194 |
$this->flush_options();
|
195 |
}
|
196 |
}
|
197 |
// end of put_option()
|
|
|
198 |
|
199 |
/**
|
200 |
* Delete URE option with name option_name
|
201 |
* @param string $option_name
|
202 |
* @param bool $flush_options
|
203 |
*/
|
204 |
-
public function delete_option($option_name, $flush_options = false) {
|
205 |
-
if (array_key_exists($option_name, $this->options)) {
|
206 |
-
unset($this->options[$option_name]);
|
207 |
-
if ($flush_options) {
|
208 |
$this->flush_options();
|
209 |
}
|
210 |
}
|
211 |
}
|
212 |
// end of delete_option()
|
213 |
|
|
|
214 |
/**
|
215 |
-
*
|
216 |
*/
|
217 |
public function flush_options() {
|
218 |
|
219 |
-
update_option($this->options_id, $this->options);
|
220 |
}
|
221 |
// end of flush_options()
|
222 |
|
|
|
223 |
/**
|
224 |
-
* Check product version and stop execution if product version is not compatible
|
225 |
* @param string $version1
|
226 |
* @param string $version2
|
227 |
* @param string $error_message
|
228 |
* @return void
|
229 |
*/
|
230 |
-
public static function check_version($version1, $version2, $error_message, $plugin_file_name) {
|
231 |
|
232 |
-
if (version_compare($version1, $version2, '<')) {
|
233 |
-
if (is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX )) {
|
234 |
require_once ABSPATH . '/wp-admin/includes/plugin.php';
|
235 |
-
deactivate_plugins($plugin_file_name);
|
236 |
-
wp_die($error_message);
|
237 |
} else {
|
238 |
return;
|
239 |
}
|
@@ -244,7 +247,8 @@ class URE_Base_Lib {
|
|
244 |
|
245 |
public function get_current_url() {
|
246 |
global $wp;
|
247 |
-
|
|
|
248 |
|
249 |
return $current_url;
|
250 |
}
|
@@ -258,23 +262,23 @@ class URE_Base_Lib {
|
|
258 |
* @param int $items_count
|
259 |
* @return string
|
260 |
*/
|
261 |
-
public function get_short_list_str($full_list, $items_count=3) {
|
262 |
|
263 |
-
if (empty($full_list) || !is_array($full_list)) {
|
264 |
return '...';
|
265 |
}
|
266 |
|
267 |
$short_list = array(); $i = 0;
|
268 |
foreach($full_list as $item) {
|
269 |
-
if ($i>=$items_count) {
|
270 |
break;
|
271 |
}
|
272 |
$short_list[] = $item;
|
273 |
$i++;
|
274 |
}
|
275 |
|
276 |
-
$str = implode(', ', $short_list);
|
277 |
-
if ($items_count<count($full_list)) {
|
278 |
$str .= ', ...';
|
279 |
}
|
280 |
|
@@ -290,23 +294,23 @@ class URE_Base_Lib {
|
|
290 |
* @param array $list_values: array of integers or strings
|
291 |
* @return string - comma separated values (CSV)
|
292 |
*/
|
293 |
-
public static function esc_sql_in_list($list_type, $list_values) {
|
294 |
global $wpdb;
|
295 |
|
296 |
-
if (empty($list_values) || !is_array($list_values) || count($list_values)==0) {
|
297 |
return '';
|
298 |
}
|
299 |
|
300 |
-
if ($list_type=='int') {
|
301 |
$placeholder = '%d'; // Integer
|
302 |
} else {
|
303 |
$placeholder = '%s'; // String
|
304 |
}
|
305 |
|
306 |
-
$placeholders = array_fill(0, count($list_values), $placeholder);
|
307 |
-
$format_str = implode(',', $placeholders);
|
308 |
|
309 |
-
$result = $wpdb->prepare($format_str, $list_values);
|
310 |
|
311 |
return $result;
|
312 |
}
|
@@ -321,7 +325,7 @@ class URE_Base_Lib {
|
|
321 |
public function get_blog_ids() {
|
322 |
global $wpdb;
|
323 |
|
324 |
-
if (!$this->multisite) {
|
325 |
return null;
|
326 |
}
|
327 |
|
21 |
protected $main_blog_id = 0;
|
22 |
|
23 |
|
24 |
+
public static function get_instance( $options_id = '') {
|
25 |
+
if ( self::$instance===null ) {
|
26 |
+
self::$instance = new URE_Base_Lib( $options_id );
|
27 |
}
|
28 |
|
29 |
return self::$instance;
|
35 |
* class constructor
|
36 |
* @param string $options_id to save/retrieve plugin options to/from wp_option DB table
|
37 |
*/
|
38 |
+
protected function __construct( $options_id ) {
|
39 |
|
40 |
$this->multisite = function_exists( 'is_multisite' ) && is_multisite();
|
41 |
if ( $this->multisite ) {
|
49 |
// end of __construct()
|
50 |
|
51 |
|
52 |
+
public function get( $property_name ) {
|
53 |
|
54 |
+
if ( !property_exists( $this, $property_name ) ) {
|
55 |
+
syslog( LOG_ERR, 'Lib class does not have such property '. $property_name );
|
56 |
return null;
|
57 |
}
|
58 |
|
61 |
// end of get_property()
|
62 |
|
63 |
|
64 |
+
public function set( $property_name, $property_value ) {
|
65 |
|
66 |
+
if ( !property_exists( $this, $property_name ) ) {
|
67 |
+
syslog( LOG_ERR, 'Lib class does not have such property '. $property_name );
|
68 |
}
|
69 |
|
70 |
$this->$property_name = $property_value;
|
75 |
public function get_main_site() {
|
76 |
global $current_site;
|
77 |
|
78 |
+
$blog_id = is_object( $current_site ) ? $current_site->blog_id : null;
|
79 |
|
80 |
return $blog_id;
|
81 |
}
|
99 |
* @param string $message message text
|
100 |
* @param string $error_style message div CSS style
|
101 |
*/
|
102 |
+
public function show_message( $message, $error_style = false ) {
|
103 |
|
104 |
+
if ( $message ) {
|
105 |
+
if ( $error_style ) {
|
106 |
echo '<div id="message" class="error">';
|
107 |
} else {
|
108 |
echo '<div id="message" class="updated fade">';
|
121 |
* @param string $var_type variable type to provide value checking
|
122 |
* @return mix variable value from request
|
123 |
*/
|
124 |
+
public function get_request_var( $var_name, $request_type = 'request', $var_type = 'string') {
|
125 |
|
126 |
$result = 0;
|
127 |
+
$request_type = strtolower( $request_type );
|
128 |
+
switch ( $request_type ) {
|
129 |
case 'get': {
|
130 |
+
if ( isset( $_GET[$var_name] ) ) {
|
131 |
+
$result = filter_var( $_GET[$var_name], FILTER_SANITIZE_STRING );
|
132 |
}
|
133 |
break;
|
134 |
}
|
135 |
case 'post': {
|
136 |
+
if ( isset( $_POST[$var_name] ) ) {
|
137 |
+
if ( $var_type!='checkbox') {
|
138 |
+
$result = filter_var( $_POST[$var_name], FILTER_SANITIZE_STRING );
|
139 |
} else {
|
140 |
$result = 1;
|
141 |
}
|
143 |
break;
|
144 |
}
|
145 |
case 'request': {
|
146 |
+
if ( isset( $_REQUEST[$var_name] ) ) {
|
147 |
+
$result = filter_var( $_REQUEST[$var_name], FILTER_SANITIZE_STRING );
|
148 |
}
|
149 |
break;
|
150 |
}
|
153 |
}
|
154 |
}
|
155 |
|
156 |
+
if ( $result ) {
|
157 |
+
if ( $var_type == 'int' && !is_numeric( $result ) ) {
|
158 |
$result = 0;
|
159 |
}
|
160 |
+
if ( $var_type != 'int') {
|
161 |
+
$result = esc_attr( $result );
|
162 |
}
|
163 |
}
|
164 |
|
170 |
/**
|
171 |
* returns option value for option with name in $option_name
|
172 |
*/
|
173 |
+
public function get_option( $option_name, $default = false ) {
|
174 |
|
175 |
+
if ( isset( $this->options[$option_name] ) ) {
|
176 |
$value = $this->options[$option_name];
|
177 |
} else {
|
178 |
$value = $default;
|
179 |
}
|
180 |
+
$value = apply_filters('ure_get_option_'. $option_name, $value );
|
181 |
|
182 |
return $value;
|
183 |
}
|
187 |
/**
|
188 |
* puts option value according to $option_name option name into options array property
|
189 |
*/
|
190 |
+
public function put_option( $option_name, $option_value, $flush_options = false ) {
|
191 |
|
192 |
$this->options[$option_name] = $option_value;
|
193 |
+
if ( $flush_options ) {
|
194 |
$this->flush_options();
|
195 |
}
|
196 |
}
|
197 |
// end of put_option()
|
198 |
+
|
199 |
|
200 |
/**
|
201 |
* Delete URE option with name option_name
|
202 |
* @param string $option_name
|
203 |
* @param bool $flush_options
|
204 |
*/
|
205 |
+
public function delete_option( $option_name, $flush_options = false ) {
|
206 |
+
if ( array_key_exists( $option_name, $this->options ) ) {
|
207 |
+
unset( $this->options[$option_name] );
|
208 |
+
if ( $flush_options ) {
|
209 |
$this->flush_options();
|
210 |
}
|
211 |
}
|
212 |
}
|
213 |
// end of delete_option()
|
214 |
|
215 |
+
|
216 |
/**
|
217 |
+
* Saves options array into WordPress database wp_options table
|
218 |
*/
|
219 |
public function flush_options() {
|
220 |
|
221 |
+
update_option( $this->options_id, $this->options );
|
222 |
}
|
223 |
// end of flush_options()
|
224 |
|
225 |
+
|
226 |
/**
|
227 |
+
* Check product version and stop execution if product version is not compatible with required one
|
228 |
* @param string $version1
|
229 |
* @param string $version2
|
230 |
* @param string $error_message
|
231 |
* @return void
|
232 |
*/
|
233 |
+
public static function check_version( $version1, $version2, $error_message, $plugin_file_name ) {
|
234 |
|
235 |
+
if ( version_compare($version1, $version2, '<') ) {
|
236 |
+
if ( is_admin() && ( !defined('DOING_AJAX') || !DOING_AJAX ) ) {
|
237 |
require_once ABSPATH . '/wp-admin/includes/plugin.php';
|
238 |
+
deactivate_plugins( $plugin_file_name );
|
239 |
+
wp_die( $error_message );
|
240 |
} else {
|
241 |
return;
|
242 |
}
|
247 |
|
248 |
public function get_current_url() {
|
249 |
global $wp;
|
250 |
+
|
251 |
+
$current_url = esc_url_raw( add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) );
|
252 |
|
253 |
return $current_url;
|
254 |
}
|
262 |
* @param int $items_count
|
263 |
* @return string
|
264 |
*/
|
265 |
+
public function get_short_list_str( $full_list, $items_count=3 ) {
|
266 |
|
267 |
+
if ( empty( $full_list ) || !is_array( $full_list ) ) {
|
268 |
return '...';
|
269 |
}
|
270 |
|
271 |
$short_list = array(); $i = 0;
|
272 |
foreach($full_list as $item) {
|
273 |
+
if ( $i>=$items_count ) {
|
274 |
break;
|
275 |
}
|
276 |
$short_list[] = $item;
|
277 |
$i++;
|
278 |
}
|
279 |
|
280 |
+
$str = implode(', ', $short_list );
|
281 |
+
if ( $items_count<count( $full_list ) ) {
|
282 |
$str .= ', ...';
|
283 |
}
|
284 |
|
294 |
* @param array $list_values: array of integers or strings
|
295 |
* @return string - comma separated values (CSV)
|
296 |
*/
|
297 |
+
public static function esc_sql_in_list( $list_type, $list_values ) {
|
298 |
global $wpdb;
|
299 |
|
300 |
+
if ( empty( $list_values ) || !is_array( $list_values ) || count( $list_values )==0 ) {
|
301 |
return '';
|
302 |
}
|
303 |
|
304 |
+
if ( $list_type=='int' ) {
|
305 |
$placeholder = '%d'; // Integer
|
306 |
} else {
|
307 |
$placeholder = '%s'; // String
|
308 |
}
|
309 |
|
310 |
+
$placeholders = array_fill( 0, count( $list_values ), $placeholder );
|
311 |
+
$format_str = implode(',', $placeholders );
|
312 |
|
313 |
+
$result = $wpdb->prepare( $format_str, $list_values );
|
314 |
|
315 |
return $result;
|
316 |
}
|
325 |
public function get_blog_ids() {
|
326 |
global $wpdb;
|
327 |
|
328 |
+
if ( !$this->multisite ) {
|
329 |
return null;
|
330 |
}
|
331 |
|
includes/classes/bbpress.php
CHANGED
@@ -16,7 +16,7 @@ class URE_bbPress {
|
|
16 |
|
17 |
public function __construct() {
|
18 |
|
19 |
-
add_action('plugins_loaded', array($this, 'detect_bbpress'), 8);
|
20 |
}
|
21 |
// end of __construct()
|
22 |
|
@@ -24,7 +24,7 @@ class URE_bbPress {
|
|
24 |
public function detect_bbpress() {
|
25 |
|
26 |
$this->bbpress_detected = false;
|
27 |
-
if (function_exists('bbp_filter_blog_editable_roles')) {
|
28 |
$this->bbpress_detected = true; // bbPress plugin is installed and active
|
29 |
}
|
30 |
|
@@ -49,7 +49,7 @@ class URE_bbPress {
|
|
49 |
|
50 |
$wp_roles = wp_roles();
|
51 |
if ($this->bbpress_detected) {
|
52 |
-
$roles = bbp_filter_blog_editable_roles($wp_roles->roles); // exclude bbPress roles
|
53 |
} else {
|
54 |
$roles = $wp_roles->roles;
|
55 |
}
|
@@ -66,8 +66,8 @@ class URE_bbPress {
|
|
66 |
*/
|
67 |
public function get_caps() {
|
68 |
|
69 |
-
if ($this->bbpress_detected) {
|
70 |
-
$caps = array_keys(bbp_get_caps_for_role(bbp_get_keymaster_role()));
|
71 |
} else {
|
72 |
$caps = array();
|
73 |
}
|
@@ -99,10 +99,10 @@ class URE_bbPress {
|
|
99 |
public function extract_bbp_roles($roles) {
|
100 |
|
101 |
$user_bbp_roles = array();
|
102 |
-
if ($this->bbpress_detected) {
|
103 |
-
$all_bbp_roles = array_keys(bbp_get_dynamic_roles());
|
104 |
-
foreach($roles as $role) {
|
105 |
-
if (in_array($role, $all_bbp_roles)) {
|
106 |
$user_bbp_roles[] = $role;
|
107 |
}
|
108 |
}
|
16 |
|
17 |
public function __construct() {
|
18 |
|
19 |
+
add_action('plugins_loaded', array($this, 'detect_bbpress'), 8 );
|
20 |
}
|
21 |
// end of __construct()
|
22 |
|
24 |
public function detect_bbpress() {
|
25 |
|
26 |
$this->bbpress_detected = false;
|
27 |
+
if ( function_exists('bbp_filter_blog_editable_roles') ) {
|
28 |
$this->bbpress_detected = true; // bbPress plugin is installed and active
|
29 |
}
|
30 |
|
49 |
|
50 |
$wp_roles = wp_roles();
|
51 |
if ($this->bbpress_detected) {
|
52 |
+
$roles = bbp_filter_blog_editable_roles( $wp_roles->roles ); // exclude bbPress roles
|
53 |
} else {
|
54 |
$roles = $wp_roles->roles;
|
55 |
}
|
66 |
*/
|
67 |
public function get_caps() {
|
68 |
|
69 |
+
if ( $this->bbpress_detected ) {
|
70 |
+
$caps = array_keys( bbp_get_caps_for_role( bbp_get_keymaster_role() ) );
|
71 |
} else {
|
72 |
$caps = array();
|
73 |
}
|
99 |
public function extract_bbp_roles($roles) {
|
100 |
|
101 |
$user_bbp_roles = array();
|
102 |
+
if ( $this->bbpress_detected ) {
|
103 |
+
$all_bbp_roles = array_keys( bbp_get_dynamic_roles() );
|
104 |
+
foreach( $roles as $role ) {
|
105 |
+
if ( in_array( $role, $all_bbp_roles ) ) {
|
106 |
$user_bbp_roles[] = $role;
|
107 |
}
|
108 |
}
|
includes/classes/capabilities-groups-manager.php
CHANGED
@@ -41,21 +41,25 @@ class URE_Capabilities_Groups_Manager {
|
|
41 |
|
42 |
public function add_custom_post_types() {
|
43 |
|
44 |
-
$this->groups['custom_post_types'] = array(
|
|
|
|
|
|
|
|
|
45 |
|
46 |
-
$post_types = get_post_types(array(), 'objects');
|
47 |
$_post_types = $this->lib->_get_post_types();
|
48 |
$built_in_pt = array('post', 'page');
|
49 |
-
if ($post_types['attachment']->cap->edit_posts=='edit_posts') {
|
50 |
$built_in_pt[] = 'attachment';
|
51 |
}
|
52 |
|
53 |
$show_wc_post_types_under_wc_only = apply_filters('ure_show_wc_post_types_under_wc_only', false);
|
54 |
-
foreach($post_types as $post_type) {
|
55 |
-
if (!isset($_post_types[$post_type->name]) || in_array($post_type->name, $built_in_pt)) {
|
56 |
continue;
|
57 |
}
|
58 |
-
if ($show_wc_post_types_under_wc_only && in_array($post_type->name, URE_Woocommerce_Capabilities::$post_types)) {
|
59 |
continue;
|
60 |
}
|
61 |
/*
|
@@ -64,7 +68,11 @@ class URE_Capabilities_Groups_Manager {
|
|
64 |
}
|
65 |
*
|
66 |
*/
|
67 |
-
$this->groups[$post_type->name] = array(
|
|
|
|
|
|
|
|
|
68 |
}
|
69 |
}
|
70 |
// end of add_custom_post_types()
|
@@ -72,7 +80,11 @@ class URE_Capabilities_Groups_Manager {
|
|
72 |
|
73 |
private function add_ure_group() {
|
74 |
|
75 |
-
$this->groups['user_role_editor'] = array(
|
|
|
|
|
|
|
|
|
76 |
|
77 |
}
|
78 |
// end of get_ure_group()
|
@@ -85,45 +97,111 @@ class URE_Capabilities_Groups_Manager {
|
|
85 |
return;
|
86 |
}
|
87 |
|
88 |
-
$post_types = get_post_types(array(), 'objects');
|
89 |
-
|
90 |
-
$this->groups['woocommerce'] = array(
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
continue;
|
95 |
}
|
96 |
-
$this->groups['woocommerce_'. $post_type] = array(
|
|
|
|
|
|
|
|
|
97 |
}
|
98 |
|
99 |
}
|
100 |
// end of add_woocommerce_group()
|
101 |
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
public function get_groups_tree() {
|
104 |
|
105 |
if ($this->groups!==null) {
|
106 |
return $this->groups;
|
107 |
}
|
108 |
|
109 |
-
$this->groups =
|
110 |
-
|
111 |
-
'core'=>array('caption'=>esc_html__('Core', 'user-role-editor'), 'parent'=>'all', 'level'=>1),
|
112 |
-
'general'=>array('caption'=>esc_html__('General', 'user-role-editor'), 'parent'=>'core', 'level'=>2),
|
113 |
-
'themes'=>array('caption'=>esc_html__('Themes', 'user-role-editor'), 'parent'=>'core', 'level'=>2),
|
114 |
-
'posts'=>array('caption'=>esc_html__('Posts', 'user-role-editor'), 'parent'=>'core', 'level'=>2),
|
115 |
-
'pages'=>array('caption'=>esc_html__('Pages', 'user-role-editor'), 'parent'=>'core', 'level'=>2),
|
116 |
-
'plugins'=>array('caption'=>esc_html__('Plugins', 'user-role-editor'), 'parent'=>'core', 'level'=>2),
|
117 |
-
'users'=>array('caption'=>esc_html__('Users', 'user-role-editor'), 'parent'=>'core', 'level'=>2)
|
118 |
-
);
|
119 |
$multisite = $this->lib->get('multisite');
|
120 |
-
if ($multisite) {
|
121 |
-
$this->groups['multisite'] = array(
|
|
|
|
|
|
|
|
|
122 |
}
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
$this->add_custom_post_types();
|
126 |
-
$this->groups['custom'] = array(
|
|
|
|
|
|
|
|
|
127 |
$this->add_ure_group();
|
128 |
$this->add_woocommerce_groups();
|
129 |
|
@@ -158,7 +236,7 @@ class URE_Capabilities_Groups_Manager {
|
|
158 |
$caps['upload_files'] = array('core', 'general');
|
159 |
$caps['import'] = array('core', 'general');
|
160 |
$caps['unfiltered_html'] = array('core','general');
|
161 |
-
if ($multisite) {
|
162 |
$caps['unfiltered_html'] = array('deprecated');
|
163 |
}
|
164 |
$caps['edit_posts'] = array('core', 'posts');
|
@@ -204,7 +282,7 @@ class URE_Capabilities_Groups_Manager {
|
|
204 |
$caps['list_users'] = array('core', 'users');
|
205 |
$caps['remove_users'] = array('core', 'users');
|
206 |
|
207 |
-
if (version_compare($wp_version, '4.4', '<')) {
|
208 |
$caps['add_users'] = array('core', 'users'); // removed from WP v. 4.4.
|
209 |
}
|
210 |
|
@@ -214,7 +292,7 @@ class URE_Capabilities_Groups_Manager {
|
|
214 |
$caps['export'] = array('core', 'general');
|
215 |
$caps['delete_users'] = array('core', 'users');
|
216 |
$caps['create_users'] = array('core', 'users');
|
217 |
-
if ($multisite) {
|
218 |
$caps['create_sites'] = array('core', 'multisite', 'general');
|
219 |
$caps['delete_sites'] = array('core', 'multisite', 'general');
|
220 |
$caps['manage_network'] = array('core', 'multisite', 'general');
|
@@ -232,7 +310,7 @@ class URE_Capabilities_Groups_Manager {
|
|
232 |
$caps['view_site_health_checks'] = array('core', 'general');
|
233 |
|
234 |
|
235 |
-
$caps = apply_filters('ure_built_in_wp_caps', $caps);
|
236 |
|
237 |
$this->built_in_wp_caps = $caps;
|
238 |
|
@@ -249,10 +327,11 @@ class URE_Capabilities_Groups_Manager {
|
|
249 |
|
250 |
|
251 |
private function get_post_types_without_caps() {
|
|
|
252 |
$pt_without_caps = array();
|
253 |
$wc_pts = URE_Woocommerce_Capabilities::get_post_types_without_caps();
|
254 |
|
255 |
-
$pt_without_caps = array_merge($pt_without_caps, $wc_pts);
|
256 |
|
257 |
return $pt_without_caps;
|
258 |
}
|
@@ -265,10 +344,10 @@ class URE_Capabilities_Groups_Manager {
|
|
265 |
* @param object $post_type
|
266 |
* @param array $post_edit_caps
|
267 |
*/
|
268 |
-
private function get_registered_cpt_caps($post_type, $post_edit_caps) {
|
269 |
|
270 |
-
foreach ($post_edit_caps as $capability) {
|
271 |
-
if (isset($post_type->cap->$capability)) {
|
272 |
$cap = $post_type->cap->$capability;
|
273 |
} else {
|
274 |
continue;
|
@@ -292,11 +371,11 @@ class URE_Capabilities_Groups_Manager {
|
|
292 |
// end of get_registered_cpt_caps()
|
293 |
|
294 |
|
295 |
-
private function add_group_to_edit_post_cap($post_type, $post_edit_caps) {
|
296 |
|
297 |
-
foreach($post_edit_caps as $cap_id) {
|
298 |
$this->built_in_wp_caps[$cap_id][] = $post_type->name;
|
299 |
-
if (!in_array('custom_post_types', $this->built_in_wp_caps[$cap_id])) {
|
300 |
$this->built_in_wp_caps[$cap_id][] = 'custom_post_types';
|
301 |
}
|
302 |
}
|
@@ -305,19 +384,20 @@ class URE_Capabilities_Groups_Manager {
|
|
305 |
// end of add_group_to_edit_post_cap()
|
306 |
|
307 |
|
308 |
-
private function get_custom_post_type_caps($post_type, $post_edit_caps) {
|
|
|
309 |
$pt_without_caps = $this->get_post_types_without_caps();
|
310 |
-
if (in_array($post_type->name, $pt_without_caps)) {
|
311 |
return;
|
312 |
}
|
313 |
|
314 |
// take into account custom post types, which uses built-in post or page capabilities
|
315 |
-
if (in_array($post_type->capability_type, array('post', 'page'))) {
|
316 |
-
$this->add_group_to_edit_post_cap($post_type, $post_edit_caps);
|
317 |
return;
|
318 |
}
|
319 |
|
320 |
-
$this->get_registered_cpt_caps($post_type, $post_edit_caps);
|
321 |
}
|
322 |
// end of get_custom_post_type_caps()
|
323 |
|
@@ -325,24 +405,24 @@ class URE_Capabilities_Groups_Manager {
|
|
325 |
private function _get_all_custom_post_types_caps() {
|
326 |
|
327 |
$post_edit_caps = $this->lib->get_edit_post_capabilities();
|
328 |
-
$post_types = get_post_types(array(), 'objects');
|
329 |
$_post_types = $this->lib->_get_post_types();
|
330 |
$built_in_pt = array('post', 'page');
|
331 |
-
if ($post_types['attachment']->cap->edit_posts=='edit_posts') {
|
332 |
$built_in_pt[] = 'attachment';
|
333 |
}
|
334 |
$this->cpt_caps = array();
|
335 |
-
foreach($post_types as $post_type) {
|
336 |
-
if (!isset($_post_types[$post_type->name])) {
|
337 |
continue;
|
338 |
}
|
339 |
-
if (in_array($post_type->name, $built_in_pt)) {
|
340 |
continue;
|
341 |
}
|
342 |
-
if (!isset($post_type->cap)) {
|
343 |
continue;
|
344 |
}
|
345 |
-
$this->get_custom_post_type_caps($post_type, $post_edit_caps);
|
346 |
}
|
347 |
|
348 |
return $this->cpt_caps;
|
@@ -350,30 +430,30 @@ class URE_Capabilities_Groups_Manager {
|
|
350 |
// end of _get_all_custom_post_types_capabilities()
|
351 |
|
352 |
|
353 |
-
private function get_groups_for_custom_cap($cap_id) {
|
354 |
|
355 |
$ure_caps = URE_Own_Capabilities::get_caps_groups();
|
356 |
-
if (isset($ure_caps[$cap_id])) {
|
357 |
$groups1 = $ure_caps[$cap_id];
|
358 |
}
|
359 |
|
360 |
-
if (empty($groups1)) {
|
361 |
$wc_caps = URE_Woocommerce_Capabilities::get_caps_groups();
|
362 |
-
if (isset($wc_caps[$cap_id])) {
|
363 |
$groups1 = $wc_caps[$cap_id];
|
364 |
}
|
365 |
}
|
366 |
|
367 |
-
if (isset($this->cpt_caps[$cap_id])) {
|
368 |
$groups2 = $this->cpt_caps[$cap_id];
|
369 |
}
|
370 |
|
371 |
$groups = array('custom');
|
372 |
-
if (!empty($groups1)) {
|
373 |
-
$groups = array_merge($groups, $groups1);
|
374 |
}
|
375 |
-
if (!empty($groups2)) {
|
376 |
-
$groups = array_merge($groups, $groups2);
|
377 |
}
|
378 |
|
379 |
return $groups;
|
@@ -381,18 +461,18 @@ class URE_Capabilities_Groups_Manager {
|
|
381 |
// end of get_groups_for_custom_cap()
|
382 |
|
383 |
|
384 |
-
public function get_cap_groups($cap_id, $built_in_wp_caps=null) {
|
385 |
|
386 |
-
if (isset($this->built_in_wp_caps[$cap_id])) {
|
387 |
$groups = $built_in_wp_caps[$cap_id];
|
388 |
} else {
|
389 |
-
$groups = $this->get_groups_for_custom_cap($cap_id);
|
390 |
}
|
391 |
-
$groups = apply_filters('ure_custom_capability_groups', $groups, $cap_id);
|
392 |
$groups[] = 'all'; // Every capability belongs to the 'all' group
|
393 |
-
$groups = array_unique($groups);
|
394 |
|
395 |
-
foreach($groups as $key=>$value) {
|
396 |
$groups[$key] = 'ure-'. $value;
|
397 |
}
|
398 |
|
41 |
|
42 |
public function add_custom_post_types() {
|
43 |
|
44 |
+
$this->groups['custom_post_types'] = array(
|
45 |
+
'caption'=>esc_html__('Custom Post Types', 'user-role-editor'),
|
46 |
+
'parent'=>'all',
|
47 |
+
'level'=>1
|
48 |
+
);
|
49 |
|
50 |
+
$post_types = get_post_types( array(), 'objects');
|
51 |
$_post_types = $this->lib->_get_post_types();
|
52 |
$built_in_pt = array('post', 'page');
|
53 |
+
if ( $post_types['attachment']->cap->edit_posts=='edit_posts') {
|
54 |
$built_in_pt[] = 'attachment';
|
55 |
}
|
56 |
|
57 |
$show_wc_post_types_under_wc_only = apply_filters('ure_show_wc_post_types_under_wc_only', false);
|
58 |
+
foreach( $post_types as $post_type ) {
|
59 |
+
if ( !isset( $_post_types[$post_type->name] ) || in_array( $post_type->name, $built_in_pt ) ) {
|
60 |
continue;
|
61 |
}
|
62 |
+
if ( $show_wc_post_types_under_wc_only && in_array( $post_type->name, URE_Woocommerce_Capabilities::$post_types ) ) {
|
63 |
continue;
|
64 |
}
|
65 |
/*
|
68 |
}
|
69 |
*
|
70 |
*/
|
71 |
+
$this->groups[$post_type->name] = array(
|
72 |
+
'caption'=>$post_type->labels->name,
|
73 |
+
'parent'=>'custom_post_types',
|
74 |
+
'level'=>2
|
75 |
+
);
|
76 |
}
|
77 |
}
|
78 |
// end of add_custom_post_types()
|
80 |
|
81 |
private function add_ure_group() {
|
82 |
|
83 |
+
$this->groups['user_role_editor'] = array(
|
84 |
+
'caption'=>esc_html__('User Role Editor', 'user-role-editor'),
|
85 |
+
'parent'=>'custom',
|
86 |
+
'level'=>2
|
87 |
+
);
|
88 |
|
89 |
}
|
90 |
// end of get_ure_group()
|
97 |
return;
|
98 |
}
|
99 |
|
100 |
+
$post_types = get_post_types( array(), 'objects');
|
101 |
+
|
102 |
+
$this->groups['woocommerce'] = array(
|
103 |
+
'caption'=>esc_html__('WooCommerce', 'user-role-editor'),
|
104 |
+
'parent'=>'custom',
|
105 |
+
'level'=>2
|
106 |
+
);
|
107 |
+
$this->groups['woocommerce_core'] = array(
|
108 |
+
'caption'=>esc_html__('Core', 'user-role-editor'),
|
109 |
+
'parent'=>'woocommerce',
|
110 |
+
'level'=>3
|
111 |
+
);
|
112 |
+
foreach( URE_Woocommerce_Capabilities::$post_types as $post_type ) {
|
113 |
+
if ( !isset( $post_types[$post_type] ) ) {
|
114 |
continue;
|
115 |
}
|
116 |
+
$this->groups['woocommerce_'. $post_type] = array(
|
117 |
+
'caption'=>$post_types[$post_type]->labels->name,
|
118 |
+
'parent'=>'woocommerce',
|
119 |
+
'level'=>3
|
120 |
+
);
|
121 |
}
|
122 |
|
123 |
}
|
124 |
// end of add_woocommerce_group()
|
125 |
|
126 |
|
127 |
+
private function get_base_wp_groups() {
|
128 |
+
$groups = array(
|
129 |
+
'all'=>array(
|
130 |
+
'caption'=>esc_html__('All', 'user-role-editor'),
|
131 |
+
'parent'=>null,
|
132 |
+
'level'=>0
|
133 |
+
),
|
134 |
+
'core'=>array(
|
135 |
+
'caption'=>esc_html__('Core', 'user-role-editor'),
|
136 |
+
'parent'=>'all',
|
137 |
+
'level'=>1
|
138 |
+
),
|
139 |
+
'general'=>array(
|
140 |
+
'caption'=>esc_html__('General', 'user-role-editor'),
|
141 |
+
'parent'=>'core',
|
142 |
+
'level'=>2
|
143 |
+
),
|
144 |
+
'themes'=>array(
|
145 |
+
'caption'=>esc_html__('Themes', 'user-role-editor'),
|
146 |
+
'parent'=>'core',
|
147 |
+
'level'=>2
|
148 |
+
),
|
149 |
+
'posts'=>array(
|
150 |
+
'caption'=>esc_html__('Posts', 'user-role-editor'),
|
151 |
+
'parent'=>'core',
|
152 |
+
'level'=>2
|
153 |
+
),
|
154 |
+
'pages'=>array(
|
155 |
+
'caption'=>esc_html__('Pages', 'user-role-editor'),
|
156 |
+
'parent'=>'core',
|
157 |
+
'level'=>2
|
158 |
+
),
|
159 |
+
'plugins'=>array(
|
160 |
+
'caption'=>esc_html__('Plugins', 'user-role-editor'),
|
161 |
+
'parent'=>'core',
|
162 |
+
'level'=>2
|
163 |
+
),
|
164 |
+
'users'=>array(
|
165 |
+
'caption'=>esc_html__('Users', 'user-role-editor'),
|
166 |
+
'parent'=>'core',
|
167 |
+
'level'=>2
|
168 |
+
)
|
169 |
+
);
|
170 |
+
|
171 |
+
return $groups;
|
172 |
+
}
|
173 |
+
// end of get_base_wp_groups
|
174 |
+
|
175 |
+
|
176 |
public function get_groups_tree() {
|
177 |
|
178 |
if ($this->groups!==null) {
|
179 |
return $this->groups;
|
180 |
}
|
181 |
|
182 |
+
$this->groups = $this->get_base_wp_groups();
|
183 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
$multisite = $this->lib->get('multisite');
|
185 |
+
if ( $multisite ) {
|
186 |
+
$this->groups['multisite'] = array(
|
187 |
+
'caption'=>esc_html__('Multisite', 'user-role-editor'),
|
188 |
+
'parent'=>'core',
|
189 |
+
'level'=>2
|
190 |
+
);
|
191 |
}
|
192 |
+
|
193 |
+
$this->groups['deprecated'] = array(
|
194 |
+
'caption'=>esc_html__('Deprecated', 'user-role-editor'),
|
195 |
+
'parent'=>'core',
|
196 |
+
'level'=>2
|
197 |
+
);
|
198 |
|
199 |
$this->add_custom_post_types();
|
200 |
+
$this->groups['custom'] = array(
|
201 |
+
'caption'=>esc_html__('Custom capabilities', 'user-role-editor'),
|
202 |
+
'parent'=>'all',
|
203 |
+
'level'=>1
|
204 |
+
);
|
205 |
$this->add_ure_group();
|
206 |
$this->add_woocommerce_groups();
|
207 |
|
236 |
$caps['upload_files'] = array('core', 'general');
|
237 |
$caps['import'] = array('core', 'general');
|
238 |
$caps['unfiltered_html'] = array('core','general');
|
239 |
+
if ( $multisite ) {
|
240 |
$caps['unfiltered_html'] = array('deprecated');
|
241 |
}
|
242 |
$caps['edit_posts'] = array('core', 'posts');
|
282 |
$caps['list_users'] = array('core', 'users');
|
283 |
$caps['remove_users'] = array('core', 'users');
|
284 |
|
285 |
+
if ( version_compare( $wp_version, '4.4', '<') ) {
|
286 |
$caps['add_users'] = array('core', 'users'); // removed from WP v. 4.4.
|
287 |
}
|
288 |
|
292 |
$caps['export'] = array('core', 'general');
|
293 |
$caps['delete_users'] = array('core', 'users');
|
294 |
$caps['create_users'] = array('core', 'users');
|
295 |
+
if ( $multisite ) {
|
296 |
$caps['create_sites'] = array('core', 'multisite', 'general');
|
297 |
$caps['delete_sites'] = array('core', 'multisite', 'general');
|
298 |
$caps['manage_network'] = array('core', 'multisite', 'general');
|
310 |
$caps['view_site_health_checks'] = array('core', 'general');
|
311 |
|
312 |
|
313 |
+
$caps = apply_filters('ure_built_in_wp_caps', $caps );
|
314 |
|
315 |
$this->built_in_wp_caps = $caps;
|
316 |
|
327 |
|
328 |
|
329 |
private function get_post_types_without_caps() {
|
330 |
+
|
331 |
$pt_without_caps = array();
|
332 |
$wc_pts = URE_Woocommerce_Capabilities::get_post_types_without_caps();
|
333 |
|
334 |
+
$pt_without_caps = array_merge( $pt_without_caps, $wc_pts );
|
335 |
|
336 |
return $pt_without_caps;
|
337 |
}
|
344 |
* @param object $post_type
|
345 |
* @param array $post_edit_caps
|
346 |
*/
|
347 |
+
private function get_registered_cpt_caps( $post_type, $post_edit_caps ) {
|
348 |
|
349 |
+
foreach ( $post_edit_caps as $capability ) {
|
350 |
+
if ( isset( $post_type->cap->$capability ) ) {
|
351 |
$cap = $post_type->cap->$capability;
|
352 |
} else {
|
353 |
continue;
|
371 |
// end of get_registered_cpt_caps()
|
372 |
|
373 |
|
374 |
+
private function add_group_to_edit_post_cap( $post_type, $post_edit_caps ) {
|
375 |
|
376 |
+
foreach( $post_edit_caps as $cap_id ) {
|
377 |
$this->built_in_wp_caps[$cap_id][] = $post_type->name;
|
378 |
+
if ( !in_array('custom_post_types', $this->built_in_wp_caps[$cap_id] ) ) {
|
379 |
$this->built_in_wp_caps[$cap_id][] = 'custom_post_types';
|
380 |
}
|
381 |
}
|
384 |
// end of add_group_to_edit_post_cap()
|
385 |
|
386 |
|
387 |
+
private function get_custom_post_type_caps( $post_type, $post_edit_caps ) {
|
388 |
+
|
389 |
$pt_without_caps = $this->get_post_types_without_caps();
|
390 |
+
if ( in_array($post_type->name, $pt_without_caps ) ) {
|
391 |
return;
|
392 |
}
|
393 |
|
394 |
// take into account custom post types, which uses built-in post or page capabilities
|
395 |
+
if ( in_array( $post_type->capability_type, array('post', 'page') ) ) {
|
396 |
+
$this->add_group_to_edit_post_cap( $post_type, $post_edit_caps );
|
397 |
return;
|
398 |
}
|
399 |
|
400 |
+
$this->get_registered_cpt_caps( $post_type, $post_edit_caps );
|
401 |
}
|
402 |
// end of get_custom_post_type_caps()
|
403 |
|
405 |
private function _get_all_custom_post_types_caps() {
|
406 |
|
407 |
$post_edit_caps = $this->lib->get_edit_post_capabilities();
|
408 |
+
$post_types = get_post_types( array(), 'objects' );
|
409 |
$_post_types = $this->lib->_get_post_types();
|
410 |
$built_in_pt = array('post', 'page');
|
411 |
+
if ( $post_types['attachment']->cap->edit_posts=='edit_posts') {
|
412 |
$built_in_pt[] = 'attachment';
|
413 |
}
|
414 |
$this->cpt_caps = array();
|
415 |
+
foreach( $post_types as $post_type ) {
|
416 |
+
if ( !isset( $_post_types[$post_type->name] ) ) {
|
417 |
continue;
|
418 |
}
|
419 |
+
if ( in_array( $post_type->name, $built_in_pt ) ) {
|
420 |
continue;
|
421 |
}
|
422 |
+
if ( !isset( $post_type->cap ) ) {
|
423 |
continue;
|
424 |
}
|
425 |
+
$this->get_custom_post_type_caps( $post_type, $post_edit_caps );
|
426 |
}
|
427 |
|
428 |
return $this->cpt_caps;
|
430 |
// end of _get_all_custom_post_types_capabilities()
|
431 |
|
432 |
|
433 |
+
private function get_groups_for_custom_cap( $cap_id ) {
|
434 |
|
435 |
$ure_caps = URE_Own_Capabilities::get_caps_groups();
|
436 |
+
if ( isset( $ure_caps[$cap_id] ) ) {
|
437 |
$groups1 = $ure_caps[$cap_id];
|
438 |
}
|
439 |
|
440 |
+
if ( empty( $groups1 ) ) {
|
441 |
$wc_caps = URE_Woocommerce_Capabilities::get_caps_groups();
|
442 |
+
if ( isset($wc_caps[$cap_id] ) ) {
|
443 |
$groups1 = $wc_caps[$cap_id];
|
444 |
}
|
445 |
}
|
446 |
|
447 |
+
if ( isset( $this->cpt_caps[$cap_id] ) ) {
|
448 |
$groups2 = $this->cpt_caps[$cap_id];
|
449 |
}
|
450 |
|
451 |
$groups = array('custom');
|
452 |
+
if ( !empty( $groups1 ) ) {
|
453 |
+
$groups = array_merge( $groups, $groups1 );
|
454 |
}
|
455 |
+
if ( !empty( $groups2 ) ) {
|
456 |
+
$groups = array_merge( $groups, $groups2 );
|
457 |
}
|
458 |
|
459 |
return $groups;
|
461 |
// end of get_groups_for_custom_cap()
|
462 |
|
463 |
|
464 |
+
public function get_cap_groups( $cap_id, $built_in_wp_caps=null ) {
|
465 |
|
466 |
+
if ( isset( $this->built_in_wp_caps[$cap_id] ) ) {
|
467 |
$groups = $built_in_wp_caps[$cap_id];
|
468 |
} else {
|
469 |
+
$groups = $this->get_groups_for_custom_cap( $cap_id );
|
470 |
}
|
471 |
+
$groups = apply_filters('ure_custom_capability_groups', $groups, $cap_id );
|
472 |
$groups[] = 'all'; // Every capability belongs to the 'all' group
|
473 |
+
$groups = array_unique( $groups );
|
474 |
|
475 |
+
foreach( $groups as $key=>$value ) {
|
476 |
$groups[$key] = 'ure-'. $value;
|
477 |
}
|
478 |
|
includes/classes/capabilities.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* @package User-Role-Editor
|
6 |
* @subpackage Admin
|
7 |
* @author Vladimir Garagulia <support@role-editor.com>
|
8 |
-
* @copyright Copyright (c) 2010 -
|
9 |
**/
|
10 |
class URE_Capabilities {
|
11 |
|
@@ -16,7 +16,7 @@ class URE_Capabilities {
|
|
16 |
|
17 |
public static function get_instance() {
|
18 |
|
19 |
-
if (self::$instance === null) {
|
20 |
// new static() will work too
|
21 |
self::$instance = new URE_Capabilities();
|
22 |
}
|
@@ -46,7 +46,8 @@ class URE_Capabilities {
|
|
46 |
|
47 |
|
48 |
protected function add_capability_to_full_caps_list( $cap_id, &$full_list ) {
|
49 |
-
|
|
|
50 |
return;
|
51 |
}
|
52 |
|
@@ -71,9 +72,9 @@ class URE_Capabilities {
|
|
71 |
protected function add_roles_caps( &$full_list ) {
|
72 |
|
73 |
$roles = $this->lib->get_user_roles();
|
74 |
-
foreach ($roles as $role) {
|
75 |
// validate if capabilities is an array
|
76 |
-
if (!isset($role['capabilities']) || !is_array($role['capabilities'])) {
|
77 |
continue;
|
78 |
}
|
79 |
foreach ( array_keys( $role['capabilities'] ) as $cap ) {
|
@@ -110,7 +111,7 @@ class URE_Capabilities {
|
|
110 |
protected function add_bbpress_caps( &$full_list ) {
|
111 |
|
112 |
$bbpress = $this->lib->get_bbpress();
|
113 |
-
if (!$bbpress->is_active()) {
|
114 |
return;
|
115 |
}
|
116 |
|
@@ -160,7 +161,7 @@ class URE_Capabilities {
|
|
160 |
|
161 |
|
162 |
/**
|
163 |
-
* Add built-in WordPress caps in case some were not included to the roles for some reason
|
164 |
*
|
165 |
*/
|
166 |
protected function add_wordpress_caps( &$full_list ) {
|
@@ -345,7 +346,7 @@ class URE_Capabilities {
|
|
345 |
$this->add_custom_taxonomies_caps( $full_list );
|
346 |
$this->add_ure_caps( $full_list );
|
347 |
asort( $full_list );
|
348 |
-
$full_list = apply_filters('ure_full_capabilites', $full_list);
|
349 |
$this->grant_all_caps_to_admin( $full_list );
|
350 |
|
351 |
return $full_list;
|
@@ -363,7 +364,7 @@ class URE_Capabilities {
|
|
363 |
foreach ( $wp_roles->roles as $role ) {
|
364 |
// validate if capabilities is an array
|
365 |
if ( isset( $role['capabilities'] ) && is_array( $role['capabilities'] ) ) {
|
366 |
-
foreach ($role['capabilities'] as $capability => $value) {
|
367 |
if ( !isset( $full_caps_list[$capability] ) ) {
|
368 |
$full_caps_list[$capability] = true;
|
369 |
}
|
@@ -382,8 +383,8 @@ class URE_Capabilities {
|
|
382 |
*/
|
383 |
protected function get_visual_composer_caps($full_caps_list) {
|
384 |
$caps = array();
|
385 |
-
foreach(array_keys($full_caps_list) as $cap) {
|
386 |
-
if (strpos($cap, 'vc_access_rules_')!==false) {
|
387 |
$caps[$cap] = 1;
|
388 |
}
|
389 |
}
|
5 |
* @package User-Role-Editor
|
6 |
* @subpackage Admin
|
7 |
* @author Vladimir Garagulia <support@role-editor.com>
|
8 |
+
* @copyright Copyright (c) 2010 - 2021, Vladimir Garagulia
|
9 |
**/
|
10 |
class URE_Capabilities {
|
11 |
|
16 |
|
17 |
public static function get_instance() {
|
18 |
|
19 |
+
if ( self::$instance === null ) {
|
20 |
// new static() will work too
|
21 |
self::$instance = new URE_Capabilities();
|
22 |
}
|
46 |
|
47 |
|
48 |
protected function add_capability_to_full_caps_list( $cap_id, &$full_list ) {
|
49 |
+
|
50 |
+
if ( isset( $full_list[$cap_id] ) ) { // if capability was added already
|
51 |
return;
|
52 |
}
|
53 |
|
72 |
protected function add_roles_caps( &$full_list ) {
|
73 |
|
74 |
$roles = $this->lib->get_user_roles();
|
75 |
+
foreach ( $roles as $role ) {
|
76 |
// validate if capabilities is an array
|
77 |
+
if ( !isset( $role['capabilities'] ) || !is_array( $role['capabilities'] ) ) {
|
78 |
continue;
|
79 |
}
|
80 |
foreach ( array_keys( $role['capabilities'] ) as $cap ) {
|
111 |
protected function add_bbpress_caps( &$full_list ) {
|
112 |
|
113 |
$bbpress = $this->lib->get_bbpress();
|
114 |
+
if ( !$bbpress->is_active() ) {
|
115 |
return;
|
116 |
}
|
117 |
|
161 |
|
162 |
|
163 |
/**
|
164 |
+
* Add built-in WordPress caps in case some of them were not included to the roles for some reason
|
165 |
*
|
166 |
*/
|
167 |
protected function add_wordpress_caps( &$full_list ) {
|
346 |
$this->add_custom_taxonomies_caps( $full_list );
|
347 |
$this->add_ure_caps( $full_list );
|
348 |
asort( $full_list );
|
349 |
+
$full_list = apply_filters('ure_full_capabilites', $full_list );
|
350 |
$this->grant_all_caps_to_admin( $full_list );
|
351 |
|
352 |
return $full_list;
|
364 |
foreach ( $wp_roles->roles as $role ) {
|
365 |
// validate if capabilities is an array
|
366 |
if ( isset( $role['capabilities'] ) && is_array( $role['capabilities'] ) ) {
|
367 |
+
foreach ( $role['capabilities'] as $capability => $value ) {
|
368 |
if ( !isset( $full_caps_list[$capability] ) ) {
|
369 |
$full_caps_list[$capability] = true;
|
370 |
}
|
383 |
*/
|
384 |
protected function get_visual_composer_caps($full_caps_list) {
|
385 |
$caps = array();
|
386 |
+
foreach( array_keys( $full_caps_list ) as $cap ) {
|
387 |
+
if ( strpos( $cap, 'vc_access_rules_')!==false ) {
|
388 |
$caps[$cap] = 1;
|
389 |
}
|
390 |
}
|
includes/classes/capability.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* @package User-Role-Editor
|
6 |
* @subpackage Admin
|
7 |
* @author Vladimir Garagulya <support@role-editor.com>
|
8 |
-
* @copyright Copyright (c) 2010 -
|
9 |
**/
|
10 |
|
11 |
class URE_Capability {
|
@@ -15,51 +15,55 @@ class URE_Capability {
|
|
15 |
const VERT_LINE_REPLACER = '_URE-VLR_';
|
16 |
|
17 |
|
18 |
-
public static function escape($cap_id) {
|
19 |
|
20 |
$search = array(' ', '/', '|');
|
21 |
$replace = array(self::SPACE_REPLACER, self::SLASH_REPLACER, self::VERT_LINE_REPLACER);
|
22 |
|
23 |
-
$cap_id_esc = str_replace($search, $replace, $cap_id);
|
24 |
|
25 |
return $cap_id_esc;
|
26 |
}
|
27 |
// end escape()
|
28 |
|
29 |
|
30 |
-
//
|
31 |
// do not allow to use internally used capabilities
|
32 |
-
public static function validate($cap_id_raw) {
|
33 |
$match = array();
|
34 |
-
$found = preg_match('/[A-Za-z0-9_\-]*/', $cap_id_raw, $match);
|
35 |
-
if (!$found || ($found && ($match[0]!=$cap_id_raw))) { // some non-alphanumeric charactes found!
|
36 |
$data = array(
|
37 |
'result'=>false,
|
38 |
'message'=>esc_html__('Error: Capability name must contain latin characters and digits only!', 'user-role-editor'),
|
39 |
-
'cap_id'=>''
|
|
|
40 |
return $data;
|
41 |
}
|
42 |
|
43 |
-
$cap_id = strtolower($match[0]);
|
44 |
-
if ($cap_id=='do_not_allow') {
|
45 |
$data = array(
|
46 |
'result'=>false,
|
47 |
'message'=>esc_html__('Error: this capability is used internally by WordPress', 'user-role-editor'),
|
48 |
-
'cap_id'=>'do_not_allow'
|
|
|
49 |
return $data;
|
50 |
}
|
51 |
-
if ($cap_id=='administrator') {
|
52 |
$data = array(
|
53 |
'result'=>false,
|
54 |
'message'=>esc_html__('Error: this word is used by WordPress as a role ID', 'user-role-editor'),
|
55 |
-
'cap_id'=>'administrator'
|
|
|
56 |
return $data;
|
57 |
}
|
58 |
|
59 |
$data = array(
|
60 |
'result'=>true,
|
61 |
'message'=>'Success',
|
62 |
-
'cap_id'=>$cap_id
|
|
|
63 |
|
64 |
return $data;
|
65 |
}
|
@@ -75,7 +79,12 @@ class URE_Capability {
|
|
75 |
public static function add( $ure_object ) {
|
76 |
global $wp_roles;
|
77 |
|
78 |
-
$response = array(
|
|
|
|
|
|
|
|
|
|
|
79 |
if ( !current_user_can( 'ure_create_capabilities' ) ) {
|
80 |
$response['message'] = esc_html__( 'Insufficient permissions to work with User Role Editor', 'user-role-editor' );
|
81 |
return $response;
|
@@ -98,8 +107,10 @@ class URE_Capability {
|
|
98 |
$full_capabilities = $lib->init_full_capabilities( $ure_object );
|
99 |
if ( !isset( $full_capabilities[$cap_id] ) ) {
|
100 |
$admin_role = $lib->get_admin_role();
|
|
|
101 |
$wp_roles->use_db = true;
|
102 |
$wp_roles->add_cap( $admin_role, $cap_id );
|
|
|
103 |
$response['result'] = 'success';
|
104 |
$response['message'] = sprintf( esc_html__( 'Capability %s was added successfully', 'user-role-editor' ), $cap_id );
|
105 |
} else {
|
@@ -112,7 +123,7 @@ class URE_Capability {
|
|
112 |
|
113 |
|
114 |
/**
|
115 |
-
* Extract capabilities selected
|
116 |
*
|
117 |
* @return array
|
118 |
*/
|
@@ -140,44 +151,47 @@ class URE_Capability {
|
|
140 |
// end of get_caps_for_deletion_from_post()
|
141 |
|
142 |
|
143 |
-
private static function revoke_caps_from_user($user_id, $caps) {
|
144 |
-
|
145 |
-
|
146 |
-
|
|
|
147 |
continue;
|
148 |
}
|
149 |
// Prevent sudden revoke role 'administrator' from a user during 'administrator' capability deletion.
|
150 |
-
if ($cap_id=='administrator') {
|
151 |
continue;
|
152 |
}
|
153 |
-
$user->remove_cap($cap_id);
|
154 |
}
|
155 |
}
|
156 |
// end of revoke_caps_from_user()
|
157 |
|
158 |
|
159 |
-
private static function revoke_caps_from_role($wp_role, $caps) {
|
160 |
-
|
161 |
-
|
162 |
-
|
|
|
163 |
}
|
164 |
}
|
|
|
165 |
}
|
166 |
// end of revoke_caps_from_role()
|
167 |
|
168 |
|
169 |
-
private static function revoke_caps($caps) {
|
170 |
global $wpdb, $wp_roles;
|
171 |
|
172 |
// remove caps from users
|
173 |
$users_ids = $wpdb->get_col("SELECT $wpdb->users.ID FROM $wpdb->users");
|
174 |
-
foreach ($users_ids as $user_id) {
|
175 |
-
self::revoke_caps_from_user($user_id, $caps);
|
176 |
}
|
177 |
|
178 |
// remove caps from roles
|
179 |
-
foreach ($wp_roles->role_objects as $wp_role) {
|
180 |
-
self::revoke_caps_from_role($wp_role, $caps);
|
181 |
}
|
182 |
}
|
183 |
// end of revoke_caps()
|
@@ -203,13 +217,13 @@ class URE_Capability {
|
|
203 |
}
|
204 |
|
205 |
$caps = self::get_caps_for_deletion_from_post( $caps_allowed_to_remove );
|
206 |
-
if ( empty($caps) ) {
|
207 |
return esc_html__( 'There are no capabilities available for deletion!', 'user-role-editor' );
|
208 |
}
|
209 |
|
210 |
self::revoke_caps( $caps );
|
211 |
|
212 |
-
if ( count($caps)==1 ) {
|
213 |
$mess = sprintf( esc_html__( 'Capability %s was removed successfully', 'user-role-editor' ), $caps[0] );
|
214 |
} else {
|
215 |
$lib = URE_Lib::get_instance();
|
5 |
* @package User-Role-Editor
|
6 |
* @subpackage Admin
|
7 |
* @author Vladimir Garagulya <support@role-editor.com>
|
8 |
+
* @copyright Copyright (c) 2010 - 2021, Vladimir Garagulya
|
9 |
**/
|
10 |
|
11 |
class URE_Capability {
|
15 |
const VERT_LINE_REPLACER = '_URE-VLR_';
|
16 |
|
17 |
|
18 |
+
public static function escape( $cap_id ) {
|
19 |
|
20 |
$search = array(' ', '/', '|');
|
21 |
$replace = array(self::SPACE_REPLACER, self::SLASH_REPLACER, self::VERT_LINE_REPLACER);
|
22 |
|
23 |
+
$cap_id_esc = str_replace( $search, $replace, $cap_id );
|
24 |
|
25 |
return $cap_id_esc;
|
26 |
}
|
27 |
// end escape()
|
28 |
|
29 |
|
30 |
+
// Sanitize user input for security
|
31 |
// do not allow to use internally used capabilities
|
32 |
+
public static function validate( $cap_id_raw ) {
|
33 |
$match = array();
|
34 |
+
$found = preg_match('/[A-Za-z0-9_\-]*/', $cap_id_raw, $match );
|
35 |
+
if ( !$found || ($found && ( $match[0]!=$cap_id_raw ) ) ) { // some non-alphanumeric charactes found!
|
36 |
$data = array(
|
37 |
'result'=>false,
|
38 |
'message'=>esc_html__('Error: Capability name must contain latin characters and digits only!', 'user-role-editor'),
|
39 |
+
'cap_id'=>''
|
40 |
+
);
|
41 |
return $data;
|
42 |
}
|
43 |
|
44 |
+
$cap_id = strtolower( $match[0] );
|
45 |
+
if ( $cap_id=='do_not_allow' ) {
|
46 |
$data = array(
|
47 |
'result'=>false,
|
48 |
'message'=>esc_html__('Error: this capability is used internally by WordPress', 'user-role-editor'),
|
49 |
+
'cap_id'=>'do_not_allow'
|
50 |
+
);
|
51 |
return $data;
|
52 |
}
|
53 |
+
if ( $cap_id=='administrator' ) {
|
54 |
$data = array(
|
55 |
'result'=>false,
|
56 |
'message'=>esc_html__('Error: this word is used by WordPress as a role ID', 'user-role-editor'),
|
57 |
+
'cap_id'=>'administrator'
|
58 |
+
);
|
59 |
return $data;
|
60 |
}
|
61 |
|
62 |
$data = array(
|
63 |
'result'=>true,
|
64 |
'message'=>'Success',
|
65 |
+
'cap_id'=>$cap_id
|
66 |
+
);
|
67 |
|
68 |
return $data;
|
69 |
}
|
79 |
public static function add( $ure_object ) {
|
80 |
global $wp_roles;
|
81 |
|
82 |
+
$response = array(
|
83 |
+
'result'=>'error',
|
84 |
+
'capability_id'=>'',
|
85 |
+
'html'=>'',
|
86 |
+
'message'=>''
|
87 |
+
);
|
88 |
if ( !current_user_can( 'ure_create_capabilities' ) ) {
|
89 |
$response['message'] = esc_html__( 'Insufficient permissions to work with User Role Editor', 'user-role-editor' );
|
90 |
return $response;
|
107 |
$full_capabilities = $lib->init_full_capabilities( $ure_object );
|
108 |
if ( !isset( $full_capabilities[$cap_id] ) ) {
|
109 |
$admin_role = $lib->get_admin_role();
|
110 |
+
$use_db = $wp_roles->use_db;
|
111 |
$wp_roles->use_db = true;
|
112 |
$wp_roles->add_cap( $admin_role, $cap_id );
|
113 |
+
$wp_roles->use_db = $use_db;
|
114 |
$response['result'] = 'success';
|
115 |
$response['message'] = sprintf( esc_html__( 'Capability %s was added successfully', 'user-role-editor' ), $cap_id );
|
116 |
} else {
|
123 |
|
124 |
|
125 |
/**
|
126 |
+
* Extract capabilities selected for deletion from the $_POST global
|
127 |
*
|
128 |
* @return array
|
129 |
*/
|
151 |
// end of get_caps_for_deletion_from_post()
|
152 |
|
153 |
|
154 |
+
private static function revoke_caps_from_user( $user_id, $caps ) {
|
155 |
+
|
156 |
+
$user = get_user_to_edit( $user_id );
|
157 |
+
foreach( $caps as $cap_id ) {
|
158 |
+
if ( !isset( $user->caps[$cap_id] ) ) {
|
159 |
continue;
|
160 |
}
|
161 |
// Prevent sudden revoke role 'administrator' from a user during 'administrator' capability deletion.
|
162 |
+
if ( $cap_id=='administrator') {
|
163 |
continue;
|
164 |
}
|
165 |
+
$user->remove_cap( $cap_id );
|
166 |
}
|
167 |
}
|
168 |
// end of revoke_caps_from_user()
|
169 |
|
170 |
|
171 |
+
private static function revoke_caps_from_role( $wp_role, $caps ) {
|
172 |
+
|
173 |
+
foreach( $caps as $cap_id ) {
|
174 |
+
if ( $wp_role->has_cap( $cap_id ) ) {
|
175 |
+
$wp_role->remove_cap( $cap_id );
|
176 |
}
|
177 |
}
|
178 |
+
|
179 |
}
|
180 |
// end of revoke_caps_from_role()
|
181 |
|
182 |
|
183 |
+
private static function revoke_caps( $caps ) {
|
184 |
global $wpdb, $wp_roles;
|
185 |
|
186 |
// remove caps from users
|
187 |
$users_ids = $wpdb->get_col("SELECT $wpdb->users.ID FROM $wpdb->users");
|
188 |
+
foreach ( $users_ids as $user_id ) {
|
189 |
+
self::revoke_caps_from_user( $user_id, $caps );
|
190 |
}
|
191 |
|
192 |
// remove caps from roles
|
193 |
+
foreach ( $wp_roles->role_objects as $wp_role ) {
|
194 |
+
self::revoke_caps_from_role( $wp_role, $caps );
|
195 |
}
|
196 |
}
|
197 |
// end of revoke_caps()
|
217 |
}
|
218 |
|
219 |
$caps = self::get_caps_for_deletion_from_post( $caps_allowed_to_remove );
|
220 |
+
if ( empty( $caps ) ) {
|
221 |
return esc_html__( 'There are no capabilities available for deletion!', 'user-role-editor' );
|
222 |
}
|
223 |
|
224 |
self::revoke_caps( $caps );
|
225 |
|
226 |
+
if ( count( $caps )==1 ) {
|
227 |
$mess = sprintf( esc_html__( 'Capability %s was removed successfully', 'user-role-editor' ), $caps[0] );
|
228 |
} else {
|
229 |
$lib = URE_Lib::get_instance();
|
includes/classes/editor.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* @package User-Role-Editor
|
6 |
* @subpackage Editor
|
7 |
* @author Vladimir Garagulya <support@role-editor.com>
|
8 |
-
* @copyright Copyright (c) 2010 -
|
9 |
**/
|
10 |
class URE_Editor {
|
11 |
|
5 |
* @package User-Role-Editor
|
6 |
* @subpackage Editor
|
7 |
* @author Vladimir Garagulya <support@role-editor.com>
|
8 |
+
* @copyright Copyright (c) 2010 - 2021, Vladimir Garagulia
|
9 |
**/
|
10 |
class URE_Editor {
|
11 |
|
includes/classes/tools.php
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
<?php
|
2 |
|
3 |
class URE_Tools {
|
4 |
-
|
|
|
5 |
|
6 |
private static function show_reset_roles( $tab_idx ) {
|
7 |
|
@@ -18,22 +19,25 @@ class URE_Tools {
|
|
18 |
<h3>Reset User Roles</h3>
|
19 |
<span style="color: red;"><?php esc_html_e('WARNING!', 'user-role-editor');?></span>
|
20 |
<?php
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
|
27 |
?>
|
28 |
<br><br>
|
29 |
<input type="checkbox" name="ure_apply_to_all" id="ure_apply_to_all" value="1" />
|
30 |
<label for="ure_apply_to_all"><?php esc_html_e('Apply to All Sites', 'user-role-editor'); ?></label>
|
31 |
(<?php esc_html_e('If checked, then apply action to ALL sites. Main site only is affected in other case.', 'user-role-editor'); ?>)
|
32 |
<?php
|
33 |
-
|
34 |
?>
|
|
|
|
|
|
|
35 |
<br><br>
|
36 |
-
<button id="ure_reset_roles_button" style="width: 100px; color: red;" title="<?php esc_html_e('Reset Roles to its original state', 'user-role-editor'); ?>"><?php esc_html_e('Reset', 'user-role-editor');?></button>
|
37 |
<?php wp_nonce_field('user-role-editor'); ?>
|
38 |
<input type="hidden" name="ure_settings_tools_exec" value="1" />
|
39 |
<input type="hidden" name="ure_reset_roles_exec" value="1" />
|
1 |
<?php
|
2 |
|
3 |
class URE_Tools {
|
4 |
+
|
5 |
+
const RESET_ROLES_SECURE_TEXT = 'Permanently delete all custom user roles and capabilities';
|
6 |
|
7 |
private static function show_reset_roles( $tab_idx ) {
|
8 |
|
19 |
<h3>Reset User Roles</h3>
|
20 |
<span style="color: red;"><?php esc_html_e('WARNING!', 'user-role-editor');?></span>
|
21 |
<?php
|
22 |
+
esc_html_e('Resetting will setup default user roles and capabilities from WordPress core.', 'user-role-editor'); echo '<br>';
|
23 |
+
esc_html_e('If any plugins (such as WooCommerce, S2Member and many others) have changed user roles and capabilities during installation, those changes will be LOST!', 'user-role-editor'); echo '<br>';
|
24 |
+
esc_html_e('For more information on how to undo undesired changes and restore plugins capabilities in case you lost them by mistake go to: ', 'user-role-editor');
|
25 |
+
echo '<a href="http://role-editor.com/how-to-restore-deleted-wordpress-user-roles/">http://role-editor.com/how-to-restore-deleted-wordpress-user-roles/</a>';
|
26 |
|
27 |
+
if ( $multisite ) {
|
28 |
?>
|
29 |
<br><br>
|
30 |
<input type="checkbox" name="ure_apply_to_all" id="ure_apply_to_all" value="1" />
|
31 |
<label for="ure_apply_to_all"><?php esc_html_e('Apply to All Sites', 'user-role-editor'); ?></label>
|
32 |
(<?php esc_html_e('If checked, then apply action to ALL sites. Main site only is affected in other case.', 'user-role-editor'); ?>)
|
33 |
<?php
|
34 |
+
}
|
35 |
?>
|
36 |
+
<br><br>
|
37 |
+
<input type="text" id="ure_reset_roles_secure" name="ure_reset_roles_secure" value="" placeholder="<?php echo URE_Tools::RESET_ROLES_SECURE_TEXT;?>" style="width:400px;"/>
|
38 |
+
<- <span style="color: red;"><?php echo URE_Tools::RESET_ROLES_SECURE_TEXT; ?></span>
|
39 |
<br><br>
|
40 |
+
<button id="ure_reset_roles_button" style="width: 100px; color: red;" title="<?php esc_html_e('Reset Roles to its original state', 'user-role-editor'); ?>" disabled><?php esc_html_e('Reset', 'user-role-editor');?></button>
|
41 |
<?php wp_nonce_field('user-role-editor'); ?>
|
42 |
<input type="hidden" name="ure_settings_tools_exec" value="1" />
|
43 |
<input type="hidden" name="ure_reset_roles_exec" value="1" />
|
includes/classes/user-role-editor.php
CHANGED
@@ -798,7 +798,8 @@ class User_Role_Editor {
|
|
798 |
esc_html__('If any plugins (such as WooCommerce, S2Member and many others) have changed user roles and capabilities during installation, all those changes will be LOST!', 'user-role-editor') .'<br>'.
|
799 |
esc_html__('For more information on how to undo undesired changes and restore plugin capabilities go to', 'user-role-editor') .'<br>'.
|
800 |
'<a href="http://role-editor.com/how-to-restore-deleted-wordpress-user-roles/">http://role-editor.com/how-to-restore-deleted-wordpress-user-roles/</a>' .'<br><br>'.
|
801 |
-
esc_html__('Continue?', 'user-role-editor')
|
|
|
802 |
));
|
803 |
|
804 |
do_action('ure_load_js_settings');
|
798 |
esc_html__('If any plugins (such as WooCommerce, S2Member and many others) have changed user roles and capabilities during installation, all those changes will be LOST!', 'user-role-editor') .'<br>'.
|
799 |
esc_html__('For more information on how to undo undesired changes and restore plugin capabilities go to', 'user-role-editor') .'<br>'.
|
800 |
'<a href="http://role-editor.com/how-to-restore-deleted-wordpress-user-roles/">http://role-editor.com/how-to-restore-deleted-wordpress-user-roles/</a>' .'<br><br>'.
|
801 |
+
esc_html__('Continue?', 'user-role-editor'),
|
802 |
+
'reset_roles_secure_text' => URE_Tools::RESET_ROLES_SECURE_TEXT
|
803 |
));
|
804 |
|
805 |
do_action('ure_load_js_settings');
|
js/settings.js
CHANGED
@@ -13,7 +13,7 @@ function ure_roles_reset_form_submit() {
|
|
13 |
}
|
14 |
|
15 |
jQuery(function() {
|
16 |
-
|
17 |
jQuery('#ure_reset_roles_button').button({
|
18 |
label: ure_data.reset
|
19 |
}).click(function (event) {
|
@@ -53,5 +53,13 @@ jQuery(function() {
|
|
53 |
}
|
54 |
// end of ure_confirm()
|
55 |
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
});
|
13 |
}
|
14 |
|
15 |
jQuery(function() {
|
16 |
+
|
17 |
jQuery('#ure_reset_roles_button').button({
|
18 |
label: ure_data.reset
|
19 |
}).click(function (event) {
|
53 |
}
|
54 |
// end of ure_confirm()
|
55 |
|
56 |
+
|
57 |
+
jQuery('#ure_reset_roles_secure').on('input', function() {
|
58 |
+
if ( this.value===ure_data.reset_roles_secure_text ) {
|
59 |
+
jQuery('#ure_reset_roles_button').button('enable');
|
60 |
+
} else {
|
61 |
+
jQuery('#ure_reset_roles_button').button('disable');
|
62 |
+
}
|
63 |
+
});
|
64 |
+
|
65 |
});
|
js/ure.js
CHANGED
@@ -89,6 +89,13 @@ jQuery(function() {
|
|
89 |
});
|
90 |
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
// Main User Role Editor object
|
93 |
var ure_main = {
|
94 |
selected_group: 'all',
|
89 |
});
|
90 |
|
91 |
|
92 |
+
if (typeof ure_current_role==='undefined') {
|
93 |
+
var ure_current_role = '';
|
94 |
+
}
|
95 |
+
if (typeof ure_current_role_name==='undefined') {
|
96 |
+
var ure_current_role_name = '';
|
97 |
+
}
|
98 |
+
|
99 |
// Main User Role Editor object
|
100 |
var ure_main = {
|
101 |
selected_group: 'all',
|
readme.txt
CHANGED
@@ -2,10 +2,10 @@
|
|
2 |
Contributors: shinephp
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=vladimir%40shinephp%2ecom&lc=RU&item_name=ShinePHP%2ecom&item_number=User%20Role%20Editor%20WordPress%20plugin¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
|
4 |
Tags: user, role, editor, security, access, permission, capability
|
5 |
-
Requires at least: 4.
|
6 |
-
Tested up to: 5.8.
|
7 |
-
Stable tag: 4.
|
8 |
-
Requires PHP:
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
@@ -81,6 +81,13 @@ https://translate.wordpress.org/projects/wp-plugins/user-role-editor/
|
|
81 |
|
82 |
== Changelog =
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
= [4.60.2] 20.09.2021 =
|
85 |
* Update: Marked as compatible with WordPress 5.8.1
|
86 |
* Fix: Multisite: URE_Editor::is_full_network_sync() returned FALSE, instead TRUE for the AJAX call, while call was made from the Network Admin (wp-admin/network/).
|
@@ -104,7 +111,10 @@ I am ready to answer on your questions about plugin usage. Use [plugin page comm
|
|
104 |
|
105 |
== Upgrade Notice ==
|
106 |
|
107 |
-
= [4.
|
108 |
-
* Update:
|
109 |
-
*
|
|
|
|
|
|
|
110 |
|
2 |
Contributors: shinephp
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=vladimir%40shinephp%2ecom&lc=RU&item_name=ShinePHP%2ecom&item_number=User%20Role%20Editor%20WordPress%20plugin¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
|
4 |
Tags: user, role, editor, security, access, permission, capability
|
5 |
+
Requires at least: 4.4
|
6 |
+
Tested up to: 5.8.2
|
7 |
+
Stable tag: 4.61
|
8 |
+
Requires PHP: 7.4
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
81 |
|
82 |
== Changelog =
|
83 |
|
84 |
+
= [4.61] 28.12.2021 =
|
85 |
+
* Update: WordPress 4.4 is marked as required.
|
86 |
+
* Update: PHP 7.4 is marked as required.
|
87 |
+
* Update: "Settings->User Role Editor->Tools->Reset" button is additionally protected from the unintended/accidental usage by text input field. Manual input of "Permanently delete all custom user roles and capabilities" text is required to enable the "Reset" button.
|
88 |
+
* Update: Partial code review and refactoring according with WordPress & PHP coding standards.
|
89 |
+
* Fix: "Users->selected user->Capabilities" page: 'select all' checkbox did not work.
|
90 |
+
|
91 |
= [4.60.2] 20.09.2021 =
|
92 |
* Update: Marked as compatible with WordPress 5.8.1
|
93 |
* Fix: Multisite: URE_Editor::is_full_network_sync() returned FALSE, instead TRUE for the AJAX call, while call was made from the Network Admin (wp-admin/network/).
|
111 |
|
112 |
== Upgrade Notice ==
|
113 |
|
114 |
+
= [4.61] 28.12.2021 =
|
115 |
+
* Update: WordPress 4.4 is marked as required.
|
116 |
+
* Update: PHP 7.4 is marked as required.
|
117 |
+
* Update: "Settings->User Role Editor->Tools->Reset" button is additionally protected from the unintended/accidental usage by text input field. Manual input of "Permanently delete all custom user roles and capabilities" text is required to enable the "Reset" button.
|
118 |
+
* Update: Partial code review and refactoring according with WordPress & PHP coding standards.
|
119 |
+
* Fix: "Users->selected user->Capabilities" page: 'select all' checkbox did not work.
|
120 |
|
user-role-editor.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: User Role Editor
|
4 |
Plugin URI: https://www.role-editor.com
|
5 |
Description: Change/add/delete WordPress user roles and capabilities.
|
6 |
-
Version: 4.
|
7 |
Author: Vladimir Garagulya
|
8 |
Author URI: https://www.role-editor.com
|
9 |
Text Domain: user-role-editor
|
@@ -23,7 +23,7 @@ if ( defined( 'URE_PLUGIN_URL' ) ) {
|
|
23 |
wp_die( 'It seems that other version of User Role Editor is active. Please deactivate it before use this version' );
|
24 |
}
|
25 |
|
26 |
-
define( 'URE_VERSION', '4.
|
27 |
define( 'URE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
28 |
define( 'URE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
29 |
define( 'URE_PLUGIN_BASE_NAME', plugin_basename( __FILE__ ) );
|
@@ -34,13 +34,13 @@ require_once( URE_PLUGIN_DIR.'includes/classes/base-lib.php' );
|
|
34 |
require_once( URE_PLUGIN_DIR.'includes/classes/lib.php' );
|
35 |
|
36 |
// check PHP version
|
37 |
-
$ure_required_php_version = '
|
38 |
$exit_msg = 'User Role Editor requires PHP '. $ure_required_php_version .' or newer. '.
|
39 |
'<a href="http://wordpress.org/about/requirements/">Please update!</a>';
|
40 |
URE_Lib::check_version( PHP_VERSION, $ure_required_php_version, $exit_msg, __FILE__ );
|
41 |
|
42 |
// check WP version
|
43 |
-
$ure_required_wp_version = '4.
|
44 |
$exit_msg = 'User Role Editor requires WordPress '. $ure_required_wp_version .' or newer. '.
|
45 |
'<a href="http://codex.wordpress.org/Upgrading_WordPress">Please update!</a>';
|
46 |
URE_Lib::check_version( get_bloginfo( 'version' ), $ure_required_wp_version, $exit_msg, __FILE__ );
|
3 |
Plugin Name: User Role Editor
|
4 |
Plugin URI: https://www.role-editor.com
|
5 |
Description: Change/add/delete WordPress user roles and capabilities.
|
6 |
+
Version: 4.61
|
7 |
Author: Vladimir Garagulya
|
8 |
Author URI: https://www.role-editor.com
|
9 |
Text Domain: user-role-editor
|
23 |
wp_die( 'It seems that other version of User Role Editor is active. Please deactivate it before use this version' );
|
24 |
}
|
25 |
|
26 |
+
define( 'URE_VERSION', '4.61' );
|
27 |
define( 'URE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
28 |
define( 'URE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
29 |
define( 'URE_PLUGIN_BASE_NAME', plugin_basename( __FILE__ ) );
|
34 |
require_once( URE_PLUGIN_DIR.'includes/classes/lib.php' );
|
35 |
|
36 |
// check PHP version
|
37 |
+
$ure_required_php_version = '7.4';
|
38 |
$exit_msg = 'User Role Editor requires PHP '. $ure_required_php_version .' or newer. '.
|
39 |
'<a href="http://wordpress.org/about/requirements/">Please update!</a>';
|
40 |
URE_Lib::check_version( PHP_VERSION, $ure_required_php_version, $exit_msg, __FILE__ );
|
41 |
|
42 |
// check WP version
|
43 |
+
$ure_required_wp_version = '4.4';
|
44 |
$exit_msg = 'User Role Editor requires WordPress '. $ure_required_wp_version .' or newer. '.
|
45 |
'<a href="http://codex.wordpress.org/Upgrading_WordPress">Please update!</a>';
|
46 |
URE_Lib::check_version( get_bloginfo( 'version' ), $ure_required_wp_version, $exit_msg, __FILE__ );
|