File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 103103<?php
104104// print_r($profileuser);
105105echo '<select name="role"> ' ;
106+ $ role_list = '' ;
107+ $ user_has_role = false ;
106108foreach ($ wp_roles ->role_names as $ role => $ name ) {
107- $ selected = ($ profileuser ->has_cap ($ role )) ? ' selected="selected" ' : '' ;
108- echo "<option value= \"{$ role }\"{$ selected }> {$ name }</option> " ;
109+ if ( $ profileuser ->has_cap ($ role ) ) {
110+ $ selected = ' selected="selected" ' ;
111+ $ user_has_role = true ;
112+ } else {
113+ $ selected = '' ;
114+ }
115+ $ role_list .= "<option value= \"{$ role }\"{$ selected }> {$ name }</option> " ;
109116}
110- echo '</select> ' ;
117+ if ( $ user_has_role )
118+ $ role_list .= '<option value=""> ' . __ ('— No role for this blog — ' ) . '</option> ' ;
119+ else
120+ $ role_list .= '<option value="" selected="selected"> ' . __ ('— No role for this blog — ' ) . '</option> ' ;
121+ echo $ role_list . '</select> ' ;
111122?> </label></p>
112123
113124<p><label><?php _e ('First name: ' ) ?> <br />
Original file line number Diff line number Diff line change 313313?>
314314
315315<tr>
316+ <?php if ( !empty ($ role ) ) : ?>
316317 <th colspan="7" align="left"><h3><?php echo $ wp_roles ->role_names [$ role ]; ?> </h3></th>
318+ <?php else : ?>
319+ <th colspan="7" align="left"><h3><em><?php _e ('No role for this blog ' ); ?> </h3></th>
320+ <?php endif ; ?>
317321</tr>
318322<tr class="thead">
319323 <th style="text-align: left"><?php _e ('ID ' ) ?> </th>
Original file line number Diff line number Diff line change @@ -174,7 +174,7 @@ function get_role_caps() {
174174
175175 //Build $allcaps from role caps, overlay user's $caps
176176 $ this ->allcaps = array ();
177- foreach ($ this ->roles as $ role ) {
177+ foreach ( ( array ) $ this ->roles as $ role ) {
178178 $ role = $ wp_roles ->get_role ($ role );
179179 $ this ->allcaps = array_merge ($ this ->allcaps , $ role ->capabilities );
180180 }
@@ -199,8 +199,12 @@ function remove_role($role) {
199199 function set_role ($ role ) {
200200 foreach ($ this ->roles as $ oldrole )
201201 unset($ this ->caps [$ oldrole ]);
202- $ this ->caps [$ role ] = true ;
203- $ this ->roles = array ($ role => true );
202+ if ( !empty ($ role ) ) {
203+ $ this ->caps [$ role ] = true ;
204+ $ this ->roles = array ($ role => true );
205+ } else {
206+ $ this ->roles = false ;
207+ }
204208 update_usermeta ($ this ->id , $ this ->cap_key , $ this ->caps );
205209 $ this ->get_role_caps ();
206210 $ this ->update_user_level_from_caps ();
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ function wp_insert_user($userdata) {
102102 update_usermeta ( $ user_id , 'aim ' , $ aim );
103103 update_usermeta ( $ user_id , 'yim ' , $ yim );
104104
105- if ($ update && ! empty ( $ role ) ) {
105+ if ( $ update ) {
106106 $ user = new WP_User ($ user_id );
107107 $ user ->set_role ($ role );
108108 }
You can’t perform that action at this time.
0 commit comments