User Role Editor - Version 4.36

Version Description

Download this release

Release Info

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

Code changes from version 4.35.3 to 4.36

includes/classes/base-lib.php CHANGED
@@ -175,13 +175,17 @@ class URE_Base_Lib {
175
  public function get_option($option_name, $default = false) {
176
 
177
  if (isset($this->options[$option_name])) {
178
- return $this->options[$option_name];
179
  } else {
180
- return $default;
181
  }
 
 
 
182
  }
183
  // end of get_option()
184
 
 
185
  /**
186
  * puts option value according to $option_name option name into options array property
187
  */
175
  public function get_option($option_name, $default = false) {
176
 
177
  if (isset($this->options[$option_name])) {
178
+ $value = $this->options[$option_name];
179
  } else {
180
+ $value = $default;
181
  }
182
+ $value = apply_filters('ure_get_option_'. $option_name, $value);
183
+
184
+ return $value;
185
  }
186
  // end of get_option()
187
 
188
+
189
  /**
190
  * puts option value according to $option_name option name into options array property
191
  */
includes/classes/grant-roles.php CHANGED
@@ -10,6 +10,8 @@
10
  */
11
 
12
  class URE_Grant_Roles {
 
 
13
 
14
  private $lib = null;
15
  private static $counter = 0;
@@ -72,7 +74,11 @@ class URE_Grant_Roles {
72
  if (empty($user)) {
73
  return;
74
  }
75
-
 
 
 
 
76
  $user->set_role($role);
77
 
78
  $lib = URE_Lib::get_instance();
@@ -81,7 +87,7 @@ class URE_Grant_Roles {
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);
@@ -117,6 +123,30 @@ class URE_Grant_Roles {
117
  // end of grant_other_roles_to_user()
118
 
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  public static function grant_roles() {
121
 
122
  if (!current_user_can('edit_users')) {
@@ -132,21 +162,16 @@ class URE_Grant_Roles {
132
 
133
  // Primary role
134
  $primary_role = $_POST['primary_role'];
135
- if (!empty($primary_role) && !self::validate_roles(array($primary_role=>$primary_role))) {
 
136
  $answer = array('result'=>'error', 'message'=>esc_html__('Invalid primary role', 'user-role-editor'));
137
  return $answer;
138
  }
139
-
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
147
- $answer = array('result'=>'success', 'message'=>esc_html__('Users does not have role for this site', 'user-role-editor'));
148
- return;
149
- }
150
  }
151
 
152
  // Other roles
@@ -213,7 +238,7 @@ class URE_Grant_Roles {
213
  <?php
214
  // print the full list of roles with the primary one selected.
215
  wp_dropdown_roles('');
216
- echo '<option value="">' . esc_html__('&mdash; No role for this site &mdash;') . '</option>'. PHP_EOL;
217
  ?>
218
  </select>
219
  <hr/>
10
  */
11
 
12
  class URE_Grant_Roles {
13
+
14
+ const NO_ROLE_FOR_THIS_SITE = 'no-role-for-this-site';
15
 
16
  private $lib = null;
17
  private static $counter = 0;
74
  if (empty($user)) {
75
  return;
76
  }
77
+
78
+ if ($role===self::NO_ROLE_FOR_THIS_SITE) {
79
+ $role = '';
80
+ }
81
+ $old_roles = $user->roles; // Save currently granted roles to restore from them the bbPress roles later if there are any...
82
  $user->set_role($role);
83
 
84
  $lib = URE_Lib::get_instance();
87
  return;
88
  }
89
 
90
+ $bbp_roles = $bbpress->extract_bbp_roles($old_roles);
91
  if (count($bbp_roles)>0) { // restore bbPress roles
92
  foreach($bbp_roles as $role) {
93
  $user->add_role($role);
123
  // end of grant_other_roles_to_user()
124
 
125
 
126
+ /**
127
+ * Decide if primary role should be granted or left as it is
128
+ *
129
+ * @param string $primary_role
130
+ * @return boolean
131
+ */
132
+ private static function is_select_primary_role($primary_role) {
133
+
134
+ if (empty($primary_role)) {
135
+ return false; // Primary role was not selected by user, leave an older one
136
+ }
137
+
138
+ $lib = URE_Lib::get_instance();
139
+ if ($lib->is_super_admin()) {
140
+ $select_primary_role = true;
141
+ } else {
142
+ $select_primary_role = apply_filters('ure_users_select_primary_role', true);
143
+ }
144
+
145
+ return $select_primary_role;
146
+ }
147
+ // end of is_select_primary_role()
148
+
149
+
150
  public static function grant_roles() {
151
 
152
  if (!current_user_can('edit_users')) {
162
 
163
  // Primary role
164
  $primary_role = $_POST['primary_role'];
165
+ if (!empty($primary_role) && ($primary_role!==self::NO_ROLE_FOR_THIS_SITE) &&
166
+ !self::validate_roles(array($primary_role=>$primary_role))) {
167
  $answer = array('result'=>'error', 'message'=>esc_html__('Invalid primary role', 'user-role-editor'));
168
  return $answer;
169
  }
170
+
171
+ if (self::is_select_primary_role($primary_role)) {
 
 
172
  foreach ($users as $user_id) {
173
  self::grant_primary_role_to_user($user_id, $primary_role);
174
+ }
 
 
 
 
175
  }
176
 
177
  // Other roles
238
  <?php
239
  // print the full list of roles with the primary one selected.
240
  wp_dropdown_roles('');
241
+ echo '<option value="'. self::NO_ROLE_FOR_THIS_SITE .'">' . esc_html__('&mdash; No role for this site &mdash;') . '</option>'. PHP_EOL;
242
  ?>
243
  </select>
244
  <hr/>
includes/classes/screen-help.php CHANGED
@@ -22,6 +22,8 @@ class URE_Screen_Help {
22
  esc_html__('Capabilities like "level_0", "level_1" are deprecated and are not used by WordPress. '
23
  . 'They are left at the user roles for the compatibility purpose with the old themes and plugins code. '
24
  . 'Turning on this option will show those deprecated capabilities.', 'user-role-editor') . '</li>
 
 
25
  <li><strong>' . esc_html__('Edit user capabilities','user-role-editor').'</strong> - '.
26
  esc_html__('If turned off - capabilities section of selected user is shown in readonly mode. '
27
  . 'Administrator can not assign capabilities to the user directly. '
22
  esc_html__('Capabilities like "level_0", "level_1" are deprecated and are not used by WordPress. '
23
  . 'They are left at the user roles for the compatibility purpose with the old themes and plugins code. '
24
  . 'Turning on this option will show those deprecated capabilities.', 'user-role-editor') . '</li>
25
+ <li><strong>' . esc_html__('Confirm role update','user-role-editor').'</strong> - ' .
26
+ esc_html__('Show confirmation dialog before save changes made to a current role.') . '</li>
27
  <li><strong>' . esc_html__('Edit user capabilities','user-role-editor').'</strong> - '.
28
  esc_html__('If turned off - capabilities section of selected user is shown in readonly mode. '
29
  . 'Administrator can not assign capabilities to the user directly. '
includes/classes/user-other-roles.php CHANGED
@@ -263,13 +263,17 @@ class URE_User_Other_Roles {
263
  }
264
  if (!current_user_can('edit_user', $user_id)) {
265
  return false;
266
- }
267
- $user = get_userdata($user_id);
268
 
269
- if (empty($_POST['ure_other_roles'])) {
270
  return false;
271
  }
272
 
 
 
 
 
 
273
  $data = explode(',', str_replace(' ', '', $_POST['ure_other_roles']));
274
  $ure_other_roles = array();
275
  foreach($data as $role_id) {
@@ -290,6 +294,13 @@ class URE_User_Other_Roles {
290
 
291
 
292
  private function add_default_other_roles($user_id) {
 
 
 
 
 
 
 
293
  $user = get_user_by('id', $user_id);
294
  if (empty($user->ID)) {
295
  return;
263
  }
264
  if (!current_user_can('edit_user', $user_id)) {
265
  return false;
266
+ }
 
267
 
268
+ if (!isset($_POST['ure_other_roles'])) { // add default other roles, there is no related data at the POST
269
  return false;
270
  }
271
 
272
+ if (empty($_POST['ure_other_roles'])) { // there is no need in other roles, user did not selected them
273
+ return true;
274
+ }
275
+
276
+ $user = get_userdata($user_id);
277
  $data = explode(',', str_replace(' ', '', $_POST['ure_other_roles']));
278
  $ure_other_roles = array();
279
  foreach($data as $role_id) {
294
 
295
 
296
  private function add_default_other_roles($user_id) {
297
+ if (!current_user_can('edit_users')) {
298
+ return false;
299
+ }
300
+ if (!current_user_can('edit_user', $user_id)) {
301
+ return false;
302
+ }
303
+
304
  $user = get_user_by('id', $user_id);
305
  if (empty($user->ID)) {
306
  return;
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
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.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -79,6 +79,13 @@ https://translate.wordpress.org/projects/wp-plugins/user-role-editor/
79
 
80
  == Changelog =
81
 
 
 
 
 
 
 
 
82
  = [4.35.3] 20.07.2017 =
83
  * Fix: Multiple roles assignment (including default roles) did not work at "Users->Add New" new-user.php (contexts: add-existing-user, add-new-user) page for WordPress multisite.
84
 
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&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
4
  Tags: user, role, editor, security, access, permission, capability
5
  Requires at least: 4.0
6
+ Tested up to: 4.8.1
7
+ Stable tag: 4.36
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
79
 
80
  == Changelog =
81
 
82
+ = [4.36] 19.09.2017 =
83
+ * New: It's possible to set any URE's option value programmatically: use custom filter 'ure_get_option_<option_name>'. It takes a single parameter with current/default value for required options.
84
+ Full list of User Role Editor options is available here: https://www.role-editor.com/documentation/options-list
85
+ * Update: Users page - Grant Roles. It's possible to change just "Other roles" for multiple users and leave their primary roles untouched. Just leave a "Primary role" field empty. If you select the "- No role for this site -" option from a "Primary role" drop-down list, plugin will revoke all roles from the selected users.
86
+ * Update: Options page screen help text was updated.
87
+ * Fix: Additional (other) default roles set at URE's settings page are not granted to a new user now, if they were deselected at a 'Add New User' page.
88
+
89
  = [4.35.3] 20.07.2017 =
90
  * Fix: Multiple roles assignment (including default roles) did not work at "Users->Add New" new-user.php (contexts: add-existing-user, add-new-user) page for WordPress multisite.
91
 
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.3
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.3');
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__));
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.36
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.36');
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__));