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: http://svn.automattic.com/wordpress/trunk@2872 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9f95e3de61
commit
5ba66d6c04
|
@ -344,6 +344,103 @@ function category_exists($cat_name) {
|
||||||
return $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'");
|
return $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Creates a new user from the "Users" form using $_POST information.
|
||||||
|
|
||||||
|
function add_user() {
|
||||||
|
return update_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_user($user_id = 0) {
|
||||||
|
|
||||||
|
if ( $user_id != 0 ) {
|
||||||
|
$update = true;
|
||||||
|
$user->ID = $user_id;
|
||||||
|
$userdata = get_userdata($user_id);
|
||||||
|
$user->user_login = $userdata->user_login;
|
||||||
|
} else {
|
||||||
|
$update = false;
|
||||||
|
$user = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isset($_POST['user_login']) )
|
||||||
|
$user->user_login = wp_specialchars(trim($_POST['user_login']));
|
||||||
|
|
||||||
|
$pass1 = $pass2 = '';
|
||||||
|
if ( isset($_POST['pass1']) )
|
||||||
|
$pass1 = $_POST['pass1'];
|
||||||
|
if ( isset($_POST['pass2']) )
|
||||||
|
$pass2 = $_POST['pass2'];
|
||||||
|
|
||||||
|
if ( isset($_POST['email']) )
|
||||||
|
$user->user_email = wp_specialchars(trim($_POST['email']));
|
||||||
|
if ( isset($_POST['url']) ) {
|
||||||
|
$user->user_url = wp_specialchars(trim($_POST['url']));
|
||||||
|
$user->user_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url;
|
||||||
|
}
|
||||||
|
if ( isset($_POST['first_name']) )
|
||||||
|
$user->first_name = wp_specialchars(trim($_POST['first_name']));
|
||||||
|
if ( isset($_POST['last_name']) )
|
||||||
|
$user->last_name = wp_specialchars(trim($_POST['last_name']));
|
||||||
|
if ( isset($_POST['nickname']) )
|
||||||
|
$user->nickname = wp_specialchars(trim($_POST['nickname']));
|
||||||
|
if ( isset($_POST['display_name']) )
|
||||||
|
$user->display_name = wp_specialchars(trim($_POST['display_name']));
|
||||||
|
if ( isset($_POST['description']) )
|
||||||
|
$user->description = wp_specialchars(trim($_POST['description']));
|
||||||
|
if ( isset($_POST['jabber']) )
|
||||||
|
$user->jabber = wp_specialchars(trim($_POST['jabber']));
|
||||||
|
if ( isset($_POST['aim']) )
|
||||||
|
$user->aim = wp_specialchars(trim($_POST['aim']));
|
||||||
|
if ( isset($_POST['yim']) )
|
||||||
|
$user->yim = wp_specialchars(trim($_POST['yim']));
|
||||||
|
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
/* checking that username has been typed */
|
||||||
|
if ($user->user_login == '')
|
||||||
|
$errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.');
|
||||||
|
|
||||||
|
/* checking the password has been typed twice */
|
||||||
|
do_action('check_passwords', array($user->user_login, &$pass1, &$pass2));
|
||||||
|
|
||||||
|
if ( !$update ) {
|
||||||
|
if ( $pass1 == '' || $pass2 == '' )
|
||||||
|
$errors['pass'] = __('<strong>ERROR</strong>: Please enter your password twice.');
|
||||||
|
} else {
|
||||||
|
if ( ( empty($pass1) && !empty($pass2) ) || ( empty($pass2) && !empty($pass1) ) )
|
||||||
|
$errors['pass'] = __("<strong>ERROR</strong>: you typed your new password only once.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* checking the password has been typed twice the same */
|
||||||
|
if ($pass1 != $pass2)
|
||||||
|
$errors['pass'] = __('<strong>ERROR</strong>: Please type the same password in the two password fields.');
|
||||||
|
|
||||||
|
if ( !empty($pass1) )
|
||||||
|
$user->user_pass = $pass1;
|
||||||
|
|
||||||
|
if ( !$update && username_exists( $user_login ) )
|
||||||
|
$errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');
|
||||||
|
|
||||||
|
/* checking e-mail address */
|
||||||
|
if (empty($user->user_email)) {
|
||||||
|
$errors['user_email'] = __("<strong>ERROR</strong>: please type an e-mail address");
|
||||||
|
} else if (!is_email($user->user_email)) {
|
||||||
|
$errors['user_email'] = __("<strong>ERROR</strong>: the email address isn't correct");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( count($errors) != 0 )
|
||||||
|
return $errors;
|
||||||
|
|
||||||
|
if ( $update ) {
|
||||||
|
$user_id = wp_update_user(get_object_vars($user));
|
||||||
|
} else {
|
||||||
|
$user_id = wp_insert_user(get_object_vars($user));
|
||||||
|
wp_new_user_notification($user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
|
||||||
function wp_delete_user($id, $reassign = 'novalue') {
|
function wp_delete_user($id, $reassign = 'novalue') {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ else
|
||||||
|
|
||||||
require_once(ABSPATH . 'wp-admin/admin-functions.php');
|
require_once(ABSPATH . 'wp-admin/admin-functions.php');
|
||||||
require_once(ABSPATH . 'wp-admin/admin-db.php');
|
require_once(ABSPATH . 'wp-admin/admin-db.php');
|
||||||
|
require_once(ABSPATH . WPINC . '/registration-functions.php');
|
||||||
|
|
||||||
auth_redirect();
|
auth_redirect();
|
||||||
|
|
||||||
nocache_headers();
|
nocache_headers();
|
||||||
|
|
|
@ -35,13 +35,16 @@ class MT_Import {
|
||||||
$importdata = preg_replace("/(\r\n|\n|\r)/", "\n", $importdata);
|
$importdata = preg_replace("/(\r\n|\n|\r)/", "\n", $importdata);
|
||||||
$importdata = preg_replace("/\n--------\n/", "--MT-ENTRY--\n", $importdata);
|
$importdata = preg_replace("/\n--------\n/", "--MT-ENTRY--\n", $importdata);
|
||||||
$this->posts = explode("--MT-ENTRY--", $importdata);
|
$this->posts = explode("--MT-ENTRY--", $importdata);
|
||||||
|
unset($importdata);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function import() {
|
function import() {
|
||||||
if ('' != MTEXPORT && !file_exists(MTEXPORT)) die("The file you specified does not seem to exist. Please check the path you've given.");
|
if ('' != MTEXPORT && !file_exists(MTEXPORT)) die("The file you specified does not seem to exist. Please check the path you've given.");
|
||||||
if ('' == MTEXPORT) die("You must edit the MTEXPORT line as described on the <a href='import-mt.php'>previous page</a> to continue.");
|
if ('' == MTEXPORT) die("You must edit the MTEXPORT line as described on the <a href='import-mt.php'>previous page</a> to continue.");
|
||||||
|
|
||||||
$this->get_entries();
|
$this->get_entries();
|
||||||
}
|
}
|
||||||
|
|
||||||
function dispatch() {
|
function dispatch() {
|
||||||
|
|
|
@ -4,55 +4,15 @@ require_once('admin.php');
|
||||||
|
|
||||||
check_admin_referer();
|
check_admin_referer();
|
||||||
|
|
||||||
if ( empty($_POST['email']) )
|
$errors = update_user($user_ID);
|
||||||
die (__("<strong>ERROR</strong>: please type your e-mail address"));
|
|
||||||
elseif ( !is_email($_POST['email']) )
|
|
||||||
die (__("<strong>ERROR</strong>: the e-mail address isn't correct"));
|
|
||||||
|
|
||||||
$pass1 = $_POST['pass1'];
|
if (count($errors) != 0) {
|
||||||
$pass2 = $_POST['pass2'];
|
foreach ($errors as $id => $error) {
|
||||||
do_action('check_passwords', array($user_login, &$pass1, &$pass2));
|
echo $error . '<br/>';
|
||||||
|
}
|
||||||
if ( '' == $pass1 ) {
|
exit;
|
||||||
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.'));
|
|
||||||
$newuser_pass = $pass1;
|
|
||||||
$updatepassword = "user_pass=MD5('$newuser_pass'), ";
|
|
||||||
wp_clearcookie();
|
|
||||||
wp_setcookie($user_login, $newuser_pass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$first_name = wp_specialchars($_POST['first_name']);
|
|
||||||
$last_name = wp_specialchars($_POST['last_name']);
|
|
||||||
$display_name = wp_specialchars($_POST['display_name']);
|
|
||||||
$nickname = $_POST['nickname'];
|
|
||||||
$nicename = sanitize_title($nickname);
|
|
||||||
$jabber = wp_specialchars($_POST['jabber']);
|
|
||||||
$aim = wp_specialchars($_POST['aim']);
|
|
||||||
$yim = wp_specialchars($_POST['yim']);
|
|
||||||
$email = wp_specialchars($_POST['email']);
|
|
||||||
$url = wp_specialchars($_POST['url']);
|
|
||||||
$url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $url) ? $url : 'http://' . $url;
|
|
||||||
$user_description = $_POST['user_description'];
|
|
||||||
|
|
||||||
$result = $wpdb->query("UPDATE $wpdb->users SET $updatepassword user_email='$email', user_url='$url', user_nicename = '$nicename', display_name = '$display_name' WHERE ID = '$user_ID'");
|
|
||||||
|
|
||||||
update_usermeta( $user_ID, 'first_name', $first_name );
|
|
||||||
update_usermeta( $user_ID, 'last_name', $last_name );
|
|
||||||
update_usermeta( $user_ID, 'nickname', $nickname );
|
|
||||||
update_usermeta( $user_ID, 'description', $user_description );
|
|
||||||
update_usermeta( $user_ID, 'jabber', $jabber );
|
|
||||||
update_usermeta( $user_ID, 'aim', $aim );
|
|
||||||
update_usermeta( $user_ID, 'yim', $yim );
|
|
||||||
|
|
||||||
do_action('profile_update', $user_ID);
|
|
||||||
|
|
||||||
if ( 'profile' == $_POST['from'] )
|
if ( 'profile' == $_POST['from'] )
|
||||||
$to = 'profile.php?updated=true';
|
$to = 'profile.php?updated=true';
|
||||||
else
|
else
|
||||||
|
|
|
@ -28,7 +28,7 @@ $bookmarklet_height= 440;
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><?php _e('Name'); ?></legend>
|
<legend><?php _e('Name'); ?></legend>
|
||||||
<p><label><?php _e('Username: (no editing)'); ?><br />
|
<p><label><?php _e('Username: (no editing)'); ?><br />
|
||||||
<input type="text" name="username" value="<?php echo $profiledata->user_login; ?>" disabled="disabled" />
|
<input type="text" name="user_login" value="<?php echo $profiledata->user_login; ?>" disabled="disabled" />
|
||||||
</label></p>
|
</label></p>
|
||||||
<p><label><?php _e('First name:') ?><br />
|
<p><label><?php _e('First name:') ?><br />
|
||||||
<input type="text" name="first_name" value="<?php echo $profiledata->first_name ?>" /></label></p>
|
<input type="text" name="first_name" value="<?php echo $profiledata->first_name ?>" /></label></p>
|
||||||
|
@ -83,7 +83,7 @@ $bookmarklet_height= 440;
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><?php _e('About yourself'); ?></legend>
|
<legend><?php _e('About yourself'); ?></legend>
|
||||||
<p class="desc"><?php _e('Share a little biographical information to fill out your profile. This may be shown publicly.'); ?></p>
|
<p class="desc"><?php _e('Share a little biographical information to fill out your profile. This may be shown publicly.'); ?></p>
|
||||||
<p><textarea name="user_description" rows="5" cols="30"><?php echo $profiledata->user_description ?></textarea></p>
|
<p><textarea name="description" rows="5" cols="30"><?php echo $profiledata->description ?></textarea></p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
|
@ -33,78 +33,22 @@ break;
|
||||||
case 'update':
|
case 'update':
|
||||||
|
|
||||||
$errors = array();
|
$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.');
|
if (!current_user_can('edit_users'))
|
||||||
|
$errors['head'] = __('You do not have permission to edit this user.');
|
||||||
/* checking the nickname has been typed */
|
else
|
||||||
if (empty($_POST["new_nickname"])) {
|
$errors = update_user($user_id);
|
||||||
$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(count($errors) == 0) {
|
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");
|
header("Location: user-edit.php?user_id=$user_id&updated=true");
|
||||||
} else {
|
exit;
|
||||||
$wp_user->roles = array($_POST['new_role'] => true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
include ('admin-header.php');
|
include ('admin-header.php');
|
||||||
|
|
||||||
if(empty($wp_user)) {
|
$profileuser = new WP_User($user_id);
|
||||||
$wp_user = new WP_User($user_id);
|
$profiledata = $profileuser->data;
|
||||||
$edituser = &$wp_user->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!current_user_can('edit_users')) $errors['head'] = __('You do not have permission to edit this user.');
|
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>
|
<p><strong><?php _e('User updated.') ?></strong></p>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php if ( isset($errors) ) : ?>
|
<?php if ( count($errors) != 0 ) : ?>
|
||||||
<div class="error">
|
<div class="error">
|
||||||
<ul>
|
<ul>
|
||||||
<?php
|
<?php
|
||||||
|
@ -126,116 +70,121 @@ if (!current_user_can('edit_users')) $errors['head'] = __('You do not have permi
|
||||||
|
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<h2><?php _e('Edit User'); ?></h2>
|
<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);
|
$show_password_fields = apply_filters('show_password_fields', true);
|
||||||
if ( $show_password_fields ) :
|
if ( $show_password_fields ) :
|
||||||
?>
|
?>
|
||||||
<tr>
|
<fieldset>
|
||||||
<th scope="row"><?php _e('New <strong>Password</strong> (Leave blank to stay the same.)') ?></th>
|
<legend><?php _e("Update User's Password"); ?></legend>
|
||||||
<td><input type="password" name="pass1" size="16" value="" />
|
<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>
|
||||||
<br />
|
<p><label><?php _e('New Password:'); ?><br />
|
||||||
<input type="password" name="pass2" size="16" value="" /></td>
|
<input type="password" name="pass1" size="16" value="" />
|
||||||
</tr>
|
</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; ?>
|
<?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="action" value="update" />
|
||||||
<input type="hidden" name="user_id" id="user_id" value="<?php echo $user_id; ?>" />
|
<input type="hidden" name="user_id" id="user_id" value="<?php echo $user_id; ?>" />
|
||||||
<input type="submit" value="<?php _e('Update User »') ?>" name="submit" />
|
<input type="submit" value="<?php _e('Update User »') ?>" name="submit" />
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,65 +110,10 @@ break;
|
||||||
|
|
||||||
case 'adduser':
|
case 'adduser':
|
||||||
check_admin_referer();
|
check_admin_referer();
|
||||||
|
|
||||||
$new_user_login = wp_specialchars(trim($_POST['user_login']));
|
|
||||||
$new_pass1 = $_POST['pass1'];
|
|
||||||
$new_pass2 = $_POST['pass2'];
|
|
||||||
$new_user_email = wp_specialchars(trim($_POST['email']));
|
|
||||||
$new_user_firstname = wp_specialchars(trim($_POST['firstname']));
|
|
||||||
$new_user_lastname = wp_specialchars(trim($_POST['lastname']));
|
|
||||||
$new_user_uri = wp_specialchars(trim($_POST['uri']));
|
|
||||||
|
|
||||||
$errors = array();
|
$errors = add_user();
|
||||||
|
|
||||||
/* checking that username has been typed */
|
|
||||||
if ($new_user_login == '')
|
|
||||||
$errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.');
|
|
||||||
|
|
||||||
/* checking the password has been typed twice */
|
|
||||||
do_action('check_passwords', array($new_user_login, &$new_pass1, &$new_pass2));
|
|
||||||
if ($new_pass1 == '' || $new_pass2 == '')
|
|
||||||
$errors['pass'] = __('<strong>ERROR</strong>: Please enter your password twice.');
|
|
||||||
|
|
||||||
/* checking the password has been typed twice the same */
|
|
||||||
if ($new_pass1 != $new_pass2)
|
|
||||||
$errors['pass'] = __('<strong>ERROR</strong>: Please type the same password in the two password fields.');
|
|
||||||
|
|
||||||
$new_user_nickname = $new_user_login;
|
|
||||||
|
|
||||||
if ( username_exists( $new_user_login ) )
|
|
||||||
$errors['pass'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');
|
|
||||||
|
|
||||||
/* checking e-mail address */
|
|
||||||
if (empty($new_user_email)) {
|
|
||||||
$errors['user_email'] = __("<strong>ERROR</strong>: please type an e-mail address");
|
|
||||||
} else if (!is_email($new_user_email)) {
|
|
||||||
$errors['user_email'] = __("<strong>ERROR</strong>: the email address isn't correct");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(count($errors) == 0) {
|
|
||||||
$user_ID = create_user( $new_user_login, $new_pass1, $new_user_email, 0 );
|
|
||||||
|
|
||||||
update_usermeta( $user_ID, 'first_name', $new_user_firstname);
|
|
||||||
update_usermeta( $user_ID, 'last_name', $new_user_lastname);
|
|
||||||
update_usermeta( $user_ID, 'first_name', $new_user_firstname);
|
|
||||||
|
|
||||||
$user = new WP_User($user_ID);
|
|
||||||
$user->set_role(get_settings('default_role'));
|
|
||||||
|
|
||||||
$stars = '';
|
|
||||||
for ($i = 0; $i < strlen($pass1); $i = $i + 1)
|
|
||||||
$stars .= '*';
|
|
||||||
|
|
||||||
$user_login = stripslashes($new_user_login);
|
if(count($errors) == 0) {
|
||||||
$message = sprintf(__('New user registration on your blog %s:'), get_settings('blogname')) . "\r\n\r\n";
|
|
||||||
$message .= sprintf(__('Username: %s'), $new_user_login) . "\r\n\r\n";
|
|
||||||
$message .= sprintf(__('E-mail: %s'), $new_user_email) . "\r\n";
|
|
||||||
|
|
||||||
@wp_mail(get_settings('admin_email'), sprintf(__('[%s] New User Registration'), get_settings('blogname')), $message);
|
|
||||||
|
|
||||||
do_action('user_register', $user_id);
|
|
||||||
|
|
||||||
header('Location: users.php?update=add');
|
header('Location: users.php?update=add');
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
@ -310,11 +255,11 @@ $role_select .= '</select>';
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><?php _e('First Name') ?> </th>
|
<th scope="row"><?php _e('First Name') ?> </th>
|
||||||
<td><input name="firstname" type="text" id="firstname" value="<?php echo $new_user_firstname; ?>" /></td>
|
<td><input name="first_name" type="text" id="first_name" value="<?php echo $new_user_firstname; ?>" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><?php _e('Last Name') ?> </th>
|
<th scope="row"><?php _e('Last Name') ?> </th>
|
||||||
<td><input name="lastname" type="text" id="lastname" value="<?php echo $new_user_lastname; ?>" /></td>
|
<td><input name="last_name" type="text" id="last_name" value="<?php echo $new_user_lastname; ?>" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><?php _e('E-mail') ?></th>
|
<th scope="row"><?php _e('E-mail') ?></th>
|
||||||
|
@ -322,7 +267,7 @@ $role_select .= '</select>';
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><?php _e('Website') ?></th>
|
<th scope="row"><?php _e('Website') ?></th>
|
||||||
<td><input name="uri" type="text" id="uri" value="<?php echo $new_user_uri; ?>" /></td>
|
<td><input name="url" type="text" id="url" value="<?php echo $new_user_uri; ?>" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
$show_password_fields = apply_filters('show_password_fields', true);
|
$show_password_fields = apply_filters('show_password_fields', true);
|
||||||
|
|
|
@ -1263,6 +1263,11 @@ function update_category_cache() {
|
||||||
endif;
|
endif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clean_user_cache($id) {
|
||||||
|
if ( isset( $cache_userdata[$id] ) )
|
||||||
|
unset( $cache_userdata[$id] );
|
||||||
|
}
|
||||||
|
|
||||||
function wp_head() {
|
function wp_head() {
|
||||||
do_action('wp_head');
|
do_action('wp_head');
|
||||||
}
|
}
|
||||||
|
|
|
@ -319,4 +319,33 @@ function wp_notify_moderator($comment_id) {
|
||||||
}
|
}
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
if ( !function_exists('wp_new_user_notification') ) :
|
||||||
|
function wp_new_user_notification($user_id, $plaintext_pass = '') {
|
||||||
|
$user = new WP_User($user_id);
|
||||||
|
|
||||||
|
$stars = '';
|
||||||
|
for ($i = 0; $i < strlen($pass1); $i = $i + 1)
|
||||||
|
$stars .= '*';
|
||||||
|
|
||||||
|
$user_login = stripslashes($user->data->user_login);
|
||||||
|
$user_email = stripslashes($user->data->user_email);
|
||||||
|
|
||||||
|
$message = sprintf(__('New user registration on your blog %s:'), get_settings('blogname')) . "\r\n\r\n";
|
||||||
|
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
|
||||||
|
$message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
|
||||||
|
|
||||||
|
@wp_mail(get_settings('admin_email'), sprintf(__('[%s] New User Registration'), get_settings('blogname')), $message);
|
||||||
|
|
||||||
|
if ( empty($plaintext_pass) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
$message = sprintf(__('Username: %s'), $user_login) . "\r\n";
|
||||||
|
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
|
||||||
|
$message .= get_settings('siteurl') . "/wp-login.php\r\n";
|
||||||
|
|
||||||
|
wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_settings('blogname')), $message);
|
||||||
|
|
||||||
|
}
|
||||||
|
endif;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -8,28 +8,116 @@ function username_exists( $username ) {
|
||||||
return $wpdb->get_var( $query );
|
return $wpdb->get_var( $query );
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_user( $username, $password, $email, $user_level ) {
|
function wp_insert_user($userdata) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$username = $wpdb->escape( $username );
|
|
||||||
$email = $wpdb->escape( $email );
|
|
||||||
$password = md5( $password );
|
|
||||||
$user_nicename = sanitize_title( $username );
|
|
||||||
$now = gmdate('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
$query = "INSERT INTO $wpdb->users
|
extract($userdata);
|
||||||
(user_login, user_pass, user_email, user_registered, user_nicename, display_name)
|
|
||||||
|
// Are we updating or creating?
|
||||||
|
if ( !empty($ID) ) {
|
||||||
|
$update = true;
|
||||||
|
} else {
|
||||||
|
$update = false;
|
||||||
|
// Password is not hashed when creating new user.
|
||||||
|
$user_pass = md5($user_pass);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty($user_nicename) )
|
||||||
|
$user_nicename = sanitize_title( $user_login );
|
||||||
|
|
||||||
|
if ( empty($display_name) )
|
||||||
|
$display_name = $user_login;
|
||||||
|
|
||||||
|
if ( empty($nickname) )
|
||||||
|
$nickname = $user_login;
|
||||||
|
|
||||||
|
if ( empty($user_registered) )
|
||||||
|
$user_registered = gmdate('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
if ( $update ) {
|
||||||
|
$query = "UPDATE $wpdb->users SET user_pass='$user_pass' user_email='$user_email', user_url='$user_url', user_nicename = '$user_nicename', display_name = '$display_name' WHERE ID = '$ID'";
|
||||||
|
$query = apply_filters('update_user_query', $query);
|
||||||
|
$wpdb->query( $query );
|
||||||
|
$user_id = $ID;
|
||||||
|
} else {
|
||||||
|
$query = "INSERT INTO $wpdb->users
|
||||||
|
(user_login, user_pass, user_email, user_url, user_registered, user_nicename, display_name)
|
||||||
VALUES
|
VALUES
|
||||||
('$username', '$password', '$email', '$now', '$user_nicename', '$username')";
|
('$user_login', '$user_pass', '$user_email', '$user_url', '$user_registered', '$user_nicename', '$display_name')";
|
||||||
$query = apply_filters('create_user_query', $query);
|
$query = apply_filters('create_user_query', $query);
|
||||||
$wpdb->query( $query );
|
$wpdb->query( $query );
|
||||||
$user_id = $wpdb->insert_id;
|
$user_id = $wpdb->insert_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
clean_user_cache($user_id);
|
||||||
|
clean_user_cache($user_login);
|
||||||
|
|
||||||
$user_level = (int) $user_level;
|
update_usermeta( $user_id, 'first_name', $first_name);
|
||||||
update_usermeta( $user_id, $wpdb->prefix . 'user_level', $user_level);
|
update_usermeta( $user_id, 'last_name', $last_name);
|
||||||
$user = new WP_User($user_id);
|
update_usermeta( $user_id, 'nickname', $nickname );
|
||||||
$user->set_role(get_settings('default_role'));
|
update_usermeta( $user_id, 'description', $description );
|
||||||
|
update_usermeta( $user_id, 'jabber', $jabber );
|
||||||
|
update_usermeta( $user_id, 'aim', $aim );
|
||||||
|
update_usermeta( $user_id, 'yim', $yim );
|
||||||
|
|
||||||
|
if ( !$update ) {
|
||||||
|
$user = new WP_User($user_id);
|
||||||
|
$user->set_role(get_settings('default_role'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $update )
|
||||||
|
do_action('profile_update', $user_id);
|
||||||
|
else
|
||||||
|
do_action('user_register', $user_id);
|
||||||
|
|
||||||
|
return $user_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function wp_update_user($userdata) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
$ID = (int) $userdata['ID'];
|
||||||
|
|
||||||
|
// First, get all of the original fields
|
||||||
|
$user = get_userdata($ID);
|
||||||
|
|
||||||
|
// Escape data pulled from DB.
|
||||||
|
$user = add_magic_quotes(get_object_vars($user));
|
||||||
|
|
||||||
|
// If password is changing, hash it now.
|
||||||
|
if ( ! empty($userdata['user_pass']) ) {
|
||||||
|
$plaintext_pass = $userdata['user_pass'];
|
||||||
|
$userdata['user_pass'] = md5($userdata['user_pass']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge old and new fields with new fields overwriting old ones.
|
||||||
|
$userdata = array_merge($user, $userdata);
|
||||||
|
$user_id = wp_insert_user($userdata);
|
||||||
|
|
||||||
|
// Update the cookies if the password changed.
|
||||||
|
if ( isset($plaintext_pass) ) {
|
||||||
|
wp_clearcookie();
|
||||||
|
wp_setcookie($userdata['user_login'], $plaintext_pass);
|
||||||
|
}
|
||||||
|
|
||||||
return $user_id;
|
return $user_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wp_create_user( $username, $password, $email ) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
$user_login = $wpdb->escape( $username );
|
||||||
|
$user_email = $wpdb->escape( $email );
|
||||||
|
$user_pass = $password;
|
||||||
|
|
||||||
|
$userdata = compact('user_login', 'user_email', 'user_pass');
|
||||||
|
return wp_insert_user($userdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function create_user( $username, $password, $email ) {
|
||||||
|
return wp_create_user( $username, $password, $email );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -30,37 +30,18 @@ case 'register':
|
||||||
if ( username_exists( $user_login ) )
|
if ( username_exists( $user_login ) )
|
||||||
$errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');
|
$errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');
|
||||||
|
|
||||||
$password = substr( md5( uniqid( microtime() ) ), 0, 7);
|
if ( 0 == count($errors) ) {
|
||||||
|
$password = substr( md5( uniqid( microtime() ) ), 0, 7);
|
||||||
|
|
||||||
$user_id = create_user( $user_login, $password, $user_email, 0 );
|
$user_id = wp_create_user( $user_login, $password, $user_email );
|
||||||
if ( !$user_id ) {
|
if ( !$user_id )
|
||||||
$errors['user_id'] = sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_settings('admin_email'));
|
$errors['user_id'] = sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_settings('admin_email'));
|
||||||
|
else
|
||||||
|
wp_new_user_notification($user_id, $password);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count($errors) == 0) {
|
|
||||||
$user = new WP_User($user_id);
|
|
||||||
$user->set_role(get_settings('default_role'));
|
|
||||||
|
|
||||||
do_action('user_register', $user_id);
|
if ( 0 == count($errors) ) {
|
||||||
|
|
||||||
|
|
||||||
$stars = '';
|
|
||||||
for ($i = 0; $i < strlen($pass1); $i = $i + 1) {
|
|
||||||
$stars .= '*';
|
|
||||||
}
|
|
||||||
|
|
||||||
$message = sprintf(__('Username: %s'), $user_login) . "\r\n";
|
|
||||||
$message .= sprintf(__('Password: %s'), $password) . "\r\n";
|
|
||||||
$message .= get_settings('siteurl') . "/wp-login.php\r\n";
|
|
||||||
|
|
||||||
wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_settings('blogname')), $message);
|
|
||||||
|
|
||||||
$message = sprintf(__('New user registration on your blog %s:'), get_settings('blogname')) . "\r\n\r\n";
|
|
||||||
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
|
|
||||||
$message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
|
|
||||||
|
|
||||||
@wp_mail(get_settings('admin_email'), sprintf(__('[%s] New User Registration'), get_settings('blogname')), $message);
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
|
Loading…
Reference in New Issue