Better handling of users with no role. Props Mark Jaquith. #2809

git-svn-id: https://develop.svn.wordpress.org/trunk@3859 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2006-06-10 20:26:26 +00:00
parent a4c408af37
commit 1053ca7014
4 changed files with 26 additions and 7 deletions

View File

@ -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="">' . __('&mdash; No role for this blog &mdash;') . '</option>';
else
$role_list .= '<option value="" selected="selected">' . __('&mdash; No role for this blog &mdash;') . '</option>';
echo $role_list . '</select>';
?></label></p>
<p><label><?php _e('First name:') ?><br />

View File

@ -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>

View File

@ -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();

View File

@ -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);
}