User Role Editor - Version 4.49

Version Description

Download this release

Release Info

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

Code changes from version 4.48 to 4.49

changelog.txt CHANGED
@@ -1,5 +1,12 @@
1
  CHANGES LOG (full version).
2
  ===========================
 
 
 
 
 
 
 
3
 
4
  = [4.48] 03.01.2019 =
5
  * Update: Multisite: Sites list is not requested from the database on every page opened in order to reduce server load.
1
  CHANGES LOG (full version).
2
  ===========================
3
+ = [4.49] 15.01.2019 =
4
+ * Update: Selected role ID was added to "Delete role" confirmation dialog.
5
+ * Update: Method URE_Base_Lib::get_short_list_str() was enhanced.
6
+ * Update: Method URE_Base_Lib::get_blog_ids() was made public.
7
+ * Update: Method URE_Lib::get_usermeta_table_name() was excluded.
8
+ * Fix: PHP warning "Undefined index:'unexisted role ID'" was fixed at URE_Lib::roles_text() (wp-content/plugins/user-role-editor/includes/classes/lib.php:360).
9
+ * Fix: Bug was fixed with incorrect usage of transient for option "Show deprecated capabilities".
10
 
11
  = [4.48] 03.01.2019 =
12
  * Update: Multisite: Sites list is not requested from the database on every page opened in order to reduce server load.
includes/classes/assign-role.php CHANGED
@@ -64,7 +64,7 @@ class URE_Assign_Role {
64
  private function get_thorougly_where_condition() {
65
  global $wpdb;
66
 
67
- $usermeta = $this->lib->get_usermeta_table_name();
68
  $id = get_current_blog_id();
69
  $blog_prefix = $wpdb->get_blog_prefix($id);
70
  $where = "WHERE NOT EXISTS (SELECT user_id from {$usermeta} ".
@@ -81,7 +81,7 @@ class URE_Assign_Role {
81
  private function get_quick_query_part2() {
82
  global $wpdb;
83
 
84
- $usermeta = $this->lib->get_usermeta_table_name();
85
  $id = get_current_blog_id();
86
  $blog_prefix = $wpdb->get_blog_prefix($id);
87
  $query = "FROM {$usermeta} usermeta ".
64
  private function get_thorougly_where_condition() {
65
  global $wpdb;
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} ".
81
  private function get_quick_query_part2() {
82
  global $wpdb;
83
 
84
+ $usermeta = $wpdb->usermeta;
85
  $id = get_current_blog_id();
86
  $blog_prefix = $wpdb->get_blog_prefix($id);
87
  $query = "FROM {$usermeta} usermeta ".
includes/classes/base-lib.php CHANGED
@@ -85,7 +85,7 @@ class URE_Base_Lib {
85
  * @global wpdb $wpdb
86
  * @return array
87
  */
88
- protected function get_blog_ids() {
89
  global $wpdb;
90
 
91
  $network = get_current_site();
@@ -119,7 +119,7 @@ class URE_Base_Lib {
119
 
120
  if ($message) {
121
  if ($error_style) {
122
- echo '<div id="message" class="error" >';
123
  } else {
124
  echo '<div id="message" class="updated fade">';
125
  }
@@ -275,8 +275,12 @@ class URE_Base_Lib {
275
  */
276
  public function get_short_list_str($full_list, $items_count=3) {
277
 
 
 
 
 
278
  $short_list = array(); $i = 0;
279
- foreach($full_list as $key=>$item) {
280
  if ($i>=$items_count) {
281
  break;
282
  }
@@ -286,7 +290,7 @@ class URE_Base_Lib {
286
 
287
  $str = implode(', ', $short_list);
288
  if ($items_count<count($full_list)) {
289
- $str .= '...';
290
  }
291
 
292
  return $str;
@@ -347,4 +351,4 @@ class URE_Base_Lib {
347
  // end of __wakeup()
348
 
349
  }
350
- // end of URE_Base_Lib class
85
  * @global wpdb $wpdb
86
  * @return array
87
  */
88
+ public function get_blog_ids() {
89
  global $wpdb;
90
 
91
  $network = get_current_site();
119
 
120
  if ($message) {
121
  if ($error_style) {
122
+ echo '<div id="message" class="error">';
123
  } else {
124
  echo '<div id="message" class="updated fade">';
125
  }
275
  */
276
  public function get_short_list_str($full_list, $items_count=3) {
277
 
278
+ if (empty($full_list) || !is_array($full_list)) {
279
+ return '...';
280
+ }
281
+
282
  $short_list = array(); $i = 0;
283
+ foreach($full_list as $item) {
284
  if ($i>=$items_count) {
285
  break;
286
  }
290
 
291
  $str = implode(', ', $short_list);
292
  if ($items_count<count($full_list)) {
293
+ $str .= ', ...';
294
  }
295
 
296
  return $str;
351
  // end of __wakeup()
352
 
353
  }
354
+ // end of URE_Base_Lib class
includes/classes/lib.php CHANGED
@@ -303,28 +303,30 @@ class URE_Lib extends URE_Base_Lib {
303
 
304
  protected function init_current_role_name() {
305
 
306
- if (!isset($this->roles[$_POST['user_role']])) {
 
 
 
 
307
  $mess = esc_html__('Error: ', 'user-role-editor') . esc_html__('Role', 'user-role-editor') . ' <em>' . esc_html($_POST['user_role']) . '</em> ' .
308
- esc_html__('does not exist', 'user-role-editor');
309
- $this->current_role = '';
310
- $this->current_role_name = '';
311
  } else {
312
  $this->current_role = $_POST['user_role'];
313
  $this->current_role_name = $this->roles[$this->current_role]['name'];
314
  $mess = '';
315
  }
316
 
317
- return $mess;
318
-
319
  }
320
  // end of init_current_role_name()
321
 
322
 
323
- // Add existing WPBakery Visial Composer () plugin capabilities from this role to the list of capabiliteis for save with this role update -
324
  // Visual Composer capabilities are excluded from a role update as they may store not boolean values.
325
  protected function restore_visual_composer_caps() {
 
326
  if (!isset($this->roles[$this->current_role]) || !is_array($this->roles[$this->current_role]['capabilities'])) {
327
- return;
328
  }
329
 
330
  foreach($this->roles[$this->current_role]['capabilities'] as $cap=>$value) {
@@ -333,6 +335,7 @@ class URE_Lib extends URE_Base_Lib {
333
  }
334
  }
335
 
 
336
  }
337
  // end of restore_visual_composer_caps()
338
 
@@ -506,7 +509,7 @@ class URE_Lib extends URE_Base_Lib {
506
  $this->show_deprecated_caps = get_site_transient('ure_show_deprecated_caps');
507
  if (false === $this->show_deprecated_caps) {
508
  $this->show_deprecated_caps = $this->get_option('ure_show_deprecated_caps');
509
- set_site_transient('ure_caps_readable', $this->caps_readable, self::TRANSIENT_EXPIRATION);
510
  }
511
 
512
  $this->hide_pro_banner = $this->get_option('ure_hide_pro_banner', 0);
@@ -559,15 +562,7 @@ class URE_Lib extends URE_Base_Lib {
559
  return $last_role_id;
560
  }
561
  // end of get_last_role_id()
562
-
563
-
564
- public function get_usermeta_table_name() {
565
- global $wpdb;
566
-
567
- return $wpdb->usermeta;
568
- }
569
- // end of get_usermeta_table_name()
570
-
571
 
572
  /**
573
  * Checks if user is allowed to use User Role Editor
@@ -1874,7 +1869,11 @@ class URE_Lib extends URE_Base_Lib {
1874
  if (is_array($roles) && count($roles) > 0) {
1875
  $role_names = array();
1876
  foreach ($roles as $role) {
1877
- $role_names[] = $wp_roles->roles[$role]['name'];
 
 
 
 
1878
  }
1879
  $output = implode(', ', $role_names);
1880
  } else {
@@ -1937,8 +1936,8 @@ class URE_Lib extends URE_Base_Lib {
1937
  // end of show_admin_role()
1938
 
1939
 
1940
- // returns true if $user has $capability assigned through the roles or directly
1941
- // returns true if user has role with name equal $capability
1942
  public function user_can($capability) {
1943
 
1944
  if (isset($this->user_to_edit->caps[$capability])) {
@@ -1993,13 +1992,13 @@ class URE_Lib extends URE_Base_Lib {
1993
  // end of is_super_admin()
1994
 
1995
 
1996
- // Returns true if user is a real superadmin
1997
  // Returns true if user has $capability assigned through the roles or directly
1998
  // Returns true if user has role with name equal $cap
1999
  public function user_has_capability($user, $cap) {
2000
  global $wp_roles;
2001
 
2002
- if (!is_object($user) || empty($user->ID)) {
2003
  return false;
2004
  }
2005
  if ($this->multisite && !$this->raised_permissions && is_super_admin($user->ID)) { // do not replace with $this->is_super_admin() to exclude recursion
@@ -2151,4 +2150,4 @@ class URE_Lib extends URE_Base_Lib {
2151
  // end of get_all_roles()
2152
 
2153
  }
2154
- // end of URE_Lib class
303
 
304
  protected function init_current_role_name() {
305
 
306
+ $this->current_role = '';
307
+ $this->current_role_name = '';
308
+ if ( !isset( $_POST['user_role'] ) ) {
309
+ $mess = esc_html__('Error: ', 'user-role-editor') . esc_html__('Wrong request!', 'user-role-editor');
310
+ } else if ( !isset($this->roles[$_POST['user_role']]) ) {
311
  $mess = esc_html__('Error: ', 'user-role-editor') . esc_html__('Role', 'user-role-editor') . ' <em>' . esc_html($_POST['user_role']) . '</em> ' .
312
+ esc_html__('does not exist', 'user-role-editor');
 
 
313
  } else {
314
  $this->current_role = $_POST['user_role'];
315
  $this->current_role_name = $this->roles[$this->current_role]['name'];
316
  $mess = '';
317
  }
318
 
319
+ return $mess;
 
320
  }
321
  // end of init_current_role_name()
322
 
323
 
324
+ // Add existing WPBakery Visial Composer () plugin capabilities from this role to the list of capabilities for save with this role update -
325
  // Visual Composer capabilities are excluded from a role update as they may store not boolean values.
326
  protected function restore_visual_composer_caps() {
327
+
328
  if (!isset($this->roles[$this->current_role]) || !is_array($this->roles[$this->current_role]['capabilities'])) {
329
+ return false;
330
  }
331
 
332
  foreach($this->roles[$this->current_role]['capabilities'] as $cap=>$value) {
335
  }
336
  }
337
 
338
+ return true;
339
  }
340
  // end of restore_visual_composer_caps()
341
 
509
  $this->show_deprecated_caps = get_site_transient('ure_show_deprecated_caps');
510
  if (false === $this->show_deprecated_caps) {
511
  $this->show_deprecated_caps = $this->get_option('ure_show_deprecated_caps');
512
+ set_site_transient( 'ure_show_deprecated_caps', $this->show_deprecated_caps, URE_Lib::TRANSIENT_EXPIRATION );
513
  }
514
 
515
  $this->hide_pro_banner = $this->get_option('ure_hide_pro_banner', 0);
562
  return $last_role_id;
563
  }
564
  // end of get_last_role_id()
565
+
 
 
 
 
 
 
 
 
566
 
567
  /**
568
  * Checks if user is allowed to use User Role Editor
1869
  if (is_array($roles) && count($roles) > 0) {
1870
  $role_names = array();
1871
  foreach ($roles as $role) {
1872
+ if (isset($wp_roles->roles[$role])) {
1873
+ $role_names[] = $wp_roles->roles[$role]['name'];
1874
+ } else {
1875
+ $role_names[] = $role;
1876
+ }
1877
  }
1878
  $output = implode(', ', $role_names);
1879
  } else {
1936
  // end of show_admin_role()
1937
 
1938
 
1939
+ // returns true if editing user has $capability assigned through the roles or directly
1940
+ // returns true if editing user has role with name equal $capability
1941
  public function user_can($capability) {
1942
 
1943
  if (isset($this->user_to_edit->caps[$capability])) {
1992
  // end of is_super_admin()
1993
 
1994
 
1995
+ // Returns true for any capability if user is a real superadmin under multisite
1996
  // Returns true if user has $capability assigned through the roles or directly
1997
  // Returns true if user has role with name equal $cap
1998
  public function user_has_capability($user, $cap) {
1999
  global $wp_roles;
2000
 
2001
+ if (!is_object($user) || !is_a( $user, 'WP_User') || empty($user->ID)) {
2002
  return false;
2003
  }
2004
  if ($this->multisite && !$this->raised_permissions && is_super_admin($user->ID)) { // do not replace with $this->is_super_admin() to exclude recursion
2150
  // end of get_all_roles()
2151
 
2152
  }
2153
+ // end of URE_Lib class
js/ure.js CHANGED
@@ -274,7 +274,14 @@ jQuery(function ($) {
274
  buttons: {
275
  'Delete Role': function () {
276
  var user_role_id = $('#del_user_role').val();
277
- if (!confirm(ure_data.delete_role)) {
 
 
 
 
 
 
 
278
  return false;
279
  }
280
  $(this).dialog('close');
274
  buttons: {
275
  'Delete Role': function () {
276
  var user_role_id = $('#del_user_role').val();
277
+ var question = '';
278
+ if (user_role_id!=-1) {
279
+ question = ure_data.delete_role +' "'+ user_role_id +'"';
280
+ } else {
281
+ question = $('#del_user_role').find('option:selected').text();
282
+ }
283
+ question += '?';
284
+ if (!confirm(question)) {
285
  return false;
286
  }
287
  $(this).dialog('close');
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: 5.0.2
7
- Stable tag: 4.48
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -79,27 +79,19 @@ https://translate.wordpress.org/projects/wp-plugins/user-role-editor/
79
 
80
 
81
  == Changelog =
 
 
 
 
 
 
 
 
82
  = [4.48] 03.01.2019 =
83
  * Update: Multisite: Sites list is not requested from the database on every page opened in order to reduce server load.
84
  * Update: URE plugin version update routine is called now at the wp-admin backend only.
85
  * Update: Direct access to URE_Lib::bbpress property was excluded as a preparation to future code enhancements.
86
 
87
- = [4.47] 12.11.2018 =
88
- * Fix: "Users->User Role Editor": Capabilities view was not refreshed properly for new selected role in case "Granted Only" filter was turned ON before other role selection.
89
- * Update: Unused code was removed from user-role-editor/includes/classes/bbpress.php
90
- * Update: Prevent sudden revoke role 'administrator' from a user(s) during capability with the same ID ('administrator') deletion from roles.
91
- * Update: Adding custom capability with ID 'administrator' was prohibited.
92
- * Update: Marked as compatible with WordPress version 5.0
93
-
94
- = [4.46] 25.09.2018 =
95
- * Update: "Users" page, "Without role" button: underlying SQL queries were replaced with more robust versions (about 10 times faster).
96
- It is critical for sites with large quant of users.New query does not take into account though some cases with incorrect users data (usually imported from the external sources).
97
- It's possible to use older (comprehensive but slower) query version defining a PHP constant: "define('URE_COUNT_USERS_WITHOUT_ROLE_THOROUGHLY', true);" or
98
- return false from a custom 'ure_count_users_without_role_quick' filter.
99
- * Update: Error checking was enhanced after default role change for the WordPress multisite subsite.
100
- * Update: URE settings page template: HTML helper checked() is used where applicable.
101
- * Fix: 2 spelling mistakes were fixed in the text labels.
102
-
103
  For full list of changes applied to User Role Editor plugin look changelog.txt file.
104
 
105
 
@@ -110,10 +102,14 @@ You can find more information about "User Role Editor" plugin at [this page](htt
110
  I am ready to answer on your questions about plugin usage. Use [plugin page comments](http://www.shinephp.com/user-role-editor-wordpress-plugin/) for that.
111
 
112
  == Upgrade Notice ==
113
- = [4.48] 03.01.2019 =
114
- * Update: Multisite: Sites list is not requested from the database on every page opened in order to reduce server load.
115
- * Update: URE plugin version update routine is called now at the wp-admin backend only.
116
- * Update: Direct access to URE_Lib::bbpress property was excluded as a preparation to future code enhancements.
 
 
 
 
117
 
118
 
119
 
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: 5.0.3
7
+ Stable tag: 4.49
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
79
 
80
 
81
  == Changelog =
82
+ = [4.49] 15.01.2019 =
83
+ * Update: Selected role ID was added to "Delete role" confirmation dialog.
84
+ * Update: Method URE_Base_Lib::get_short_list_str() was enhanced.
85
+ * Update: Method URE_Base_Lib::get_blog_ids() was made public.
86
+ * Update: Method URE_Lib::get_usermeta_table_name() was excluded.
87
+ * Fix: PHP warning "Undefined index:'unexisted role ID'" was fixed at URE_Lib::roles_text() (wp-content/plugins/user-role-editor/includes/classes/lib.php:360).
88
+ * Fix: Bug was fixed with incorrect usage of transient for option "Show deprecated capabilities".
89
+
90
  = [4.48] 03.01.2019 =
91
  * Update: Multisite: Sites list is not requested from the database on every page opened in order to reduce server load.
92
  * Update: URE plugin version update routine is called now at the wp-admin backend only.
93
  * Update: Direct access to URE_Lib::bbpress property was excluded as a preparation to future code enhancements.
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  For full list of changes applied to User Role Editor plugin look changelog.txt file.
96
 
97
 
102
  I am ready to answer on your questions about plugin usage. Use [plugin page comments](http://www.shinephp.com/user-role-editor-wordpress-plugin/) for that.
103
 
104
  == Upgrade Notice ==
105
+ = [4.49] 15.01.2019 =
106
+ * Update: Selected role ID was added to "Delete role" confirmation dialog.
107
+ * Update: Method URE_Base_Lib::get_short_list_str() was enhanced.
108
+ * Update: Method URE_Base_Lib::get_blog_ids() was made public.
109
+ * Update: Method URE_Lib::get_usermeta_table_name() was excluded.
110
+ * Fix: PHP warning "Undefined index:'unexisted role ID'" was fixed at URE_Lib::roles_text() (wp-content/plugins/user-role-editor/includes/classes/lib.php:360).
111
+ * Fix: Bug was fixed with incorrect usage of transient for option "Show deprecated capabilities".
112
+
113
 
114
 
115
 
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.48
7
  Author: Vladimir Garagulya
8
  Author URI: https://www.role-editor.com
9
  Text Domain: user-role-editor
@@ -11,7 +11,7 @@ Domain Path: /lang/
11
  */
12
 
13
  /*
14
- Copyright 2010-2018 Vladimir Garagulya (email: support@role-editor.com)
15
  */
16
 
17
  if ( ! function_exists( 'get_option' ) ) {
@@ -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.48' );
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.49
7
  Author: Vladimir Garagulya
8
  Author URI: https://www.role-editor.com
9
  Text Domain: user-role-editor
11
  */
12
 
13
  /*
14
+ Copyright 2010-2019 Vladimir Garagulya (email: support@role-editor.com)
15
  */
16
 
17
  if ( ! function_exists( 'get_option' ) ) {
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.49' );
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__ ) );