summaryrefslogtreecommitdiffstats
path: root/wp-inst/wp-admin/user-edit.php
blob: adac5a04166bb89e790413fd478988462efbe293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
require_once('admin.php');

$title = __('Edit User');
$parent_file = 'profile.php';	
$submenu_file = 'users.php';

$wpvarstoreset = array('action', 'redirect', 'profile', 'user_id');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
	$wpvar = $wpvarstoreset[$i];
	if (!isset($$wpvar)) {
		if (empty($_POST["$wpvar"])) {
			if (empty($_GET["$wpvar"])) {
				$$wpvar = '';
			} else {
				$$wpvar = $_GET["$wpvar"];
			}
		} else {
			$$wpvar = $_POST["$wpvar"];
		}
	}
}

switch ($action) {
case 'update':

get_currentuserinfo();
$edituser = get_userdata($user_id);
if ($edituser->user_level >= $user_level) die( __('You do not have permission to edit this user.') );

/* checking the nickname has been typed */
if (empty($_POST["new_nickname"])) {
	die (__("<strong>ERROR</strong>: please enter your nickname (can be the same as your username)"));
	return false;
}

$new_user_login  = wp_specialchars($_POST['new_user_login']);
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
do_action('check_passwords', array($new_user_login, &$pass1, &$pass2));

if ( '' == $pass1 ) {
	if ( '' != $pass2 )
		die (__("<strong>ERROR</strong>: you typed your new password only once. Go back to type it twice."));
	$updatepassword = '';
} else {
	if ( '' == $pass2)
		die (__("<strong>ERROR</strong>: you typed your new password only once. Go back to type it twice."));
	if ( $pass1 != $pass2 )
		die (__("<strong>ERROR</strong>: you typed two different passwords. Go back to correct that."));
	$new_pass = $pass1;
	$updatepassword = "user_pass=MD5('$new_pass'), ";
}

$new_firstname   = wp_specialchars($_POST['new_firstname']);
$new_lastname    = wp_specialchars($_POST['new_lastname']);
$new_nickname    = $_POST['new_nickname'];
$new_nicename    = sanitize_title($new_nickname, $user_id);
$new_icq         = wp_specialchars($_POST['new_icq']);
$new_aim         = wp_specialchars($_POST['new_aim']);
$new_msn         = wp_specialchars($_POST['new_msn']);
$new_yim         = wp_specialchars($_POST['new_yim']);
$new_email       = wp_specialchars($_POST['new_email']);
$new_url         = wp_specialchars($_POST['new_url']);
$new_url         = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $new_url) ? $new_url : 'http://' . $new_url; 
$display_name    = wp_specialchars($_POST['display_name']);
$new_description = $_POST['new_description'];

$result = $wpdb->query("UPDATE $wpdb->users SET user_login = '$new_user_login', $updatepassword user_email='$new_email', user_url='$new_url', user_nicename = '$new_nicename', display_name = '$display_name' WHERE ID = '$user_id'");

update_usermeta( $user_id, 'first_name', $new_firstname );
update_usermeta( $user_id, 'last_name', $new_lastname );
update_usermeta( $user_id, 'nickname', $new_nickname );
update_usermeta( $user_id, 'description', $new_description );
update_usermeta( $user_id, 'icq', $new_icq );
update_usermeta( $user_id, 'aim', $new_aim );
update_usermeta( $user_id, 'msn', $new_msn );
update_usermeta( $user_id, 'yim', $new_yim );

header("Location: user-edit.php?user_id=$user_id&updated=true");

break;

case 'switchposts':

check_admin_referer();

/* TODO: Switch all posts from one user to another user */

break;

default:
include ('admin-header.php');

$edituser = get_userdata($user_id);

if ($edituser->user_level >= $user_level) die( __('You do not have permission to edit this user.') );
?>

<?php if ( isset($_GET['updated']) ) : ?>
<div class="updated">
	<p><strong><?php _e('User updated.') ?></strong></p>
</div>
<?php endif; ?>

<div class="wrap">
<h2><?php _e('Edit User'); ?></h2>
<form name="edituser" id="edituser" action="user-edit.php" method="post">
<table width="99%"  border="0" cellspacing="2" cellpadding="3">
	<tr>
		<th width="33%" scope="row"><?php _e('Username:') ?></th>
		<td width="73%"><input type="text" name="new_user_login" id="new_user_login" value="<?php echo $edituser->user_login; ?>" /></td>
	</tr>
	<tr>
		<th scope="row"><?php _e('Level:') ?></th>
		<td><?php echo $edituser->user_level; ?></td>
	</tr>
	<tr>
		<th scope="row"><?php _e('Posts:') ?></th>
		<td><?php echo get_usernumposts($edituser->ID); ?></td>
	</tr>
<?php if ( '0000-00-00 00:00:00' != $edituser->user_registered ) { ?>
	<tr>
		<th scope="row"><?php _e('Registered on:') ?></th>
		<td><?php echo substr($edituser->user_registered, 0, 11); ?></td>
	</tr>
<?php } ?>
	<tr>
		<th scope="row"><?php _e('First name:') ?></th>
		<td><input type="text" name="new_firstname" id="new_firstname" value="<?php echo $edituser->first_name ?>" /></td>
	</tr>
	<tr>
		<th scope="row"><?php _e('Last name:') ?></th>
		<td><input type="text" name="new_lastname" id="new_lastname2" value="<?php echo $edituser->last_name ?>" /></td>
	</tr>
	<tr>
		<th scope="row"><?php _e('Profile:') ?></th>
		<td><textarea name="new_description" rows="5" id="new_description" style="width: 99%; "><?php echo $edituser->user_description ?></textarea></td>
	</tr>
	<tr>
		<th scope="row"><?php _e('Nickname:') ?></th>
		<td><input type="text" name="new_nickname" id="new_nickname" value="<?php echo $edituser->nickname ?>" /></td>
	</tr>
	<tr>
		<th scope="row"><?php _e('E-mail:') ?></th>
		<td><input type="text" name="new_email" id="new_email" value="<?php echo $edituser->user_email ?>" /></td>
	</tr>
	<tr>
		<th scope="row"><?php _e('Website:') ?></th>
		<td><input type="text" name="new_url" id="new_url" value="<?php echo $edituser->user_url ?>" /></td>
	</tr>
	<tr>
		<th scope="row"><?php _e('ICQ:') ?></th>
		<td><input type="text" name="new_icq" id="new_icq" value="<?php if ($edituser->icq > 0) { echo $edituser->icq; } ?>" /></td>
	</tr>
	<tr>
		<th scope="row"><?php _e('AIM:') ?></th>
		<td><input type="text" name="new_aim" id="new_aim" value="<?php echo $edituser->aim ?>" /></td>
	</tr>
	<tr>
		<th scope="row"><?php _e('MSN IM:') ?>
		</th>
		<td><input type="text" name="new_msn" id="new_msn" value="<?php echo $edituser->msn ?>" /></td>
	</tr>
	<tr>
		<th scope="row"><?php _e('Yahoo IM:') ?>
		</th>
		<td><input type="text" name="new_yim" id="new_yim" value="<?php echo $edituser->yim ?>" />
		</td>
	</tr>
	<tr>
		<th scope="row"><?php _e('Identity on blog:') ?>
		</th>
		<td>	<select name="display_name">
		<option value="<?php echo $edituser->display_name; ?>"><?php echo $edituser->display_name; ?></option>
        <option value="<?php echo $edituser->nickname ?>"><?php echo $edituser->nickname ?></option>
        <option value="<?php echo $edituser->user_login ?>"><?php echo $edituser->user_login ?></option>
	<?php if ( !empty( $edituser->first_name ) ) : ?>
        <option value="<?php echo $edituser->first_name ?>"><?php echo $edituser->first_name ?></option>
	<?php endif; ?>
	<?php if ( !empty( $edituser->last_name ) ) : ?>
        <option value="<?php echo $edituser->last_name ?>"><?php echo $edituser->last_name ?></option>
	<?php endif; ?>
	<?php if ( !empty( $edituser->first_name ) && !empty( $edituser->last_name ) ) : ?>
        <option value="<?php echo $edituser->first_name." ".$edituser->last_name ?>"><?php echo $edituser->first_name." ".$edituser->last_name ?></option>
        <option value="<?php echo $edituser->last_name." ".$edituser->first_name ?>"><?php echo $edituser->last_name." ".$edituser->first_name ?></option>
	<?php endif; ?>
      </select>
		</td>
	</tr>
<?php
$show_password_fields = apply_filters('show_password_fields', true);
if ( $show_password_fields ) :
?>
	<tr>
		<th scope="row"><?php _e('New <strong>Password</strong> (Leave blank to stay the same.)') ?></th>
		<td><input type="password" name="pass1" size="16" value="" />
			<br />
			<input type="password" name="pass2" size="16" value="" /></td>
	</tr>
<?php endif; ?>
</table>
  <p class="submit">
	<input type="hidden" name="action" value="update" />
	<input type="hidden" name="user_id" id="user_id" value="<?php echo $user_id; ?>" />
    <input type="submit" value="<?php _e('Update User &raquo;') ?>" name="submit" />
  </p>
</form>
</div>

<?php
break;
}

include('admin-footer.php');
?>