mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-30 20:21:37 +01:00
Better handling of users with no role. Props Mark Jaquith. #2809
git-svn-id: http://svn.automattic.com/wordpress/trunk@3859 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5e7c850484
commit
8310e71be6
@ -103,11 +103,22 @@ if ( !current_user_can('edit_user', $user_id) )
|
||||
<?php
|
||||
// print_r($profileuser);
|
||||
echo '<select name="role">';
|
||||
$role_list = '';
|
||||
$user_has_role = false;
|
||||
foreach($wp_roles->role_names as $role => $name) {
|
||||
$selected = ($profileuser->has_cap($role)) ? ' selected="selected"' : '';
|
||||
echo "<option value=\"{$role}\"{$selected}>{$name}</option>";
|
||||
if ( $profileuser->has_cap($role) ) {
|
||||
$selected = ' selected="selected"';
|
||||
$user_has_role = true;
|
||||
} else {
|
||||
$selected = '';
|
||||
}
|
||||
$role_list .= "<option value=\"{$role}\"{$selected}>{$name}</option>";
|
||||
}
|
||||
echo '</select>';
|
||||
if ( $user_has_role )
|
||||
$role_list .= '<option value="">' . __('— No role for this blog —') . '</option>';
|
||||
else
|
||||
$role_list .= '<option value="" selected="selected">' . __('— No role for this blog —') . '</option>';
|
||||
echo $role_list . '</select>';
|
||||
?></label></p>
|
||||
|
||||
<p><label><?php _e('First name:') ?><br />
|
||||
|
@ -313,7 +313,11 @@ foreach($roleclasses as $role => $roleclass) {
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<?php if ( !empty($role) ) : ?>
|
||||
<th colspan="7" align="left"><h3><?php echo $wp_roles->role_names[$role]; ?></h3></th>
|
||||
<?php else : ?>
|
||||
<th colspan="7" align="left"><h3><em><?php _e('No role for this blog'); ?></h3></th>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
<tr class="thead">
|
||||
<th style="text-align: left"><?php _e('ID') ?></th>
|
||||
|
@ -174,7 +174,7 @@ class WP_User {
|
||||
|
||||
//Build $allcaps from role caps, overlay user's $caps
|
||||
$this->allcaps = array();
|
||||
foreach($this->roles as $role) {
|
||||
foreach( (array) $this->roles as $role) {
|
||||
$role = $wp_roles->get_role($role);
|
||||
$this->allcaps = array_merge($this->allcaps, $role->capabilities);
|
||||
}
|
||||
@ -199,8 +199,12 @@ class WP_User {
|
||||
function set_role($role) {
|
||||
foreach($this->roles as $oldrole)
|
||||
unset($this->caps[$oldrole]);
|
||||
$this->caps[$role] = true;
|
||||
$this->roles = array($role => true);
|
||||
if ( !empty($role) ) {
|
||||
$this->caps[$role] = true;
|
||||
$this->roles = array($role => true);
|
||||
} else {
|
||||
$this->roles = false;
|
||||
}
|
||||
update_usermeta($this->id, $this->cap_key, $this->caps);
|
||||
$this->get_role_caps();
|
||||
$this->update_user_level_from_caps();
|
||||
|
@ -102,7 +102,7 @@ function wp_insert_user($userdata) {
|
||||
update_usermeta( $user_id, 'aim', $aim );
|
||||
update_usermeta( $user_id, 'yim', $yim );
|
||||
|
||||
if ($update && !empty($role)) {
|
||||
if ( $update ) {
|
||||
$user = new WP_User($user_id);
|
||||
$user->set_role($role);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user