Ticket #17924: wp-3.6-alpha-multi-role-diff.patch
File wp-3.6-alpha-multi-role-diff.patch, 13.2 KB (added by , 12 years ago) |
---|
-
wp-admin/includes/class-wp-users-list-table.php
73 73 'total_items' => $wp_user_search->get_total(), 74 74 'per_page' => $users_per_page, 75 75 ) ); 76 77 add_filter( 'user_role_name', array( &$this, 'wp_user_role_name' ), 1, 2 ); 76 78 } 77 79 78 80 function no_items() { … … 140 142 <div class="alignleft actions"> 141 143 <?php if ( current_user_can( 'promote_users' ) ) : ?> 142 144 <label class="screen-reader-text" for="new_role"><?php _e( 'Change role to…' ) ?></label> 143 <select name="new_role" id="new_role"> 144 <option value=''><?php _e( 'Change role to…' ) ?></option> 145 <?php wp_dropdown_roles(); ?> 146 </select> 145 <?php wp_user_role_selector(array( 146 'name' => 'new_role', 147 'id' => 'new_role', 148 'no_role' => false, 149 'before_list' => '<option value="" selected="true">' . __( 'Change role to…' ) . '</option>' 150 )) ?> 147 151 <?php 148 152 submit_button( __( 'Change' ), 'button', 'changeit', false ); 149 153 endif; … … 197 201 198 202 $style = ''; 199 203 foreach ( $this->items as $userid => $user_object ) { 200 if ( count( $user_object->roles ) <= 1 ) {201 $role = reset( $user_object->roles );202 } elseif ( $roles = array_intersect( array_values( $user_object->roles ), $editable_roles ) ) {203 $role = reset( $roles );204 } else {205 $role = reset( $user_object->roles );206 }207 208 204 if ( is_multisite() && empty( $user_object->allcaps ) ) 209 205 continue; 210 206 … … 267 263 } else { 268 264 $edit = '<strong>' . $user_object->user_login . '</strong>'; 269 265 } 270 $role_name = isset( $wp_roles->role_names[$role] ) ? translate_user_role( $wp_roles->role_names[$role] ) : __( 'None' ); 266 267 if ( !isset( $role ) || $role == '' ) 268 $role = $user_object->roles; 269 if ( !is_array($role) ) 270 $role = array( $role ); 271 272 $role_name = apply_filters( 'user_role_name' , $role, $role ); 273 271 274 $avatar = get_avatar( $user_object->ID, 32 ); 272 275 273 276 $r = "<tr id='user-$user_object->ID'$style>"; … … 321 324 322 325 return $r; 323 326 } 327 328 /** 329 * Formats the role name for the WP_Users_List table role column. 330 * 331 * @param type string $role the string that is being filtered. 332 * @param type array $roles the array of roles 333 * @return type string 334 */ 335 static function wp_user_role_name( $role, $roles ) { 336 global $wp_roles; 337 return isset( $wp_roles->role_names[$roles[0]] ) ? translate_user_role( $wp_roles->role_names[$roles[0]] ) : __( 'None' ); 324 338 } 339 } -
wp-admin/includes/template.php
749 749 } 750 750 751 751 /** 752 * Print out<option> html elements for role selectors752 * Get the <option> html elements for role selectors 753 753 * 754 754 * @since 2.1.0 755 * 755 * @deprecated 3.6 this function is deprecated. User wp_user_role_selector instead. 756 * @uses serves as a wrapper for wp_get_dropdown_roles 756 757 * @param string $selected slug for the role that should be already selected 757 758 */ 758 759 function wp_dropdown_roles( $selected = false ) { 760 echo wp_get_dropdown_roles( $selected ); 761 } 762 763 764 /** 765 * Get the <option> html elements for role selectors 766 * 767 * @since 3.6 768 * 769 * @param string $selected slug for the role that should be already selected 770 * @return string 771 */ 772 function wp_get_dropdown_roles( $selected = false ) { 773 759 774 $p = ''; 760 775 $r = ''; 761 776 762 777 $editable_roles = get_editable_roles(); 763 778 764 779 foreach ( $editable_roles as $role => $details ) { 765 $name = translate_user_role($details['name'] ); 766 if ( $selected == $role ) // preselect specified role 780 $name = translate_user_role( $details['name'] ); 781 782 // preselect specified role 783 if ( (is_string($selected) && $selected == $role) || (is_array($selected) && in_array($role, $selected)) ) 767 784 $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>"; 768 785 else 769 786 $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>"; 770 787 } 771 echo $p . $r; 788 789 return $p . $r; 772 790 } 773 791 774 792 /** 793 * Print out the dropdown role selector 794 * 795 * selected - (string) The role that is to be selected in the dropdown 796 * name - (string) The html name element of the selector 797 * id - (string) The html id element of the selector 798 * class - (string) The classes to be applied to the selector 799 * no_role - (bool) Whether an option should be shown to select no role 800 * before_list - (string) Html to be inserted after the <select> and 801 * before the first option. 802 * after_list - (string) Html to be inserted after the last <option> and 803 * before </select> 804 * 805 * @since 3.6 806 * 807 * @param string $options an array of options for the dropdown 808 */ 809 function wp_user_role_selector( $args = array() ) { 810 $defaults = array( 811 'selected' => false, 812 'name' => 'role', 813 'id' => 'role', 814 'class' => false, 815 'no_role' => true, 816 'before_list' => false, 817 'after_list' => false 818 ); 819 820 $args = wp_parse_args( $args, $defaults ); 821 extract( $args ); 822 823 $p = "<select name='$name' id='$id'" . ( $class ? '' : " class='$class'" ) . '>' . $before_list; 824 $r = ''; 825 826 if ( $no_role ) { 827 if ( $selected !== false ) 828 $r = '<option value="">' . __('— No role for this site —') . '</option>'; 829 else 830 $r = '<option value="" selected="selected">' . __('— No role for this site —') . '</option>'; 831 } 832 833 $r .= '</select>' . $after_list; 834 835 echo apply_filters( 'user_role_selector', $p . wp_get_dropdown_roles( $selected ) . $r, $args ); 836 } 837 838 839 /** 775 840 * Outputs the form used by the importers to accept the data to be imported 776 841 * 777 842 * @since 2.0.0 -
wp-admin/includes/user.php
6 6 * @subpackage Administration 7 7 */ 8 8 9 function wp_sanitize_user_role( $role, $user_id ){ 10 global $wp_roles; 11 if ( is_string( $role ) ) { 12 $r = false; 13 $new_role = sanitize_text_field( $role ); 14 $potential_role = isset($wp_roles->role_objects[$new_role]) ? $wp_roles->role_objects[$new_role] : false; 15 // Don't let anyone with 'edit_users' (admins) edit their own role to something without it. 16 // Multisite super admins can freely edit their blog roles -- they possess all caps. 17 if ( ( is_multisite() && current_user_can( 'manage_sites' ) ) || $user_id != get_current_user_id() || ($potential_role && $potential_role->has_cap( 'edit_users' ) ) ) 18 $r = $new_role; 19 20 // If the new role isn't editable by the logged-in user die with error 21 $editable_roles = get_editable_roles(); 22 if ( ! empty( $new_role ) && empty( $editable_roles[$new_role] ) ) 23 wp_die(__('You can’t give users that role.')); 24 25 return $r; 26 } else { 27 //Can't do anything, so return the input 28 return $role; 29 } 30 } 31 9 32 /** 33 * Add the sanitize_user_role filter 34 */ 35 add_filter( 'sanitize_user_role', 'wp_sanitize_user_role', 5, 2 ); 36 37 /** 10 38 * Creates a new user from the "Users" form using $_POST information. 11 39 * 12 40 * @since 2.0 … … 49 77 $pass2 = $_POST['pass2']; 50 78 51 79 if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) { 52 $new_role = sanitize_text_field( $_POST['role'] ); 53 $potential_role = isset($wp_roles->role_objects[$new_role]) ? $wp_roles->role_objects[$new_role] : false; 54 // Don't let anyone with 'edit_users' (admins) edit their own role to something without it. 55 // Multisite super admins can freely edit their blog roles -- they possess all caps. 56 if ( ( is_multisite() && current_user_can( 'manage_sites' ) ) || $user_id != get_current_user_id() || ($potential_role && $potential_role->has_cap( 'edit_users' ) ) ) 57 $user->role = $new_role; 58 59 // If the new role isn't editable by the logged-in user die with error 60 $editable_roles = get_editable_roles(); 61 if ( ! empty( $new_role ) && empty( $editable_roles[$new_role] ) ) 62 wp_die(__('You can’t give users that role.')); 80 $user->role = apply_filters( 'sanitize_user_role', $_POST['role'], $user_id ); 63 81 } 64 82 65 83 if ( isset( $_POST['email'] )) -
wp-admin/options-general.php
125 125 <tr valign="top"> 126 126 <th scope="row"><label for="default_role"><?php _e('New User Default Role') ?></label></th> 127 127 <td> 128 <select name="default_role" id="default_role"><?php wp_dropdown_roles( get_option('default_role') ); ?></select> 128 <?php wp_user_role_selector( array( 129 'selected' => get_option('default_role'), 130 'name' => 'default_role', 131 'id' => 'default_role', 132 'no_role' => true 133 ) ); ?> 129 134 </td> 130 135 </tr> 131 136 <?php } else { ?> -
wp-admin/user-edit.php
247 247 248 248 <?php if ( !IS_PROFILE_PAGE && !is_network_admin() ) : ?> 249 249 <tr><th><label for="role"><?php _e('Role') ?></label></th> 250 <td> <select name="role" id="role">250 <td> 251 251 <?php 252 252 // Compare user role against currently editable roles 253 253 // TODO: create a function that does this: wp_get_user_role() 254 254 $user_roles = array_intersect( array_values( $profileuser->roles ), array_keys( get_editable_roles() ) ); 255 $user_role = array_shift( $user_roles );256 255 257 256 // print the full list of roles with the primary one selected. 258 wp_dropdown_roles($user_role); 259 260 // print the 'no role' option. Make it selected if the user has no role yet. 261 if ( $user_role ) 262 echo '<option value="">' . __('— No role for this site —') . '</option>'; 263 else 264 echo '<option value="" selected="selected">' . __('— No role for this site —') . '</option>'; 257 wp_user_role_selector(array( 258 'selected' => $user_roles 259 )); 265 260 ?> 266 </select></td></tr> 267 <?php endif; //!IS_PROFILE_PAGE 261 </td> 262 <?php 263 endif; //!IS_PROFILE_PAGE 268 264 269 265 if ( is_multisite() && is_network_admin() && ! IS_PROFILE_PAGE && current_user_can( 'manage_network_options' ) && !isset($super_admins) ) { ?> 270 266 <tr><th><?php _e('Super Admin'); ?></th> -
wp-admin/user-new.php
278 278 </tr> 279 279 <tr class="form-field"> 280 280 <th scope="row"><label for="adduser-role"><?php _e('Role'); ?></label></th> 281 <td><select name="role" id="adduser-role"> 282 <?php wp_dropdown_roles( get_option('default_role') ); ?> 283 </select> 281 <td> 282 <?php 283 wp_user_role_selector( array( 284 'selected' => get_option('default_role'), 285 'name' => 'role', 286 'id' => 'adduser-role', 287 'no_role' => false 288 )); 289 ?> 290 284 291 </td> 285 292 </tr> 286 293 <?php if ( is_super_admin() ) { ?> … … 358 365 <?php } // !is_multisite ?> 359 366 <tr class="form-field"> 360 367 <th scope="row"><label for="role"><?php _e('Role'); ?></label></th> 361 <td> <select name="role" id="role">368 <td> 362 369 <?php 363 370 if ( !$new_user_role ) 364 371 $new_user_role = !empty($current_role) ? $current_role : get_option('default_role'); 365 wp_dropdown_roles($new_user_role); 372 wp_user_role_selector(array( 373 'selected' => $new_user_role, 374 'no_role' => false 375 )); 366 376 ?> 367 </select>377 368 378 </td> 369 379 </tr> 370 380 <?php if ( is_multisite() && is_super_admin() ) { ?> -
wp-includes/user.php
1408 1408 } 1409 1409 1410 1410 if ( isset($role) ) 1411 $user->set_role($role);1411 do_action( 'apply_user_role' , apply_filters( 'pre_user_role', $role ), $user ); 1412 1412 elseif ( !$update ) 1413 $user->set_role(get_option('default_role'));1413 do_action( 'apply_user_role' , get_option('default_role'), $user ); 1414 1414 1415 1415 wp_cache_delete($user_id, 'users'); 1416 1416 wp_cache_delete($user_login, 'userlogins'); … … 1424 1424 } 1425 1425 1426 1426 /** 1427 * Hooks into the apply_user_role action to set the users role 1428 * 1429 * @param type $role the role to set 1430 * @param type $user the user to set the role on 1431 */ 1432 function wp_apply_user_role( $role, $user ) { 1433 if ( is_string( $role ) ) { 1434 $user->set_role($role); 1435 } 1436 } 1437 1438 /** 1439 * Register the action for the apply_user_role hook 1440 */ 1441 add_action( 'apply_user_role', 'wp_apply_user_role', 5, 2); 1442 1443 /** 1427 1444 * Update an user in the database. 1428 1445 * 1429 1446 * It is possible to update a user's password by specifying the 'user_pass' 1447 * 1448 * It is possible to update a user's password by specifying the 'user_pass' 1430 1449 * value in the $userdata parameter array. 1431 1450 * 1432 1451 * If $userdata does not contain an 'ID' key, then a new user will be created