Changeset 3407477
- Timestamp:
- 12/02/2025 03:08:23 AM (12 days ago)
- Location:
- user-role-editor/trunk
- Files:
-
- 9 edited
-
includes/classes/ajax-processor.php (modified) (5 diffs)
-
includes/classes/grant-roles.php (modified) (9 diffs)
-
includes/classes/settings.php (modified) (2 diffs)
-
includes/classes/tools.php (modified) (1 diff)
-
includes/classes/user-view.php (modified) (2 diffs)
-
includes/settings-template.php (modified) (7 diffs)
-
js/users-grant-roles.js (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
-
user-role-editor.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
user-role-editor/trunk/includes/classes/ajax-processor.php
r3208188 r3407477 44 44 $promote_users_actions = array( 45 45 'grant_roles', 46 'get_user_roles',47 46 'add_role_to_user', 48 47 'revoke_role_from_user' … … 231 230 // end of get_users_without_role() 232 231 232 233 protected function get_grant_roles() { 234 235 $answer = URE_Grant_Roles::get_dialog_html(); 236 237 return $answer; 238 239 } 240 // end of get_grant_roles_dialog_html() 241 242 233 243 234 244 protected function grant_roles() { … … 261 271 // end of add_role_to_user() 262 272 263 protected function get_user_roles() { 264 265 $answer = URE_Grant_Roles::get_user_roles(); 266 267 return $answer; 268 269 } 270 // end of get_user_roles() 271 272 273 273 274 protected function get_role_caps() { 274 275 … … 351 352 $answer = $this->get_users_without_role(); 352 353 break; 354 case 'get_grant_roles': 355 $answer = $this->get_grant_roles(); 356 break; 353 357 case 'grant_roles': 354 358 $answer = $this->grant_roles(); … … 359 363 case 'revoke_role_from_user': 360 364 $answer = $this->revoke_role_from_user(); 361 break;362 case 'get_user_roles':363 $answer = $this->get_user_roles();364 365 break; 365 366 case 'get_role_caps': -
user-role-editor/trunk/includes/classes/grant-roles.php
r3274620 r3407477 329 329 } 330 330 331 $users = $_POST['users'];331 $users = isset( $_POST['users'] ) ? $_POST['users'] : false; 332 332 if ( !self::validate_users( $users ) ) { 333 333 $answer = array('result'=>'error', 'message'=>esc_html__('Can not edit user or invalid data at the users list', 'user-role-editor') ); … … 368 368 369 369 370 public static function get_user_roles() { 371 372 if ( !current_user_can( 'promote_users' ) ) { 373 $answer = array('result'=>'error', 'message'=>esc_html__('Not enough permissions', 'user-role-editor')); 374 return $answer; 375 } 376 377 $lib = URE_Lib::get_instance(); 378 $user_id = (int) $lib->get_request_var('user_id', 'post', 'int'); 379 if (empty($user_id)) { 380 $answer = array('result'=>'error', 'message'=>esc_html__('Wrong request, valid user ID was missed', 'user-role-editor')); 370 private static function get_user_roles( $user_id ) { 371 372 $answer = array('primary_role'=>'', 'other_roles'=>array() ); 373 if ( empty($user_id) ) { 381 374 return $answer; 382 375 } 383 376 384 377 $user = get_user_by('id', $user_id); 385 if (empty($user)) { 386 $answer = array('result'=>'error', 'message'=>esc_html__('Requested user does not exist', 'user-role-editor')); 378 if ( empty( $user ) ) { 387 379 return $answer; 388 380 } … … 391 383 $primary_role = array_shift($other_roles); 392 384 393 $answer = array(' result'=>'success', 'primary_role'=>$primary_role, 'other_roles'=>$other_roles, 'message'=>'User roles were sent');385 $answer = array('primary_role'=>$primary_role, 'other_roles'=>$other_roles ); 394 386 395 387 return $answer; 396 388 } 397 389 // end of get_user_roles() 398 399 400 401 private function select_primary_role_html() {402 390 391 392 private static function select_primary_role_html( $primary_role ) { 393 394 $lib = URE_Lib::get_instance(); 403 395 $select_primary_role = apply_filters('ure_users_select_primary_role', true); 404 if (!$select_primary_role && !$ this->lib->is_super_admin()) {396 if (!$select_primary_role && !$lib->is_super_admin()) { 405 397 return; 406 398 } … … 412 404 <?php 413 405 // print the full list of roles with the primary one selected. 414 wp_dropdown_roles( '');406 wp_dropdown_roles( $primary_role ); 415 407 echo '<option value="'. self::NO_ROLE_FOR_THIS_SITE .'">' . esc_html__('— No role for this site —', 'user-role-editor') . '</option>'. PHP_EOL; 416 408 ?> … … 422 414 423 415 424 private function select_other_roles_html() { 416 private static function select_other_roles_html( $other_roles ) { 417 $lib = URE_Lib::get_instance(); 425 418 ?> 426 419 <div id="other_roles_container"> … … 434 427 $use_pll = function_exists('pll__'); 435 428 436 $show_admin_role = $ this->lib->show_admin_role_allowed();437 $roles = $ this->lib->get_all_editable_roles();429 $show_admin_role = $lib->show_admin_role_allowed(); 430 $roles = $lib->get_all_editable_roles(); 438 431 foreach ($roles as $role_id => $role) { 439 432 if (!$show_admin_role && $role_id=='administrator') { 440 433 continue; 441 434 } 435 $selected = ( in_array( $role_id, $other_roles ) ) ? 'checked="checked"': ''; 442 436 $role_name = $use_pll ? pll__( $role['name'] ) : $role['name']; 443 437 echo '<label for="wp_role_' . $role_id . '"><input type="checkbox" id="wp_role_' . $role_id . 444 '" name="ure_roles[]" value="' . $role_id . '" /> ' .438 '" name="ure_roles[]" value="' . $role_id . '" '. $selected .'/> ' . 445 439 esc_html( $role_name ) .' ('. $role_id .')</label><br />'. PHP_EOL; 446 440 } … … 451 445 // end of select_other_roles_html() 452 446 447 448 public static function get_dialog_html() { 449 450 if ( !current_user_can('promote_users') ) { 451 $answer = array('result'=>'error', 'message'=>esc_html__('Not enough permissions', 'user-role-editor')); 452 return $answer; 453 } 454 455 $lib = URE_Lib::get_instance(); 456 $user_id = $lib->get_request_var('user_id', 'post', 'int'); 457 $data = self::get_user_roles( $user_id ); 458 ob_start(); 459 self::select_primary_role_html( $data['primary_role'] ); 460 self::select_other_roles_html( $data['other_roles'] ); 461 $output = ob_get_clean(); 462 $answer = array('result'=>'success', 'message'=>'Grant roles dialog HTML', 'html'=>$output ); 463 464 return $answer; 465 } 466 // end of get_dialog_html() 467 453 468 454 469 private function get_roles_options_list() { … … 461 476 } 462 477 // end of get_roles_options_list() 463 464 465 public function show_roles_manage_html( ) {478 479 480 public function show_roles_manage_html( $which ) { 466 481 467 482 if ( !current_user_can( 'promote_users' ) ) { 468 483 return; 469 484 } 470 $button_number = (self::$counter>0) ? '_2': ''; 485 $button_number = ( $which==='bottom') ? '_2': ''; 486 // escaped for secure output already 471 487 $roles_options_list = self::get_roles_options_list(); 488 ob_start(); 472 489 ?> 473 490 … … 493 510 494 511 <?php 495 if (self::$counter==0) {512 if ( $which==='bottom' ) { 496 513 ?> 497 514 <div id="ure_grant_roles_dialog" class="ure-dialog"> 498 <div id="ure_grant_roles_content"> 499 <?php 500 $this->select_primary_role_html(); 501 $this->select_other_roles_html(); 502 ?> 503 </div> 515 <div id="ure_grant_roles_container"></div> 504 516 </div> 505 517 <?php 506 URE_View::output_task_status_div();507 self::$counter++;508 }509 518 URE_View::output_task_status_div(); 519 } 520 $output = ob_get_clean(); 521 echo $output; 510 522 } 511 523 // end of show_grant_roles_html() -
user-role-editor/trunk/includes/classes/settings.php
r2715703 r3407477 20 20 'ure_default_roles_update', 21 21 'ure_settings_tools_exec'); 22 foreach( $update_buttons as $update_button) {23 if ( !isset($_POST[$update_button])) {22 foreach( $update_buttons as $update_button ) { 23 if ( !isset( $_POST[$update_button] ) ) { 24 24 continue; 25 25 } 26 if ( !wp_verify_nonce($_POST['_wpnonce'], 'user-role-editor')) {26 if ( !wp_verify_nonce($_POST['_wpnonce'], 'user-role-editor') ) { 27 27 wp_die('Security check failed'); 28 28 } … … 203 203 echo '<label for="wp_role_' . $role_id .'"><input type="checkbox" id="wp_role_' . $role_id . 204 204 '" name="wp_role_' . $role_id . '" value="' . $role_id . '"' . $checked .' /> ' . 205 $role['name']. '</label><br />';205 esc_html( $role['name'] ) . '</label><br />'; 206 206 } 207 207 -
user-role-editor/trunk/includes/classes/tools.php
r2649770 r3407477 42 42 <input type="hidden" name="ure_settings_tools_exec" value="1" /> 43 43 <input type="hidden" name="ure_reset_roles_exec" value="1" /> 44 <input type="hidden" name="ure_tab_idx" value="<?php echo $tab_idx; ?>" />44 <input type="hidden" name="ure_tab_idx" value="<?php echo (int) $tab_idx; ?>" /> 45 45 </form> 46 46 </div> -
user-role-editor/trunk/includes/classes/user-view.php
r3201795 r3407477 63 63 $anchor_end = ''; 64 64 } 65 $user_info = ' <span style="font-weight: bold;">' . $anchor_start . $this->user_to_edit->user_login;65 $user_info = ' <span style="font-weight: bold;">' . $anchor_start . esc_html( $this->user_to_edit->user_login ); 66 66 if ($this->user_to_edit->display_name !== $this->user_to_edit->user_login) { 67 $user_info .= ' (' . $this->user_to_edit->display_name .')';67 $user_info .= ' ('. esc_html( $this->user_to_edit->display_name ) .')'; 68 68 } 69 69 $user_info .= $anchor_end . '</span>'; … … 189 189 $bbp_user_role = bbp_get_user_role($this->user_to_edit->ID); 190 190 if (!empty($bbp_user_role)) { 191 echo $dynamic_roles[$bbp_user_role]['name'];191 echo esc_html( $dynamic_roles[$bbp_user_role]['name'] ); 192 192 } 193 193 } -
user-role-editor/trunk/includes/settings-template.php
r2878948 r3407477 50 50 <div id="ure_tabs-1"> 51 51 <div id="ure-settings-form"> 52 <form method="post" action="<?php echo $link; ?>?page=settings-<?php echo URE_PLUGIN_FILE; ?>" >52 <form method="post" action="<?php echo esc_url( $link ); ?>?page=settings-<?php echo URE_PLUGIN_FILE; ?>" > 53 53 <table id="ure_settings"> 54 54 <?php … … 131 131 132 132 <div id="ure_tabs-2"> 133 <form name="ure_additional_modules" method="post" action="<?php echo $link; ?>?page=settings-<?php echo URE_PLUGIN_FILE; ?>" >133 <form name="ure_additional_modules" method="post" action="<?php echo esc_url( $link ); ?>?page=settings-<?php echo URE_PLUGIN_FILE; ?>" > 134 134 <table id="ure_addons"> 135 135 <?php … … 163 163 164 164 <div id="ure_tabs-3"> 165 <form name="ure_default_roles" method="post" action="<?php echo $link; ?>?page=settings-<?php echo URE_PLUGIN_FILE; ?>" >165 <form name="ure_default_roles" method="post" action="<?php echo esc_url( $link ); ?>?page=settings-<?php echo URE_PLUGIN_FILE; ?>" > 166 166 <?php 167 167 if ( ! $multisite ) { 168 168 esc_html_e( 'Primary default role: ', 'user-role-editor' ); 169 // User input is not used - ignore Plugin Check warning 169 170 echo $view->role_default_html; 170 171 ?> … … 184 185 <hr> 185 186 <?php wp_nonce_field( 'user-role-editor' ); ?> 186 <input type="hidden" name="ure_tab_idx" value="<?php echo $tabs_index[3]; ?>" />187 <input type="hidden" name="ure_tab_idx" value="<?php echo (int) $tabs_index[3]; ?>" /> 187 188 <p class="submit"> 188 189 <input type="submit" class="button-primary" name="ure_default_roles_update" value="<?php esc_html_e( 'Save', 'user-role-editor' ) ?>" /> … … 196 197 <div id="ure_tabs-4"> 197 198 <div id="ure-settings-form-ms"> 198 <form name="ure_settings_ms" method="post" action="<?php echo $link; ?>?page=settings-<?php echo URE_PLUGIN_FILE; ?>" >199 <form name="ure_settings_ms" method="post" action="<?php echo esc_url( $link ); ?>?page=settings-<?php echo URE_PLUGIN_FILE; ?>" > 199 200 <table id="ure_settings_ms"> 200 201 <?php … … 216 217 </table> 217 218 <?php wp_nonce_field( 'user-role-editor' ); ?> 218 <input type="hidden" name="ure_tab_idx" value="<?php echo $tabs_index[4]; ?>" />219 <input type="hidden" name="ure_tab_idx" value="<?php echo (int) $tabs_index[4]; ?>" /> 219 220 <p class="submit"> 220 221 <input type="submit" class="button-primary" name="ure_settings_ms_update" value="<?php esc_html_e( 'Save', 'user-role-editor' ); ?>" /> … … 251 252 if ($ure_tab_idx>0 && $ure_tab_idx<=count($tabs_index)) { 252 253 ?> 253 $('#ure_tabs').tabs('option', 'active', <?php echo $ure_tab_idx; ?>);254 $('#ure_tabs').tabs('option', 'active', <?php echo (int) $ure_tab_idx; ?>); 254 255 <?php 255 256 } -
user-role-editor/trunk/js/users-grant-roles.js
r3208188 r3407477 41 41 42 42 43 function ure_show_grant_roles_dialog_pre_selected(response) { 44 jQuery('#ure_task_status').hide(); 45 if (response!==null && response.result=='error') { 46 alert(response.message); 47 return; 48 } 49 if (response.primary_role!==null && response.primary_role.length>0 && jQuery('#primary_role').length>0) { 50 jQuery('#primary_role').val(response.primary_role); 51 } 52 53 if (response.other_roles!==null && response.other_roles.length>0) { 54 for(i=0;i<response.other_roles.length;i++) { 55 jQuery('#wp_role_'+ response.other_roles[i]).prop('checked', true); 56 } 57 } 58 59 ure_show_grant_roles_dialog(); 60 61 } 62 63 64 function ure_get_selected_user_roles(users) { 43 function ure_grant_roles() { 44 45 var primary_role = jQuery('#primary_role').val(); 46 var other_roles = ure_get_selected_checkboxes('ure_roles'); 65 47 jQuery('#ure_task_status').show(); 66 var user _id = users.shift();48 var users = ure_get_selected_checkboxes('users'); 67 49 var data = { 68 50 'action': 'ure_ajax', 69 'sub_action':'get_user_roles', 70 'user_id': user_id, 71 'wp_nonce': ure_users_grant_roles_data.wp_nonce}; 72 jQuery.post(ajaxurl, data, ure_show_grant_roles_dialog_pre_selected, 'json'); 73 } 74 75 76 function ure_unselect_roles() { 77 jQuery('#primary_role').val([]); 78 79 // uncheck all checked checkboxes if there are any 80 jQuery('input[type="checkbox"][name="ure_roles\\[\\]"]:checked').map(function() { 81 this.checked = false; 82 }); 83 } 84 85 function ure_prepare_grant_roles_dialog() { 86 var users = ure_get_selected_checkboxes('users'); 87 if (users.length==0) { 88 alert(ure_users_grant_roles_data.select_users_first); 89 return; 90 } 91 92 if (users.length==1) { 93 ure_get_selected_user_roles(users); 94 } else { 95 ure_unselect_roles(); 96 ure_show_grant_roles_dialog(); 97 } 98 99 } 100 101 102 function ure_show_grant_roles_dialog() { 51 'sub_action':'grant_roles', 52 'users': users, 53 'primary_role': primary_role, 54 'other_roles': other_roles, 55 'wp_nonce': ure_users_grant_roles_data.wp_nonce 56 }; 57 jQuery.post(ajaxurl, data, ure_page_reload, 'json'); 58 59 return true; 60 } 61 62 63 function ure_show_grant_roles_dialog( data ) { 103 64 104 65 jQuery('#ure_grant_roles_dialog').dialog({ … … 116 77 jQuery(this).dialog('close'); 117 78 return true; 118 },79 }, 119 80 Cancel: function () { 120 81 jQuery(this).dialog('close'); 121 82 return false; 83 } 122 84 } 123 } 124 }); 125 } 126 127 128 function ure_grant_roles() { 129 var primary_role = jQuery('#primary_role').val(); 130 var other_roles = ure_get_selected_checkboxes('ure_roles'); 131 jQuery('#ure_task_status').show(); 132 var users = ure_get_selected_checkboxes('users'); 133 var data = { 134 'action': 'ure_ajax', 135 'sub_action':'grant_roles', 136 'users': users, 137 'primary_role': primary_role, 138 'other_roles': other_roles, 139 'wp_nonce': ure_users_grant_roles_data.wp_nonce 140 }; 141 jQuery.post(ajaxurl, data, ure_page_reload, 'json'); 142 143 return true; 85 }); 86 jQuery('#ure_grant_roles_container').html( data.html ); 87 88 } 89 90 91 function ure_get_user_roles_markup( user_id ) { 92 jQuery.ajax({ 93 url: ajaxurl, 94 type: 'POST', 95 dataType: 'html', 96 data: { 97 action: 'ure_ajax', 98 sub_action: 'get_grant_roles', 99 user_id : user_id, 100 wp_nonce: ure_users_grant_roles_data.wp_nonce 101 }, 102 success: function(response) { 103 var data = jQuery.parseJSON( response ); 104 if (typeof data.result !== 'undefined') { 105 if (data.result === 'success') { 106 ure_show_grant_roles_dialog( data ); 107 } else if (data.result === 'failure') { 108 alert(data.message); 109 } else { 110 alert('Wrong response: ' + response) 111 } 112 } else { 113 alert('Wrong response: ' + response) 114 } 115 }, 116 error: function(XMLHttpRequest, textStatus, exception) { 117 alert("Ajax failure\n" + XMLHttpRequest.statusText); 118 }, 119 async: true 120 }); 121 } 122 123 124 function ure_prepare_grant_roles_dialog() { 125 var users = ure_get_selected_checkboxes('users'); 126 if ( users.length===0 ) { 127 alert(ure_users_grant_roles_data.select_users_first); 128 return; 129 } 130 var user_id = ( users.length===1) ? users[0] : 0; 131 ure_get_user_roles_markup( user_id ); 144 132 } 145 133 -
user-role-editor/trunk/readme.txt
r3274692 r3407477 3 3 Tags: user, role, editor, security, access 4 4 Requires at least: 4.4 5 Tested up to: 6. 85 Tested up to: 6.9 6 6 Stable tag: 4.64.5 7 7 Requires PHP: 7.3 … … 82 82 83 83 == Changelog = 84 85 = [4.64.6] 01.12.2025 = 86 * Update: Marked as compatible with WordPress 6.9 87 * Update: Minor code enhancements according to the "Plugin Check" tool recommendations. 88 * Update: "Users->Grant Roles" HTML code download optimization to exclude cases when URE's "Grant Roles" data flickers or stays visible while Users page is opening. 89 84 90 = [4.64.5] 16.04.2025 = 85 91 * Update: Marked as compatible with WordPress 6.8 86 92 * Update: Minor changes were applied to the CSS/JS loading code to minimize "Plugin Check" tool warnings. 87 93 * Plugin headers were extended at role-editor.php and readme.txt files according to wordpress.org recommendations. 88 89 = [4.64.4] 15.12.2024 =90 * Security Fix: Users - "Add Role", "Revoke Role" buttons: Cross-Site request forgery to privilege escalation was possible due to missed nonce validation. This issue was discovered and responsibly reported by vgo0.91 94 92 95 File changelog.txt contains the full list of changes. … … 100 103 == Upgrade Notice == 101 104 102 = [4.64.5] 16.04.2025 = 103 * Update: Marked as compatible with WordPress 6.8 104 * Update: Minor changes were applied to the CSS/JS loading code to minimize "Plugin Check" tool warnings. 105 = [4.64.6] 01.12.2025 = 106 * Update: Marked as compatible with WordPress 6.9 107 * Update: Minor code enhancements according to the "Plugin Check" tool recommendations. 108 * Update: "Users->Grant Roles" HTML code download optimization to exclude cases when URE's "Grant Roles" data flickers or stays visible while Users page is opening. -
user-role-editor/trunk/user-role-editor.php
r3274620 r3407477 4 4 Plugin URI: https://www.role-editor.com 5 5 Description: Change/add/delete WordPress user roles and capabilities. 6 Version: 4.64. 56 Version: 4.64.6 7 7 Requires at least: 4.4 8 8 Requires PHP: 7.3 … … 34 34 } 35 35 36 define( 'URE_VERSION', '4.64. 5' );36 define( 'URE_VERSION', '4.64.6' ); 37 37 define( 'URE_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 38 38 define( 'URE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
Note: See TracChangeset
for help on using the changeset viewer.