mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
User create/update rework. Introduce wp_insert_user(), wp_create_user(), wp_update_user(), add_user(), update_user(), wp_new_user_notification().
git-svn-id: https://develop.svn.wordpress.org/trunk@2872 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
+113
-164
@@ -33,78 +33,22 @@ break;
|
||||
case 'update':
|
||||
|
||||
$errors = array();
|
||||
if(empty($wp_user)) {
|
||||
$wp_user = new WP_User($user_id);
|
||||
$edituser = &$wp_user->data;
|
||||
}
|
||||
|
||||
if (!current_user_can('edit_users')) $errors['head'] = __('You do not have permission to edit this user.');
|
||||
|
||||
/* checking the nickname has been typed */
|
||||
if (empty($_POST["new_nickname"])) {
|
||||
$errors['nickname'] = __("<strong>ERROR</strong>: please enter your nickname (can be the same as your username)");
|
||||
}
|
||||
|
||||
$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 )
|
||||
$errors['pass'] = __("<strong>ERROR</strong>: you typed your new password only once.");
|
||||
$updatepassword = '';
|
||||
} else {
|
||||
if ( '' == $pass2)
|
||||
$errors['pass'] = __("<strong>ERROR</strong>: you typed your new password only once.");
|
||||
if ( $pass1 != $pass2 )
|
||||
$errors['pass'] = __("<strong>ERROR</strong>: you typed two different passwords.");
|
||||
$new_pass = $pass1;
|
||||
$updatepassword = "user_pass=MD5('$new_pass'), ";
|
||||
}
|
||||
|
||||
$edituser->user_login = wp_specialchars($_POST['new_user_login']);
|
||||
$edituser->user_nicename = sanitize_title($new_nickname, $user_id);
|
||||
$edituser->user_email = wp_specialchars($_POST['new_email']);
|
||||
$edituser->user_url = wp_specialchars($_POST['new_url']);
|
||||
$edituser->user_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $edituser->user_url) ? $edituser->user_url : 'http://' . $edituser->user_url;
|
||||
$edituser->display_name = wp_specialchars($_POST['display_name']);
|
||||
|
||||
$edituser->first_name = wp_specialchars($_POST['new_firstname']);
|
||||
$edituser->last_name = wp_specialchars($_POST['new_lastname']);
|
||||
$edituser->nickname = $_POST['new_nickname'];
|
||||
$edituser->icq = wp_specialchars($_POST['new_icq']);
|
||||
$edituser->aim = wp_specialchars($_POST['new_aim']);
|
||||
$edituser->msn = wp_specialchars($_POST['new_msn']);
|
||||
$edituser->yim = wp_specialchars($_POST['new_yim']);
|
||||
$edituser->description = $_POST['new_description'];
|
||||
if (!current_user_can('edit_users'))
|
||||
$errors['head'] = __('You do not have permission to edit this user.');
|
||||
else
|
||||
$errors = update_user($user_id);
|
||||
|
||||
if(count($errors) == 0) {
|
||||
$result = $wpdb->query("UPDATE $wpdb->users SET user_login = '$edituser->user_login', $updatepassword user_email='$edituser->user_email', user_url='$edituser->user_url', user_nicename = '$edituser->user_nicename', display_name = '$edituser->display_name' WHERE ID = '$user_id'");
|
||||
|
||||
update_usermeta( $user_id, 'first_name', $edituser->firstname );
|
||||
update_usermeta( $user_id, 'last_name', $edituser->lastname );
|
||||
update_usermeta( $user_id, 'nickname', $edituser->nickname );
|
||||
update_usermeta( $user_id, 'description', $edituser->description );
|
||||
update_usermeta( $user_id, 'icq', $edituser->icq );
|
||||
update_usermeta( $user_id, 'aim', $edituser->aim );
|
||||
update_usermeta( $user_id, 'msn', $edituser->msn );
|
||||
update_usermeta( $user_id, 'yim', $edituser->yim );
|
||||
|
||||
$wp_user->set_role($_POST['new_role']);
|
||||
|
||||
header("Location: user-edit.php?user_id=$user_id&updated=true");
|
||||
} else {
|
||||
$wp_user->roles = array($_POST['new_role'] => true);
|
||||
exit;
|
||||
}
|
||||
|
||||
default:
|
||||
include ('admin-header.php');
|
||||
|
||||
if(empty($wp_user)) {
|
||||
$wp_user = new WP_User($user_id);
|
||||
$edituser = &$wp_user->data;
|
||||
}
|
||||
$profileuser = new WP_User($user_id);
|
||||
$profiledata = $profileuser->data;
|
||||
|
||||
if (!current_user_can('edit_users')) $errors['head'] = __('You do not have permission to edit this user.');
|
||||
?>
|
||||
@@ -114,7 +58,7 @@ if (!current_user_can('edit_users')) $errors['head'] = __('You do not have permi
|
||||
<p><strong><?php _e('User updated.') ?></strong></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ( isset($errors) ) : ?>
|
||||
<?php if ( count($errors) != 0 ) : ?>
|
||||
<div class="error">
|
||||
<ul>
|
||||
<?php
|
||||
@@ -126,116 +70,121 @@ if (!current_user_can('edit_users')) $errors['head'] = __('You do not have permi
|
||||
|
||||
<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('Role:') ?></th>
|
||||
<td><select name="new_role" id="new_role"><?php
|
||||
foreach($wp_roles->role_names as $role => $name) {
|
||||
$selected = (empty($wp_user->roles[$role])) ? '' : 'selected="selected"';
|
||||
echo "<option {$selected} value=\"{$role}\">{$name}</option>";
|
||||
}
|
||||
?></select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Posts:') ?></th>
|
||||
<td><?php echo get_usernumposts($edituser->ID); ?></td>
|
||||
</tr>
|
||||
<?php if ( isset($edituser->user_registered) && ('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->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
|
||||
do_action('edit_user_profile');
|
||||
|
||||
<form name="profile" id="your-profile" action="user-edit.php" method="post">
|
||||
<p>
|
||||
<input type="hidden" name="from" value="profile" />
|
||||
<input type="hidden" name="checkuser_id" value="<?php echo $user_ID ?>" />
|
||||
</p>
|
||||
|
||||
<fieldset>
|
||||
<legend><?php _e('Name'); ?></legend>
|
||||
<p><label><?php _e('Username: (no editing)'); ?><br />
|
||||
<input type="text" name="user_login" value="<?php echo $profiledata->user_login; ?>" disabled="disabled" />
|
||||
</label></p>
|
||||
<p><label><?php _e('First name:') ?><br />
|
||||
<input type="text" name="first_name" value="<?php echo $profiledata->first_name ?>" /></label></p>
|
||||
|
||||
<p><label><?php _e('Last name:') ?><br />
|
||||
<input type="text" name="last_name" value="<?php echo $profiledata->last_name ?>" /></label></p>
|
||||
|
||||
<p><label><?php _e('Nickname:') ?><br />
|
||||
<input type="text" name="nickname" value="<?php echo $profiledata->nickname ?>" /></label></p>
|
||||
|
||||
</p><label><?php _e('Display name publicly as:') ?> <br />
|
||||
<select name="display_name">
|
||||
<option value="<?php echo $profiledata->display_name; ?>"><?php echo $profiledata->display_name; ?></option>
|
||||
<option value="<?php echo $profiledata->nickname ?>"><?php echo $profiledata->nickname ?></option>
|
||||
<option value="<?php echo $profiledata->user_login ?>"><?php echo $profiledata->user_login ?></option>
|
||||
<?php if ( !empty( $profiledata->first_name ) ) : ?>
|
||||
<option value="<?php echo $profiledata->first_name ?>"><?php echo $profiledata->first_name ?></option>
|
||||
<?php endif; ?>
|
||||
<?php if ( !empty( $profiledata->last_name ) ) : ?>
|
||||
<option value="<?php echo $profiledata->last_name ?>"><?php echo $profiledata->last_name ?></option>
|
||||
<?php endif; ?>
|
||||
<?php if ( !empty( $profiledata->first_name ) && !empty( $profiledata->last_name ) ) : ?>
|
||||
<option value="<?php echo $profiledata->first_name." ".$profiledata->last_name ?>"><?php echo $profiledata->first_name." ".$profiledata->last_name ?></option>
|
||||
<option value="<?php echo $profiledata->last_name." ".$profiledata->first_name ?>"><?php echo $profiledata->last_name." ".$profiledata->first_name ?></option>
|
||||
<?php endif; ?>
|
||||
</select></label></p>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend><?php _e('Contact Info'); ?></legend>
|
||||
|
||||
<p><label><?php _e('E-mail: (required)') ?><br />
|
||||
<input type="text" name="email" value="<?php echo $profiledata->user_email ?>" /></label></p>
|
||||
|
||||
<p><label><?php _e('Website:') ?><br />
|
||||
<input type="text" name="url" value="<?php echo $profiledata->user_url ?>" />
|
||||
</label></p>
|
||||
|
||||
<p><label><?php _e('AIM:') ?><br />
|
||||
<input type="text" name="aim" value="<?php echo $profiledata->aim ?>" />
|
||||
</label></p>
|
||||
|
||||
<p><label><?php _e('Yahoo IM:') ?><br />
|
||||
<input type="text" name="yim" value="<?php echo $profiledata->yim ?>" />
|
||||
</label></p>
|
||||
|
||||
<p><label><?php _e('Jabber / Google Talk:') ?>
|
||||
<input type="text" name="jabber" value="<?php echo $profiledata->jabber ?>" /></label>
|
||||
</p>
|
||||
</fieldset>
|
||||
<br clear="all" />
|
||||
<fieldset>
|
||||
<legend><?php _e('About the user'); ?></legend>
|
||||
<p class="desc"><?php _e('Share a little biographical information to fill out your profile. This may be shown publicly.'); ?></p>
|
||||
<p><textarea name="description" rows="5" cols="30"><?php echo $profiledata->description ?></textarea></p>
|
||||
</fieldset>
|
||||
|
||||
<?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>
|
||||
<fieldset>
|
||||
<legend><?php _e("Update User's Password"); ?></legend>
|
||||
<p class="desc"><?php _e("If you would like to change the user's password type a new one twice below. Otherwise leave this blank."); ?></p>
|
||||
<p><label><?php _e('New Password:'); ?><br />
|
||||
<input type="password" name="pass1" size="16" value="" />
|
||||
</label></p>
|
||||
<p><label><?php _e('Type it one more time:'); ?><br />
|
||||
<input type="password" name="pass2" size="16" value="" />
|
||||
</label></p>
|
||||
</fieldset>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
<p class="submit">
|
||||
|
||||
<?php do_action('edit_user_profile'); ?>
|
||||
|
||||
<br clear="all" />
|
||||
<table width="99%" border="0" cellspacing="2" cellpadding="3" class="editform">
|
||||
<?php
|
||||
if(count($profileuser->caps) > count($profileuser->roles)):
|
||||
?>
|
||||
<tr>
|
||||
<th scope="row"><?php _e('Additional Capabilities:') ?></th>
|
||||
<td><?php
|
||||
$output = '';
|
||||
foreach($profileuser->caps as $cap => $value) {
|
||||
if(!$wp_roles->is_role($cap)) {
|
||||
if($output != '') $output .= ', ';
|
||||
$output .= $value ? $cap : "Denied: {$cap}";
|
||||
}
|
||||
}
|
||||
echo $output;
|
||||
?></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 »') ?>" name="submit" />
|
||||
</p>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user