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