AJAXify user addition. Props mdawaffe. fixes #2624

git-svn-id: https://develop.svn.wordpress.org/trunk@3677 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2006-04-02 00:31:26 +00:00
parent e622346b7d
commit b3206083c3
9 changed files with 142 additions and 91 deletions
+36 -53
View File
@@ -79,7 +79,7 @@ case 'delete':
}
if ( !current_user_can('edit_users') )
$error['edit_users'] = __('You can’t delete users.');
$error = new WP_Error('edit_users', __('You can’t delete users.'));
$userids = $_POST['users'];
@@ -133,15 +133,19 @@ break;
case 'adduser':
check_admin_referer();
$errors = add_user();
if(count($errors) == 0) {
$user_id = add_user();
if ( is_wp_error( $user_id ) )
$errors = $user_id;
else {
header('Location: users.php?update=add');
die();
}
default:
$list_js = true;
$users_js = true;
include ('admin-header.php');
$userids = $wpdb->get_col("SELECT ID FROM $wpdb->users;");
@@ -187,11 +191,13 @@ default:
break;
}
endif;
if ( isset($errors) ) : ?>
if ( is_wp_error( $errors ) ) : ?>
<div class="error">
<ul>
<?php
foreach($errors as $error) echo "<li>$error</li>";
foreach( $errors->get_error_codes() as $code)
foreach( $errors->get_error_messages($code) as $message )
echo "<li>$message</li>";
?>
</ul>
</div>
@@ -209,51 +215,27 @@ default:
?>
<tr>
<th colspan="8" align="left">
<h3><?php echo $wp_roles->role_names[$role]; ?></h3>
</th></tr>
<tr>
<th><?php _e('ID') ?></th>
<th><?php _e('Username') ?></th>
<th><?php _e('Name') ?></th>
<th><?php _e('E-mail') ?></th>
<th><?php _e('Website') ?></th>
<th><?php _e('Posts') ?></th>
<th>&nbsp;</th>
<th colspan="8" align="left"><h3><?php echo $wp_roles->role_names[$role]; ?></h3></th>
</tr>
<?php
<tr>
<th><?php _e('ID') ?></th>
<th><?php _e('Username') ?></th>
<th><?php _e('Name') ?></th>
<th><?php _e('E-mail') ?></th>
<th><?php _e('Website') ?></th>
<th><?php _e('Posts') ?></th>
<th>&nbsp;</th>
</tr>
<tbody id="role-<?php echo $role; ?>"><?php
$style = '';
foreach ($roleclass as $user_object) {
$email = $user_object->user_email;
$url = $user_object->user_url;
$short_url = str_replace('http://', '', $url);
$short_url = str_replace('www.', '', $short_url);
if ('/' == substr($short_url, -1))
$short_url = substr($short_url, 0, -1);
if (strlen($short_url) > 35)
$short_url = substr($short_url, 0, 32).'...';
$style = ('class="alternate"' == $style) ? '' : 'class="alternate"';
$numposts = get_usernumposts($user_object->ID);
if (0 < $numposts) $numposts = "<a href='edit.php?author=$user_object->ID' title='" . __('View posts') . "'>$numposts</a>";
echo "
<tr $style>
<td><input type='checkbox' name='users[]' id='user_{$user_object->ID}' value='{$user_object->ID}' /> <label for='user_{$user_object->ID}'>{$user_object->ID}</label></td>
<td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td>
<td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td>
<td><a href='mailto:$email' title='" . sprintf(__('e-mail: %s'), $email) . "'>$email</a></td>
<td><a href='$url' title='website: $url'>$short_url</a></td>";
echo "<td align='right'>$numposts</td>";
echo '<td>';
if (current_user_can('edit_users'))
echo "<a href='user-edit.php?user_id=$user_object->ID' class='edit'>".__('Edit')."</a>";
echo '</td>';
echo '</tr>';
$style = (' class="alternate"' == $style) ? '' : ' class="alternate"';
echo "\n\t" . user_row( $user_object, $style );
}
?>
</tbody>
<?php
}
?>
@@ -261,16 +243,12 @@ default:
<h2><?php _e('Update Users'); ?></h2>
<?php
$role_select = '<select name="new_role">';
foreach($wp_roles->role_names as $role => $name) {
$role_select .= "<option value=\"{$role}\">{$name}</option>";
}
$role_select .= '</select>';
?>
<ul style="list-style:none;">
<li><input type="radio" name="action" id="action0" value="delete" /> <label for="action0"><?php _e('Delete checked users.'); ?></label></li>
<li><input type="radio" name="action" id="action1" value="promote" /> <?php echo '<label for="action1">'.__('Set the Role of checked users to:')."</label> $role_select"; ?></li>
<li>
<input type="radio" name="action" id="action1" value="promote" /> <label for="action1"><?php _e('Set the Role of checked users to:'); ?></label>
<select name="new_role"><?php wp_dropdown_roles(); ?></select>
</li>
</ul>
<p class="submit"><input type="submit" value="<?php _e('Update &raquo;'); ?>" /></p>
</div>
@@ -313,11 +291,16 @@ if ( $show_password_fields ) :
<input name="pass2" type="password" id="pass2" /></td>
</tr>
<?php endif; ?>
<tr>
<th scope="row"><?php _e('Role'); ?></th>
<td><select name="role" id="role"><?php wp_dropdown_roles( get_settings('default_role') ); ?></select></td>
</tr>
</table>
<p class="submit">
<input name="adduser" type="submit" id="adduser" value="<?php _e('Add User &raquo;') ?>" />
<input name="adduser" type="submit" id="addusersub" value="<?php _e('Add User &raquo;') ?>" />
</p>
</form>
<div id="ajax-response"></div>
</div>
<?php