diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php
index bb4ba32fd5..4939b82848 100644
--- a/wp-admin/admin-functions.php
+++ b/wp-admin/admin-functions.php
@@ -344,6 +344,103 @@ function category_exists($cat_name) {
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'] = __('ERROR: 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'] = __('ERROR: Please enter your password twice.');
+ } else {
+ if ( ( empty($pass1) && !empty($pass2) ) || ( empty($pass2) && !empty($pass1) ) )
+ $errors['pass'] = __("ERROR: you typed your new password only once.");
+ }
+
+ /* checking the password has been typed twice the same */
+ if ($pass1 != $pass2)
+ $errors['pass'] = __('ERROR: 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'] = __('ERROR: This username is already registered, please choose another one.');
+
+ /* checking e-mail address */
+ if (empty($user->user_email)) {
+ $errors['user_email'] = __("ERROR: please type an e-mail address");
+ } else if (!is_email($user->user_email)) {
+ $errors['user_email'] = __("ERROR: 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') {
global $wpdb;
diff --git a/wp-admin/admin.php b/wp-admin/admin.php
index 2a65c30cfa..c228b1d293 100644
--- a/wp-admin/admin.php
+++ b/wp-admin/admin.php
@@ -6,6 +6,8 @@ else
require_once(ABSPATH . 'wp-admin/admin-functions.php');
require_once(ABSPATH . 'wp-admin/admin-db.php');
+require_once(ABSPATH . WPINC . '/registration-functions.php');
+
auth_redirect();
nocache_headers();
diff --git a/wp-admin/import/mt.php b/wp-admin/import/mt.php
index 53c7df2b42..c067e0eec7 100644
--- a/wp-admin/import/mt.php
+++ b/wp-admin/import/mt.php
@@ -35,13 +35,16 @@ class MT_Import {
$importdata = preg_replace("/(\r\n|\n|\r)/", "\n", $importdata);
$importdata = preg_replace("/\n--------\n/", "--MT-ENTRY--\n", $importdata);
$this->posts = explode("--MT-ENTRY--", $importdata);
+ unset($importdata);
+
+
}
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) die("You must edit the MTEXPORT line as described on the previous page to continue.");
- $this->get_entries();
+ $this->get_entries();
}
function dispatch() {
diff --git a/wp-admin/profile-update.php b/wp-admin/profile-update.php
index 6591c31c3c..492d26a355 100644
--- a/wp-admin/profile-update.php
+++ b/wp-admin/profile-update.php
@@ -4,55 +4,15 @@ require_once('admin.php');
check_admin_referer();
-if ( empty($_POST['email']) )
- die (__("ERROR: please type your e-mail address"));
-elseif ( !is_email($_POST['email']) )
- die (__("ERROR: the e-mail address isn't correct"));
+$errors = update_user($user_ID);
-$pass1 = $_POST['pass1'];
-$pass2 = $_POST['pass2'];
-do_action('check_passwords', array($user_login, &$pass1, &$pass2));
-
-if ( '' == $pass1 ) {
- if ( '' != $pass2 )
- die (__('ERROR: you typed your new password only once. Go back to type it twice.'));
- $updatepassword = '';
-} else {
- if ('' == $pass2)
- die (__('ERROR: you typed your new password only once. Go back to type it twice.'));
- if ( $pass1 != $pass2 )
- die (__('ERROR: 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);
+if (count($errors) != 0) {
+ foreach ($errors as $id => $error) {
+ echo $error . '
';
+ }
+ exit;
}
-$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'] )
$to = 'profile.php?updated=true';
else
diff --git a/wp-admin/profile.php b/wp-admin/profile.php
index 27bec9f849..c65da5247f 100644
--- a/wp-admin/profile.php
+++ b/wp-admin/profile.php
@@ -28,7 +28,7 @@ $bookmarklet_height= 440;