User Role Editor - Version 4.35.1

Version Description

Download this release

Release Info

Developer shinephp
Plugin Icon 128x128 User Role Editor
Version 4.35.1
Comparing to
See all releases

Code changes from version 4.35 to 4.35.1

includes/classes/assign-role.php CHANGED
@@ -12,13 +12,15 @@
12
  class URE_Assign_Role {
13
 
14
  const MAX_USERS_TO_PROCESS = 50;
 
 
15
 
16
  protected $lib = null;
17
 
18
 
19
- function __construct($lib) {
20
 
21
- $this->lib = $lib;
22
  }
23
  // end of __construct()
24
 
@@ -89,6 +91,31 @@ class URE_Assign_Role {
89
  return $users0;
90
  }
91
  // end of get_users_without_role()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  }
94
  // end of URE_Assign_Role class
12
  class URE_Assign_Role {
13
 
14
  const MAX_USERS_TO_PROCESS = 50;
15
+
16
+ private static $counter = 0;
17
 
18
  protected $lib = null;
19
 
20
 
21
+ function __construct() {
22
 
23
+ $this->lib = URE_Lib::get_instance();
24
  }
25
  // end of __construct()
26
 
91
  return $users0;
92
  }
93
  // end of get_users_without_role()
94
+
95
+
96
+ public function show_html() {
97
+
98
+ $users_quant = $this->count_users_without_role();
99
+ if ($users_quant==0) {
100
+ return;
101
+ }
102
+ $button_number = (self::$counter>0) ? '_2': '';
103
+
104
+ ?>
105
+ &nbsp;&nbsp;<input type="button" name="move_from_no_role<?php echo $button_number;?>" id="move_from_no_role<?php echo $button_number;?>" class="button"
106
+ value="Without role (<?php echo $users_quant;?>)" onclick="ure_move_users_from_no_role_dialog()">
107
+ <?php
108
+ if (self::$counter==0) {
109
+ ?>
110
+ <div id="move_from_no_role_dialog" class="ure-dialog">
111
+ <div id="move_from_no_role_content" style="padding: 10px;"></div>
112
+ </div>
113
+ <?php
114
+ self::$counter++;
115
+ }
116
+
117
+ }
118
+ // end of show_html()
119
 
120
  }
121
  // end of URE_Assign_Role class
includes/classes/bbpress.php CHANGED
@@ -16,7 +16,7 @@ class URE_bbPress {
16
  protected $lib = null;
17
 
18
 
19
- protected function __construct(Ure_Lib $lib) {
20
 
21
  $this->lib = $lib;
22
 
@@ -24,7 +24,7 @@ class URE_bbPress {
24
  // end of __construct()
25
 
26
 
27
- static public function get_instance(Ure_Lib $lib) {
28
  if (!function_exists('bbp_filter_blog_editable_roles')) { // bbPress plugin is not active
29
  return null;
30
  }
@@ -73,5 +73,40 @@ class URE_bbPress {
73
  }
74
  // end of get_caps()
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
77
  // end of URE_bbPress class
16
  protected $lib = null;
17
 
18
 
19
+ protected function __construct(URE_Lib $lib) {
20
 
21
  $this->lib = $lib;
22
 
24
  // end of __construct()
25
 
26
 
27
+ static public function get_instance(URE_Lib $lib) {
28
  if (!function_exists('bbp_filter_blog_editable_roles')) { // bbPress plugin is not active
29
  return null;
30
  }
73
  }
74
  // end of get_caps()
75
 
76
+
77
+ /**
78
+ * Return empty array in order do not include bbPress roles into selectable lists: supported by Pro version only
79
+ * @return array
80
+ */
81
+ public function get_bbp_editable_roles() {
82
+
83
+ $all_bbp_roles = array();
84
+
85
+ return $all_bbp_roles;
86
+ }
87
+ // end of get_bbp_editable_roles()
88
+
89
+
90
+ /**
91
+ * Return bbPress roles found at $roles array. Used to exclude bbPress roles from processing as free version should not support them
92
+ *
93
+ * @param array $roles
94
+ * @return array
95
+ */
96
+ public function extract_bbp_roles($roles) {
97
+
98
+ $all_bbp_roles = array_keys(bbp_get_dynamic_roles());
99
+ $user_bbp_roles = array();
100
+ foreach($roles as $role) {
101
+ if (in_array($role, $all_bbp_roles)) {
102
+ $user_bbp_roles[] = $role;
103
+ }
104
+ }
105
+
106
+ return $user_bbp_roles;
107
+ }
108
+ // end of extract_bbp_roles()
109
+
110
+
111
  }
112
  // end of URE_bbPress class
includes/classes/grant-roles.php CHANGED
@@ -43,7 +43,7 @@ class URE_Grant_Roles {
43
 
44
  return true;
45
  }
46
- // end of validate_users()
47
 
48
 
49
  private static function validate_roles($roles) {
@@ -52,7 +52,8 @@ class URE_Grant_Roles {
52
  return false;
53
  }
54
 
55
- $editable_roles = get_editable_roles();
 
56
  $valid_roles = array_keys($editable_roles);
57
  foreach($roles as $role) {
58
  if (!in_array($role, $valid_roles)) {
@@ -63,7 +64,7 @@ class URE_Grant_Roles {
63
  return true;
64
  }
65
  // end of validate_roles()
66
-
67
 
68
  private static function grant_primary_role_to_user($user_id, $role) {
69
 
@@ -71,13 +72,25 @@ class URE_Grant_Roles {
71
  if (empty($user)) {
72
  return;
73
  }
 
 
74
 
75
- $user->set_role($role);
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  }
78
  // end of grant_primary_role_to_user()
79
-
80
-
81
 
82
  private static function grant_other_roles_to_user($user_id, $roles) {
83
 
@@ -87,8 +100,15 @@ class URE_Grant_Roles {
87
  }
88
 
89
  $primary_role = array_shift(array_values($user->roles)); // Get the 1st element from the roles array
 
 
 
 
 
 
 
90
  $user->remove_all_caps();
91
- $roles = array_merge(array($primary_role), $roles);
92
  foreach($roles as $role) {
93
  $user->add_role($role);
94
  }
@@ -120,7 +140,7 @@ class URE_Grant_Roles {
120
  $lib = URE_Lib::get_instance();
121
  $select_primary_role = apply_filters('ure_users_select_primary_role', true);
122
  if ($select_primary_role || $lib->is_super_admin()) {
123
- foreach ($users as $user_id) {
124
  self::grant_primary_role_to_user($user_id, $primary_role);
125
  }
126
  if (empty($primary_role)) { // users don't have primary role, so they should not have any other roles - stop processing
@@ -200,7 +220,7 @@ class URE_Grant_Roles {
200
  <?php
201
  }
202
  // end of select_primary_role_html()
203
-
204
 
205
  private function select_other_roles_html() {
206
  ?>
@@ -211,8 +231,8 @@ class URE_Grant_Roles {
211
  ?>
212
  </span><br>
213
  <?php
214
- $show_admin_role = $this->lib->show_admin_role_allowed();
215
- $roles = get_editable_roles();
216
  foreach ($roles as $role_id => $role) {
217
  if (!$show_admin_role && $role_id=='administrator') {
218
  continue;
@@ -235,11 +255,12 @@ class URE_Grant_Roles {
235
  if (!current_user_can('edit_users')) {
236
  return;
237
  }
 
238
  ?>
239
- &nbsp;&nbsp;<input type="button" name="ure_grant_roles" id="ure_grant_roles" class="button"
240
  value="<?php esc_html_e('Grant Roles', 'user-role-editor');?>">
241
  <?php
242
- if (self::$counter<1) {
243
  ?>
244
  <div id="ure_grant_roles_dialog" class="ure-dialog">
245
  <div id="ure_grant_roles_content">
43
 
44
  return true;
45
  }
46
+ // end of validate_users()
47
 
48
 
49
  private static function validate_roles($roles) {
52
  return false;
53
  }
54
 
55
+ $lib = URE_Lib::get_instance();
56
+ $editable_roles = $lib->get_all_editable_roles();
57
  $valid_roles = array_keys($editable_roles);
58
  foreach($roles as $role) {
59
  if (!in_array($role, $valid_roles)) {
64
  return true;
65
  }
66
  // end of validate_roles()
67
+
68
 
69
  private static function grant_primary_role_to_user($user_id, $role) {
70
 
72
  if (empty($user)) {
73
  return;
74
  }
75
+
76
+ $user->set_role($role);
77
 
78
+ $lib = URE_Lib::get_instance();
79
+ $bbpress = $lib->get('bbpress');
80
+ if (empty($bbpress)) {
81
+ return;
82
+ }
83
+
84
+ $bbp_roles = $bbpress->extract_bbp_roles($user->roles);
85
+ if (count($bbp_roles)>0) { // restore bbPress roles
86
+ foreach($bbp_roles as $role) {
87
+ $user->add_role($role);
88
+ }
89
+ }
90
 
91
  }
92
  // end of grant_primary_role_to_user()
93
+
 
94
 
95
  private static function grant_other_roles_to_user($user_id, $roles) {
96
 
100
  }
101
 
102
  $primary_role = array_shift(array_values($user->roles)); // Get the 1st element from the roles array
103
+ $lib = URE_Lib::get_instance();
104
+ $bbpress = $lib->get('bbpress');
105
+ if (empty($bbpress)) {
106
+ $bbp_roles = array();
107
+ } else {
108
+ $bbp_roles = $bbpress->extract_bbp_roles($user->roles);
109
+ }
110
  $user->remove_all_caps();
111
+ $roles = array_merge(array($primary_role), $bbp_roles, $roles);
112
  foreach($roles as $role) {
113
  $user->add_role($role);
114
  }
140
  $lib = URE_Lib::get_instance();
141
  $select_primary_role = apply_filters('ure_users_select_primary_role', true);
142
  if ($select_primary_role || $lib->is_super_admin()) {
143
+ foreach ($users as $user_id) {
144
  self::grant_primary_role_to_user($user_id, $primary_role);
145
  }
146
  if (empty($primary_role)) { // users don't have primary role, so they should not have any other roles - stop processing
220
  <?php
221
  }
222
  // end of select_primary_role_html()
223
+
224
 
225
  private function select_other_roles_html() {
226
  ?>
231
  ?>
232
  </span><br>
233
  <?php
234
+ $show_admin_role = $this->lib->show_admin_role_allowed();
235
+ $roles = $this->lib->get_all_editable_roles();
236
  foreach ($roles as $role_id => $role) {
237
  if (!$show_admin_role && $role_id=='administrator') {
238
  continue;
255
  if (!current_user_can('edit_users')) {
256
  return;
257
  }
258
+ $button_number = (self::$counter>0) ? '_2': '';
259
  ?>
260
+ &nbsp;&nbsp;<input type="button" name="ure_grant_roles<?php echo $button_number;?>" id="ure_grant_roles<?php echo $button_number;?>" class="button"
261
  value="<?php esc_html_e('Grant Roles', 'user-role-editor');?>">
262
  <?php
263
+ if (self::$counter==0) {
264
  ?>
265
  <div id="ure_grant_roles_dialog" class="ure-dialog">
266
  <div id="ure_grant_roles_content">
includes/classes/ure-lib.php CHANGED
@@ -11,7 +11,7 @@
11
  /**
12
  * This class contains general stuff for usage at WordPress plugins
13
  */
14
- class Ure_Lib extends URE_Base_Lib {
15
 
16
  const TRANSIENT_EXPIRATION = 600;
17
 
@@ -2168,7 +2168,8 @@ class Ure_Lib extends URE_Base_Lib {
2168
 
2169
  // create assign_role object
2170
  public function get_assign_role() {
2171
- $assign_role = new URE_Assign_Role($this);
 
2172
 
2173
  return $assign_role;
2174
  }
@@ -2207,5 +2208,16 @@ class Ure_Lib extends URE_Base_Lib {
2207
  }
2208
  // end of is_right_admin_path()
2209
 
 
 
 
 
 
 
 
 
 
 
 
2210
  }
2211
  // end of URE_Lib class
11
  /**
12
  * This class contains general stuff for usage at WordPress plugins
13
  */
14
+ class URE_Lib extends URE_Base_Lib {
15
 
16
  const TRANSIENT_EXPIRATION = 600;
17
 
2168
 
2169
  // create assign_role object
2170
  public function get_assign_role() {
2171
+
2172
+ $assign_role = new URE_Assign_Role();
2173
 
2174
  return $assign_role;
2175
  }
2208
  }
2209
  // end of is_right_admin_path()
2210
 
2211
+ /*
2212
+ * It's overriden in Pro version to add bbPress roles
2213
+ */
2214
+ public function get_all_editable_roles() {
2215
+
2216
+ $roles = get_editable_roles(); // WordPress roles
2217
+
2218
+ return $roles;
2219
+ }
2220
+ // end of get_all_roles()
2221
+
2222
  }
2223
  // end of URE_Lib class
includes/classes/user-role-editor.php CHANGED
@@ -251,16 +251,7 @@ class User_Role_Editor {
251
  }
252
 
253
  $assign_role = $this->lib->get_assign_role();
254
- $users_quant = $assign_role->count_users_without_role();
255
- if ($users_quant>0) {
256
- ?>
257
- &nbsp;&nbsp;<input type="button" name="move_from_no_role" id="move_from_no_role" class="button"
258
- value="Without role (<?php echo $users_quant;?>)" onclick="ure_move_users_from_no_role_dialog()">
259
- <div id="move_from_no_role_dialog" class="ure-dialog">
260
- <div id="move_from_no_role_content" style="padding: 10px;"></div>
261
- </div>
262
- <?php
263
- }
264
 
265
  }
266
  // end of move_users_from_no_role()
251
  }
252
 
253
  $assign_role = $this->lib->get_assign_role();
254
+ $assign_role->show_html();
 
 
 
 
 
 
 
 
 
255
 
256
  }
257
  // end of move_users_from_no_role()
js/users-grant-roles.js CHANGED
@@ -7,6 +7,9 @@ jQuery(document).ready(function() {
7
  jQuery('#ure_grant_roles').click(function() {
8
  ure_prepare_grant_roles_dialog();
9
  });
 
 
 
10
 
11
  if (ure_users_grant_roles_data.show_wp_change_role!=1) {
12
  jQuery('#new_role').hide();
7
  jQuery('#ure_grant_roles').click(function() {
8
  ure_prepare_grant_roles_dialog();
9
  });
10
+ jQuery('#ure_grant_roles_2').click(function() {
11
+ ure_prepare_grant_roles_dialog();
12
+ });
13
 
14
  if (ure_users_grant_roles_data.show_wp_change_role!=1) {
15
  jQuery('#new_role').hide();
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=vladi
4
  Tags: user, role, editor, security, access, permission, capability
5
  Requires at least: 4.0
6
  Tested up to: 4.8
7
- Stable tag: 4.35
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -78,6 +78,11 @@ https://translate.wordpress.org/projects/wp-plugins/user-role-editor/
78
 
79
 
80
  == Changelog =
 
 
 
 
 
81
  = [4.35] 11.06.2017 =
82
  * Update: Bulk capabilities selection checkbox is not shown for 'administrator' role for single site WP, and is shown if current user is superadmin for multisite WP. It was done to exclude sudden revoke of all capabilities from the 'administrator' role.
83
  * Update: Full copy of JQuery UI 1.11.4 custom theme CSS file (jquery-ui.css) was included.
4
  Tags: user, role, editor, security, access, permission, capability
5
  Requires at least: 4.0
6
  Tested up to: 4.8
7
+ Stable tag: 4.35.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
78
 
79
 
80
  == Changelog =
81
+ = [4.35.1] 10.07.2017 =
82
+ * Fix: "Grant Roles" button at the bottom of "Users" page did not work as had the same ID as a similar button at the top of this page.
83
+ * Update: when bbPress plugin is active, "Grant Roles" does not revoke bbPress role granted to user anymore.
84
+ * Fix: The same ID "move_from_no_role" and "move_from_no_role_dialog" were included twice to the "Users" page.
85
+
86
  = [4.35] 11.06.2017 =
87
  * Update: Bulk capabilities selection checkbox is not shown for 'administrator' role for single site WP, and is shown if current user is superadmin for multisite WP. It was done to exclude sudden revoke of all capabilities from the 'administrator' role.
88
  * Update: Full copy of JQuery UI 1.11.4 custom theme CSS file (jquery-ui.css) was included.
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.35
7
  Author: Vladimir Garagulya
8
  Author URI: https://www.role-editor.com
9
  Text Domain: ure
@@ -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.35');
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__));
@@ -37,13 +37,13 @@ require_once(URE_PLUGIN_DIR.'includes/classes/ure-lib.php');
37
  $ure_required_php_version = '5.3';
38
  $exit_msg = sprintf( 'User Role Editor requires PHP %s or newer.', $ure_required_php_version ) .
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.0';
44
  $exit_msg = sprintf( 'User Role Editor requires WordPress %s or newer.', $ure_required_wp_version ) .
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__ );
47
 
48
  require_once(URE_PLUGIN_DIR .'includes/loader.php');
49
 
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.35.1
7
  Author: Vladimir Garagulya
8
  Author URI: https://www.role-editor.com
9
  Text Domain: ure
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.35.1');
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__));
37
  $ure_required_php_version = '5.3';
38
  $exit_msg = sprintf( 'User Role Editor requires PHP %s or newer.', $ure_required_php_version ) .
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.0';
44
  $exit_msg = sprintf( 'User Role Editor requires WordPress %s or newer.', $ure_required_wp_version ) .
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__ );
47
 
48
  require_once(URE_PLUGIN_DIR .'includes/loader.php');
49