Ticket #17924: Replace_Admin_Role_Dropdown.patch
File Replace_Admin_Role_Dropdown.patch, 9.3 KB (added by , 14 years ago) |
---|
-
wp-admin/includes/class-wp-users-list-table.php
72 72 'total_items' => $wp_user_search->get_total(), 73 73 'per_page' => $users_per_page, 74 74 ) ); 75 76 add_filter( 'user_role_name', array( &$this, 'wp_user_role_name' ), 1, 2 ); 75 77 } 76 78 77 79 function no_items() { … … 140 142 ?> 141 143 <div class="alignleft actions"> 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 submit_button( __( 'Change' ), 'secondary', 'changeit', false ); ?> 148 152 </div> 149 153 <?php … … 192 196 193 197 $style = ''; 194 198 foreach ( $this->items as $userid => $user_object ) { 195 $role = reset( $user_object->roles );196 199 197 200 if ( is_multisite() && empty( $role ) ) 198 201 continue; … … 260 263 } else { 261 264 $edit = '<strong>' . $user_object->user_login . '</strong>'; 262 265 } 263 $role_name = isset( $wp_roles->role_names[$role] ) ? translate_user_role( $wp_roles->role_names[$role] ) : __( 'None' ); 266 if ( !isset( $role ) || $role == '' ) 267 $role = $user_object->roles; 268 if ( !is_array($role) ) 269 $role = array( $role ); 270 $role_name = apply_filters( 'user_role_name' , $role, $role ); 264 271 $avatar = get_avatar( $user_object->ID, 32 ); 265 272 266 273 $r = "<tr id='user-$user_object->ID'$style>"; … … 314 321 315 322 return $r; 316 323 } 324 325 /** 326 * Formats the role name for the WP_Users_List table role column. 327 * 328 * @param type string $role the string that is being filtered. 329 * @param type array $roles the array of roles 330 * @return type string 331 */ 332 static function wp_user_role_name( $role, $roles ) { 333 global $wp_roles; 334 return isset( $wp_roles->role_names[$roles[0]] ) ? translate_user_role( $wp_roles->role_names[$roles[0]] ) : __( 'None' ); 335 } 336 317 337 } 318 338 319 339 ?> -
wp-admin/includes/template.php
752 752 753 753 754 754 /** 755 * Print out<option> html elements for role selectors755 * Get the <option> html elements for role selectors 756 756 * 757 757 * @since 2.1.0 758 * @deprecated 3.1.2 this function is deprecated. User wp_user_role_selector instead. 759 * @uses serves as a wrapper for wp_get_dropdown_roles 760 * @param string $selected slug for the role that should be already selected 761 */ 762 function wp_dropdown_roles( $selected = false ) { 763 echo wp_get_dropdown_roles( $selected ); 764 } 765 766 767 /** 768 * Get the <option> html elements for role selectors 758 769 * 770 * @since 3.1.2 771 * 759 772 * @param string $selected slug for the role that should be already selected 773 * @return string 760 774 */ 761 function wp_ dropdown_roles( $selected = false ) {775 function wp_get_dropdown_roles( $selected = false ) { 762 776 $p = ''; 763 777 $r = ''; 764 778 765 779 $editable_roles = get_editable_roles(); 780 781 if ( is_array( $selected ) ) 782 $selected = $selected[0]; 766 783 767 784 foreach ( $editable_roles as $role => $details ) { 768 $name = translate_user_role( $details['name'] );785 $name = translate_user_role( $details['name'] ); 769 786 if ( $selected == $role ) // preselect specified role 770 787 $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>"; 771 788 else 772 789 $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>"; 773 790 } 774 echo$p . $r;791 return $p . $r; 775 792 } 776 793 794 777 795 /** 796 * Print out the dropdown role selector 797 * 798 * selected - (string) The role that is to be selected in the dropdown 799 * name - (string) The html name element of the selector 800 * id - (string) The html id element of the selector 801 * class - (string) The classes to be applied to the selector 802 * no_role - (bool) Whether an option should be shown to select no role 803 * before_list - (string) Html to be inserted after the <select> and 804 * before the first option. 805 * after_list - (string) Html to be inserted after the last <option> and 806 * before </select> 807 * 808 * @since 3.1.2 809 * 810 * @param string $options an array of options for the dropdown 811 */ 812 function wp_user_role_selector( $args = array() ) { 813 $defaults = array( 814 'selected' => false, 815 'name' => 'role', 816 'id' => 'role', 817 'class' => false, 818 'no_role' => true, 819 'before_list' => false, 820 'after_list' => false 821 ); 822 823 $args = wp_parse_args( $args, $defaults ); 824 extract( $args ); 825 826 $p = "<select name='$name' id='$id'" . ( $class ? '' : " class='$class'" ) . '>' . $before_list; 827 $r = ''; 828 829 if ( $no_role ) { 830 if ( $selected ) 831 $r = '<option value="">' . __('— No role for this site —') . '</option>'; 832 else 833 $r = '<option value="" selected="selected">' . __('— No role for this site —') . '</option>'; 834 } 835 836 $r .= '</select>' . $after_list; 837 838 echo apply_filters( 'user_role_selector', $p . wp_get_dropdown_roles( $selected ) . $r, $args ); 839 } 840 841 /** 778 842 * {@internal Missing Short Description}} 779 843 * 780 844 * @since 2.3.0 -
wp-admin/options-general.php
115 115 <tr valign="top"> 116 116 <th scope="row"><label for="default_role"><?php _e('New User Default Role') ?></label></th> 117 117 <td> 118 <select name="default_role" id="default_role"><?php wp_dropdown_roles( get_option('default_role') ); ?></select> 118 <?php wp_user_role_selector( array( 119 'selected' => get_option('default_role'), 120 'name' => 'default_role', 121 'id' => 'default_role', 122 'no_role' => true 123 ) ); ?> 119 124 </td> 120 125 </tr> 121 126 <?php } else { ?> -
wp-admin/user-edit.php
233 233 234 234 <?php if ( !IS_PROFILE_PAGE && !is_network_admin() ) : ?> 235 235 <tr><th><label for="role"><?php _e('Role:') ?></label></th> 236 <td> <select name="role" id="role">236 <td> 237 237 <?php 238 238 // Get the highest/primary role for this user 239 239 // TODO: create a function that does this: wp_get_user_role() 240 240 $user_roles = $profileuser->roles; 241 $user_role = array_shift($user_roles);242 241 243 242 // print the full list of roles with the primary one selected. 244 wp_dropdown_roles($user_role); 245 246 // print the 'no role' option. Make it selected if the user has no role yet. 247 if ( $user_role ) 248 echo '<option value="">' . __('— No role for this site —') . '</option>'; 249 else 250 echo '<option value="" selected="selected">' . __('— No role for this site —') . '</option>'; 243 wp_user_role_selector(array( 244 'selected' => $user_roles 245 )); 251 246 ?> 252 </select> 253 <?php endif; //!IS_PROFILE_PAGE 247 </td> 248 <?php 249 endif; //!IS_PROFILE_PAGE 254 250 255 251 if ( is_multisite() && is_network_admin() && ! IS_PROFILE_PAGE && current_user_can( 'manage_network_options' ) && !isset($super_admins) ) { ?> 256 252 <tr><th><label for="role"><?php _e('Super Admin'); ?></label></th> -
wp-admin/user-new.php
243 243 </tr> 244 244 <tr class="form-field"> 245 245 <th scope="row"><label for="adduser-role"><?php _e('Role'); ?></label></th> 246 <td><select name="role" id="adduser-role"> 247 <?php wp_dropdown_roles( get_option('default_role') ); ?> 248 </select> 246 <td> 247 <?php 248 wp_user_role_selector( array( 249 'selected' => get_option('default_role'), 250 'name' => 'role', 251 'id' => 'adduser-role', 252 'no_role' => false 253 )); 254 ?> 255 249 256 </td> 250 257 </tr> 251 258 <?php if ( is_super_admin() ) { ?> … … 323 330 <?php } // !is_multisite ?> 324 331 <tr class="form-field"> 325 332 <th scope="row"><label for="role"><?php _e('Role'); ?></label></th> 326 <td> <select name="role" id="role">333 <td> 327 334 <?php 328 335 if ( !$new_user_role ) 329 336 $new_user_role = !empty($current_role) ? $current_role : get_option('default_role'); 330 wp_dropdown_roles($new_user_role); 337 wp_user_role_selector(array( 338 'selected' => $new_user_role, 339 'no_role' => false 340 )); 331 341 ?> 332 </select>342 333 343 </td> 334 344 </tr> 335 345 <?php if ( is_multisite() && is_super_admin() ) { ?>