Make WordPress Core

Changeset 2872


Ignore:
Timestamp:
09/14/2005 12:03:02 AM (19 years ago)
Author:
ryan
Message:

User create/update rework. Introduce wp_insert_user(), wp_create_user(), wp_update_user(), add_user(), update_user(), wp_new_user_notification().

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r2866 r2872  
    343343       
    344344    return $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'");
     345}
     346
     347// Creates a new user from the "Users" form using $_POST information.
     348
     349function add_user() {
     350    return update_user();   
     351}
     352
     353function update_user($user_id = 0) {
     354   
     355    if ( $user_id != 0 ) {
     356        $update = true;
     357        $user->ID = $user_id;
     358        $userdata = get_userdata($user_id);
     359        $user->user_login = $userdata->user_login;
     360    } else {
     361        $update = false;
     362        $user = '';
     363    }
     364   
     365    if ( isset($_POST['user_login']) )
     366        $user->user_login = wp_specialchars(trim($_POST['user_login']));
     367
     368    $pass1 = $pass2 = '';
     369    if ( isset($_POST['pass1']) )
     370        $pass1 = $_POST['pass1'];
     371    if ( isset($_POST['pass2']) )
     372        $pass2 = $_POST['pass2'];
     373
     374    if ( isset($_POST['email']) )
     375        $user->user_email = wp_specialchars(trim($_POST['email']));
     376    if ( isset($_POST['url']) ) {
     377        $user->user_url = wp_specialchars(trim($_POST['url']));
     378        $user->user_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url;
     379    }
     380    if ( isset($_POST['first_name']) )
     381        $user->first_name = wp_specialchars(trim($_POST['first_name']));
     382    if ( isset($_POST['last_name']) )
     383        $user->last_name = wp_specialchars(trim($_POST['last_name']));
     384    if ( isset($_POST['nickname']) )
     385        $user->nickname = wp_specialchars(trim($_POST['nickname']));
     386    if ( isset($_POST['display_name']) )
     387        $user->display_name = wp_specialchars(trim($_POST['display_name']));
     388    if ( isset($_POST['description']) )
     389        $user->description = wp_specialchars(trim($_POST['description']));
     390    if ( isset($_POST['jabber']) )
     391        $user->jabber = wp_specialchars(trim($_POST['jabber']));
     392    if ( isset($_POST['aim']) )
     393        $user->aim = wp_specialchars(trim($_POST['aim']));
     394    if ( isset($_POST['yim']) )
     395        $user->yim = wp_specialchars(trim($_POST['yim']));
     396
     397    $errors = array();
     398       
     399    /* checking that username has been typed */
     400    if ($user->user_login == '')
     401        $errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.');
     402
     403    /* checking the password has been typed twice */
     404    do_action('check_passwords', array($user->user_login, &$pass1, &$pass2));
     405   
     406    if ( !$update ) {
     407        if ( $pass1 == '' || $pass2 == '' )
     408            $errors['pass'] = __('<strong>ERROR</strong>: Please enter your password twice.');
     409    } else {
     410        if ( ( empty($pass1) && !empty($pass2) ) || ( empty($pass2) && !empty($pass1) ) )
     411            $errors['pass'] = __("<strong>ERROR</strong>: you typed your new password only once.");
     412    }
     413   
     414    /* checking the password has been typed twice the same */
     415    if ($pass1 != $pass2)
     416        $errors['pass'] = __('<strong>ERROR</strong>: Please type the same password in the two password fields.');
     417
     418    if ( !empty($pass1) )
     419        $user->user_pass = $pass1;
     420   
     421    if ( !$update && username_exists( $user_login ) )
     422        $errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');
     423
     424    /* checking e-mail address */
     425    if (empty($user->user_email)) {
     426        $errors['user_email'] = __("<strong>ERROR</strong>: please type an e-mail address");
     427    } else if (!is_email($user->user_email)) {
     428        $errors['user_email'] = __("<strong>ERROR</strong>: the email address isn't correct");
     429    }
     430
     431    if ( count($errors) != 0 )
     432        return $errors;
     433   
     434    if ( $update ) {
     435        $user_id = wp_update_user(get_object_vars($user));
     436    } else {
     437        $user_id = wp_insert_user(get_object_vars($user));
     438        wp_new_user_notification($user_id);
     439    }
     440   
     441    return $errors;
    345442}
    346443
  • trunk/wp-admin/admin.php

    r2865 r2872  
    77require_once(ABSPATH . 'wp-admin/admin-functions.php');
    88require_once(ABSPATH . 'wp-admin/admin-db.php');
     9require_once(ABSPATH . WPINC . '/registration-functions.php');
     10
    911auth_redirect();
    1012
  • trunk/wp-admin/import/mt.php

    r2800 r2872  
    3636        $importdata = preg_replace("/\n--------\n/", "--MT-ENTRY--\n", $importdata);
    3737        $this->posts = explode("--MT-ENTRY--", $importdata);
     38        unset($importdata);
     39       
     40       
    3841    }
    3942   
     
    4245        if ('' == MTEXPORT) die("You must edit the MTEXPORT line as described on the <a href='import-mt.php'>previous page</a> to continue.");
    4346   
    44         $this->get_entries();   
     47        $this->get_entries();
    4548    }
    4649   
  • trunk/wp-admin/profile-update.php

    r2845 r2872  
    55check_admin_referer();
    66
    7 if ( empty($_POST['email']) )
    8     die (__("<strong>ERROR</strong>: please type your e-mail address"));
    9 elseif ( !is_email($_POST['email']) )
    10     die (__("<strong>ERROR</strong>: the e-mail address isn't correct"));
     7$errors = update_user($user_ID);
    118
    12 $pass1 = $_POST['pass1'];
    13 $pass2 = $_POST['pass2'];
    14 do_action('check_passwords', array($user_login, &$pass1, &$pass2));
    15 
    16 if ( '' == $pass1 ) {
    17     if ( '' != $pass2 )
    18         die (__('<strong>ERROR</strong>: you typed your new password only once. Go back to type it twice.'));
    19     $updatepassword = '';
    20 } else {
    21     if ('' == $pass2)
    22         die (__('<strong>ERROR</strong>: you typed your new password only once. Go back to type it twice.'));
    23     if ( $pass1 != $pass2 )
    24         die (__('<strong>ERROR</strong>: you typed two different passwords. Go back to correct that.'));
    25     $newuser_pass = $pass1;
    26     $updatepassword = "user_pass=MD5('$newuser_pass'), ";
    27     wp_clearcookie();
    28     wp_setcookie($user_login, $newuser_pass);
     9if (count($errors) != 0) {
     10    foreach ($errors as $id => $error) {
     11        echo $error . '<br/>';
     12    }
     13    exit;
    2914}
    30 
    31 $first_name = wp_specialchars($_POST['first_name']);
    32 $last_name = wp_specialchars($_POST['last_name']);
    33 $display_name = wp_specialchars($_POST['display_name']);
    34 $nickname = $_POST['nickname'];
    35 $nicename = sanitize_title($nickname);
    36 $jabber = wp_specialchars($_POST['jabber']);
    37 $aim = wp_specialchars($_POST['aim']);
    38 $yim = wp_specialchars($_POST['yim']);
    39 $email = wp_specialchars($_POST['email']);
    40 $url = wp_specialchars($_POST['url']);
    41 $url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $url) ? $url : 'http://' . $url;
    42 $user_description = $_POST['user_description'];
    43 
    44 $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'");
    45 
    46 update_usermeta( $user_ID, 'first_name', $first_name );
    47 update_usermeta( $user_ID, 'last_name', $last_name );
    48 update_usermeta( $user_ID, 'nickname', $nickname );
    49 update_usermeta( $user_ID, 'description', $user_description );
    50 update_usermeta( $user_ID, 'jabber', $jabber );
    51 update_usermeta( $user_ID, 'aim', $aim );
    52 update_usermeta( $user_ID, 'yim', $yim );
    53 
    54 do_action('profile_update', $user_ID);
    5515
    5616if ( 'profile' == $_POST['from'] )
  • trunk/wp-admin/profile.php

    r2844 r2872  
    2929<legend><?php _e('Name'); ?></legend>
    3030<p><label><?php _e('Username: (no editing)'); ?><br />
    31 <input type="text" name="username" value="<?php echo $profiledata->user_login; ?>" disabled="disabled" />
     31<input type="text" name="user_login" value="<?php echo $profiledata->user_login; ?>" disabled="disabled" />
    3232</label></p>
    3333<p><label><?php _e('First name:') ?><br />
     
    8484<legend><?php _e('About yourself'); ?></legend>
    8585<p class="desc"><?php _e('Share a little biographical information to fill out your profile. This may be shown publicly.'); ?></p>
    86 <p><textarea name="user_description" rows="5" cols="30"><?php echo $profiledata->user_description ?></textarea></p>
     86<p><textarea name="description" rows="5" cols="30"><?php echo $profiledata->description ?></textarea></p>
    8787</fieldset>
    8888
  • trunk/wp-admin/user-edit.php

    r2762 r2872  
    3434
    3535$errors = array();
    36 if(empty($wp_user)) {
    37     $wp_user = new WP_User($user_id);
    38     $edituser = &$wp_user->data;
    39 }
    4036
    41 if (!current_user_can('edit_users')) $errors['head'] = __('You do not have permission to edit this user.');
    42 
    43 /* checking the nickname has been typed */
    44 if (empty($_POST["new_nickname"])) {
    45     $errors['nickname'] = __("<strong>ERROR</strong>: please enter your nickname (can be the same as your username)");
    46 }
    47 
    48 $new_user_login  = wp_specialchars($_POST['new_user_login']);
    49 $pass1 = $_POST['pass1'];
    50 $pass2 = $_POST['pass2'];
    51 do_action('check_passwords', array($new_user_login, &$pass1, &$pass2));
    52 
    53 if ( '' == $pass1 ) {
    54     if ( '' != $pass2 )
    55         $errors['pass'] = __("<strong>ERROR</strong>: you typed your new password only once.");
    56     $updatepassword = '';
    57 } else {
    58     if ( '' == $pass2)
    59         $errors['pass'] = __("<strong>ERROR</strong>: you typed your new password only once.");
    60     if ( $pass1 != $pass2 )
    61         $errors['pass'] = __("<strong>ERROR</strong>: you typed two different passwords.");
    62     $new_pass = $pass1;
    63     $updatepassword = "user_pass=MD5('$new_pass'), ";
    64 }
    65 
    66 $edituser->user_login       = wp_specialchars($_POST['new_user_login']);
    67 $edituser->user_nicename    = sanitize_title($new_nickname, $user_id);
    68 $edituser->user_email       = wp_specialchars($_POST['new_email']);
    69 $edituser->user_url         = wp_specialchars($_POST['new_url']);
    70 $edituser->user_url         = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $edituser->user_url) ? $edituser->user_url : 'http://' . $edituser->user_url;
    71 $edituser->display_name     = wp_specialchars($_POST['display_name']);
    72 
    73 $edituser->first_name  = wp_specialchars($_POST['new_firstname']);
    74 $edituser->last_name   = wp_specialchars($_POST['new_lastname']);
    75 $edituser->nickname    = $_POST['new_nickname'];
    76 $edituser->icq         = wp_specialchars($_POST['new_icq']);
    77 $edituser->aim         = wp_specialchars($_POST['new_aim']);
    78 $edituser->msn         = wp_specialchars($_POST['new_msn']);
    79 $edituser->yim         = wp_specialchars($_POST['new_yim']);
    80 $edituser->description = $_POST['new_description'];
     37if (!current_user_can('edit_users'))
     38    $errors['head'] = __('You do not have permission to edit this user.');
     39else
     40    $errors = update_user($user_id);
    8141
    8242if(count($errors) == 0) {
    83     $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'");
    84    
    85     update_usermeta( $user_id, 'first_name', $edituser->firstname );
    86     update_usermeta( $user_id, 'last_name', $edituser->lastname );
    87     update_usermeta( $user_id, 'nickname', $edituser->nickname );
    88     update_usermeta( $user_id, 'description', $edituser->description );
    89     update_usermeta( $user_id, 'icq', $edituser->icq );
    90     update_usermeta( $user_id, 'aim', $edituser->aim );
    91     update_usermeta( $user_id, 'msn', $edituser->msn );
    92     update_usermeta( $user_id, 'yim', $edituser->yim );
    93    
    94     $wp_user->set_role($_POST['new_role']);
    95    
    9643    header("Location: user-edit.php?user_id=$user_id&updated=true");
    97 } else {
    98     $wp_user->roles = array($_POST['new_role'] => true);
     44    exit;
    9945}
    10046
     
    10248include ('admin-header.php');
    10349
    104 if(empty($wp_user)) {
    105     $wp_user = new WP_User($user_id);
    106     $edituser = &$wp_user->data;
    107 }
     50$profileuser = new WP_User($user_id);
     51$profiledata = $profileuser->data;
    10852
    10953if (!current_user_can('edit_users')) $errors['head'] = __('You do not have permission to edit this user.');
     
    11559</div>
    11660<?php endif; ?>
    117 <?php if ( isset($errors) ) : ?>
     61<?php if ( count($errors) != 0 ) : ?>
    11862<div class="error">
    11963    <ul>
     
    12771<div class="wrap">
    12872<h2><?php _e('Edit User'); ?></h2>
    129 <form name="edituser" id="edituser" action="user-edit.php" method="post">
    130 <table width="99%"  border="0" cellspacing="2" cellpadding="3">
    131     <tr>
    132         <th width="33%" scope="row"><?php _e('Username:') ?></th>
    133         <td width="73%"><input type="text" name="new_user_login" id="new_user_login" value="<?php echo $edituser->user_login; ?>" /></td>
    134     </tr>
    135     <tr>
    136         <th scope="row"><?php _e('Role:') ?></th>
    137         <td><select name="new_role" id="new_role"><?php
    138         foreach($wp_roles->role_names as $role => $name) {
    139             $selected = (empty($wp_user->roles[$role])) ? '' : 'selected="selected"';
    140             echo "<option {$selected} value=\"{$role}\">{$name}</option>";
    141         }
    142         ?></select></td>
    143     </tr>
    144     <tr>
    145         <th scope="row"><?php _e('Posts:') ?></th>
    146         <td><?php echo get_usernumposts($edituser->ID); ?></td>
    147     </tr>
    148 <?php if ( isset($edituser->user_registered) && ('0000-00-00 00:00:00' != $edituser->user_registered) ) { ?>
    149     <tr>
    150         <th scope="row"><?php _e('Registered on:') ?></th>
    151         <td><?php echo substr($edituser->user_registered, 0, 11); ?></td>
    152     </tr>
    153 <?php } ?>
    154     <tr>
    155         <th scope="row"><?php _e('First name:') ?></th>
    156         <td><input type="text" name="new_firstname" id="new_firstname" value="<?php echo $edituser->first_name ?>" /></td>
    157     </tr>
    158     <tr>
    159         <th scope="row"><?php _e('Last name:') ?></th>
    160         <td><input type="text" name="new_lastname" id="new_lastname2" value="<?php echo $edituser->last_name ?>" /></td>
    161     </tr>
    162     <tr>
    163         <th scope="row"><?php _e('Profile:') ?></th>
    164         <td><textarea name="new_description" rows="5" id="new_description" style="width: 99%; "><?php echo $edituser->description ?></textarea></td>
    165     </tr>
    166     <tr>
    167         <th scope="row"><?php _e('Nickname:') ?></th>
    168         <td><input type="text" name="new_nickname" id="new_nickname" value="<?php echo $edituser->nickname ?>" /></td>
    169     </tr>
    170     <tr>
    171         <th scope="row"><?php _e('E-mail:') ?></th>
    172         <td><input type="text" name="new_email" id="new_email" value="<?php echo $edituser->user_email ?>" /></td>
    173     </tr>
    174     <tr>
    175         <th scope="row"><?php _e('Website:') ?></th>
    176         <td><input type="text" name="new_url" id="new_url" value="<?php echo $edituser->user_url ?>" /></td>
    177     </tr>
    178     <tr>
    179         <th scope="row"><?php _e('ICQ:') ?></th>
    180         <td><input type="text" name="new_icq" id="new_icq" value="<?php if ($edituser->icq > 0) { echo $edituser->icq; } ?>" /></td>
    181     </tr>
    182     <tr>
    183         <th scope="row"><?php _e('AIM:') ?></th>
    184         <td><input type="text" name="new_aim" id="new_aim" value="<?php echo $edituser->aim ?>" /></td>
    185     </tr>
    186     <tr>
    187         <th scope="row"><?php _e('MSN IM:') ?>
    188         </th>
    189         <td><input type="text" name="new_msn" id="new_msn" value="<?php echo $edituser->msn ?>" /></td>
    190     </tr>
    191     <tr>
    192         <th scope="row"><?php _e('Yahoo IM:') ?>
    193         </th>
    194         <td><input type="text" name="new_yim" id="new_yim" value="<?php echo $edituser->yim ?>" />
    195         </td>
    196     </tr>
    197     <tr>
    198         <th scope="row"><?php _e('Identity on blog:') ?>
    199         </th>
    200         <td>    <select name="display_name">
    201         <option value="<?php echo $edituser->display_name; ?>"><?php echo $edituser->display_name; ?></option>
    202         <option value="<?php echo $edituser->nickname ?>"><?php echo $edituser->nickname ?></option>
    203         <option value="<?php echo $edituser->user_login ?>"><?php echo $edituser->user_login ?></option>
    204     <?php if ( !empty( $edituser->first_name ) ) : ?>
    205         <option value="<?php echo $edituser->first_name ?>"><?php echo $edituser->first_name ?></option>
    206     <?php endif; ?>
    207     <?php if ( !empty( $edituser->last_name ) ) : ?>
    208         <option value="<?php echo $edituser->last_name ?>"><?php echo $edituser->last_name ?></option>
    209     <?php endif; ?>
    210     <?php if ( !empty( $edituser->first_name ) && !empty( $edituser->last_name ) ) : ?>
    211         <option value="<?php echo $edituser->first_name." ".$edituser->last_name ?>"><?php echo $edituser->first_name." ".$edituser->last_name ?></option>
    212         <option value="<?php echo $edituser->last_name." ".$edituser->first_name ?>"><?php echo $edituser->last_name." ".$edituser->first_name ?></option>
    213     <?php endif; ?>
    214       </select>
    215         </td>
    216     </tr>
     73
     74<form name="profile" id="your-profile" action="user-edit.php" method="post">
     75<p>
     76<input type="hidden" name="from" value="profile" />
     77<input type="hidden" name="checkuser_id" value="<?php echo $user_ID ?>" />
     78</p>
     79
     80<fieldset>
     81<legend><?php _e('Name'); ?></legend>
     82<p><label><?php _e('Username: (no editing)'); ?><br />
     83<input type="text" name="user_login" value="<?php echo $profiledata->user_login; ?>" disabled="disabled" />
     84</label></p>
     85<p><label><?php _e('First name:') ?><br />
     86<input type="text" name="first_name" value="<?php echo $profiledata->first_name ?>" /></label></p>
     87
     88<p><label><?php _e('Last name:') ?><br />
     89<input type="text" name="last_name"  value="<?php echo $profiledata->last_name ?>" /></label></p>
     90
     91<p><label><?php _e('Nickname:') ?><br />
     92<input type="text" name="nickname" value="<?php echo $profiledata->nickname ?>" /></label></p>
     93
     94</p><label><?php _e('Display name publicly as:') ?> <br />
     95<select name="display_name">
     96<option value="<?php echo $profiledata->display_name; ?>"><?php echo $profiledata->display_name; ?></option>
     97<option value="<?php echo $profiledata->nickname ?>"><?php echo $profiledata->nickname ?></option>
     98<option value="<?php echo $profiledata->user_login ?>"><?php echo $profiledata->user_login ?></option>
     99<?php if ( !empty( $profiledata->first_name ) ) : ?>
     100<option value="<?php echo $profiledata->first_name ?>"><?php echo $profiledata->first_name ?></option>
     101<?php endif; ?>
     102<?php if ( !empty( $profiledata->last_name ) ) : ?>
     103<option value="<?php echo $profiledata->last_name ?>"><?php echo $profiledata->last_name ?></option>
     104<?php endif; ?>
     105<?php if ( !empty( $profiledata->first_name ) && !empty( $profiledata->last_name ) ) : ?>
     106<option value="<?php echo $profiledata->first_name." ".$profiledata->last_name ?>"><?php echo $profiledata->first_name." ".$profiledata->last_name ?></option>
     107<option value="<?php echo $profiledata->last_name." ".$profiledata->first_name ?>"><?php echo $profiledata->last_name." ".$profiledata->first_name ?></option>
     108<?php endif; ?>
     109</select></label></p>
     110</fieldset>
     111
     112<fieldset>
     113<legend><?php _e('Contact Info'); ?></legend>
     114
     115<p><label><?php _e('E-mail: (required)') ?><br />
     116<input type="text" name="email" value="<?php echo $profiledata->user_email ?>" /></label></p>
     117
     118<p><label><?php _e('Website:') ?><br />
     119<input type="text" name="url" value="<?php echo $profiledata->user_url ?>" />
     120</label></p>
     121
     122<p><label><?php _e('AIM:') ?><br />
     123<input type="text" name="aim" value="<?php echo $profiledata->aim ?>" />
     124</label></p>
     125
     126<p><label><?php _e('Yahoo IM:') ?><br />
     127<input type="text" name="yim" value="<?php echo $profiledata->yim ?>" />
     128</label></p>
     129
     130<p><label><?php _e('Jabber / Google Talk:') ?>
     131<input type="text" name="jabber" value="<?php echo $profiledata->jabber ?>" /></label>
     132</p>
     133</fieldset>
     134<br clear="all" />
     135<fieldset>
     136<legend><?php _e('About the user'); ?></legend>
     137<p class="desc"><?php _e('Share a little biographical information to fill out your profile. This may be shown publicly.'); ?></p>
     138<p><textarea name="description" rows="5" cols="30"><?php echo $profiledata->description ?></textarea></p>
     139</fieldset>
     140
    217141<?php
    218 do_action('edit_user_profile');
    219 
    220142$show_password_fields = apply_filters('show_password_fields', true);
    221143if ( $show_password_fields ) :
    222144?>
    223     <tr>
    224         <th scope="row"><?php _e('New <strong>Password</strong> (Leave blank to stay the same.)') ?></th>
    225         <td><input type="password" name="pass1" size="16" value="" />
    226             <br />
    227             <input type="password" name="pass2" size="16" value="" /></td>
    228     </tr>
     145<fieldset>
     146<legend><?php _e("Update User's Password"); ?></legend>
     147<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>
     148<p><label><?php _e('New Password:'); ?><br />
     149<input type="password" name="pass1" size="16" value="" />
     150</label></p>
     151<p><label><?php _e('Type it one more time:'); ?><br />
     152<input type="password" name="pass2" size="16" value="" />
     153</label></p>
     154</fieldset>
    229155<?php endif; ?>
    230 </table>
    231   <p class="submit">
     156
     157<?php do_action('edit_user_profile'); ?>
     158
     159<br clear="all" />
     160  <table width="99%"  border="0" cellspacing="2" cellpadding="3" class="editform">
     161    <?php
     162    if(count($profileuser->caps) > count($profileuser->roles)):
     163    ?>
     164    <tr>
     165      <th scope="row"><?php _e('Additional Capabilities:') ?></th>
     166      <td><?php
     167            $output = '';
     168            foreach($profileuser->caps as $cap => $value) {
     169                if(!$wp_roles->is_role($cap)) {
     170                    if($output != '') $output .= ', ';
     171                    $output .= $value ? $cap : "Denied: {$cap}";
     172                }
     173            }
     174            echo $output;
     175            ?></td>
     176    </tr>
     177    <?php
     178    endif;
     179    ?>
     180  </table>
     181<p class="submit">
    232182    <input type="hidden" name="action" value="update" />
    233183    <input type="hidden" name="user_id" id="user_id" value="<?php echo $user_id; ?>" />
    234184    <input type="submit" value="<?php _e('Update User &raquo;') ?>" name="submit" />
    235   </p>
     185 </p>
    236186</form>
    237187</div>
    238 
    239188<?php
    240189break;
  • trunk/wp-admin/users.php

    r2847 r2872  
    111111case 'adduser':
    112112    check_admin_referer();
    113 
    114     $new_user_login     = wp_specialchars(trim($_POST['user_login']));
    115     $new_pass1          = $_POST['pass1'];
    116     $new_pass2          = $_POST['pass2'];
    117     $new_user_email     = wp_specialchars(trim($_POST['email']));
    118     $new_user_firstname = wp_specialchars(trim($_POST['firstname']));
    119     $new_user_lastname  = wp_specialchars(trim($_POST['lastname']));
    120     $new_user_uri       = wp_specialchars(trim($_POST['uri']));
    121    
    122     $errors = array();
    123        
    124     /* checking that username has been typed */
    125     if ($new_user_login == '')
    126         $errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.');
    127 
    128     /* checking the password has been typed twice */
    129     do_action('check_passwords', array($new_user_login, &$new_pass1, &$new_pass2));
    130     if ($new_pass1 == '' || $new_pass2 == '')
    131         $errors['pass'] = __('<strong>ERROR</strong>: Please enter your password twice.');
    132 
    133     /* checking the password has been typed twice the same */
    134     if ($new_pass1 != $new_pass2)
    135         $errors['pass'] = __('<strong>ERROR</strong>: Please type the same password in the two password fields.');
    136 
    137     $new_user_nickname = $new_user_login;
    138 
    139   if ( username_exists( $new_user_login ) )
    140         $errors['pass'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');
    141 
    142     /* checking e-mail address */
    143     if (empty($new_user_email)) {
    144         $errors['user_email'] = __("<strong>ERROR</strong>: please type an e-mail address");
    145     } else if (!is_email($new_user_email)) {
    146         $errors['user_email'] = __("<strong>ERROR</strong>: the email address isn't correct");
    147     }
    148 
    149     if(count($errors) == 0) {   
    150         $user_ID = create_user( $new_user_login, $new_pass1, $new_user_email, 0 );
    151 
    152         update_usermeta( $user_ID, 'first_name', $new_user_firstname);
    153         update_usermeta( $user_ID, 'last_name', $new_user_lastname);
    154         update_usermeta( $user_ID, 'first_name', $new_user_firstname);
    155        
    156         $user = new WP_User($user_ID);
    157         $user->set_role(get_settings('default_role'));
    158        
    159         $stars = '';
    160         for ($i = 0; $i < strlen($pass1); $i = $i + 1)
    161             $stars .= '*';
    162    
    163         $user_login = stripslashes($new_user_login);
    164         $message  = sprintf(__('New user registration on your blog %s:'), get_settings('blogname')) . "\r\n\r\n";
    165         $message .= sprintf(__('Username: %s'), $new_user_login) . "\r\n\r\n";
    166         $message .= sprintf(__('E-mail: %s'), $new_user_email) . "\r\n";
    167    
    168         @wp_mail(get_settings('admin_email'), sprintf(__('[%s] New User Registration'), get_settings('blogname')), $message);
    169 
    170         do_action('user_register', $user_id);
    171 
     113   
     114    $errors = add_user();
     115   
     116    if(count($errors) == 0) {
    172117        header('Location: users.php?update=add');
    173118        die();
     
    311256    <tr>
    312257      <th scope="row"><?php _e('First Name') ?> </th>
    313       <td><input name="firstname" type="text" id="firstname" value="<?php echo $new_user_firstname; ?>" /></td>
     258      <td><input name="first_name" type="text" id="first_name" value="<?php echo $new_user_firstname; ?>" /></td>
    314259    </tr>
    315260    <tr>
    316261      <th scope="row"><?php _e('Last Name') ?> </th>
    317       <td><input name="lastname" type="text" id="lastname" value="<?php echo $new_user_lastname; ?>" /></td>
     262      <td><input name="last_name" type="text" id="last_name" value="<?php echo $new_user_lastname; ?>" /></td>
    318263    </tr>
    319264    <tr>
     
    323268    <tr>
    324269      <th scope="row"><?php _e('Website') ?></th>
    325       <td><input name="uri" type="text" id="uri" value="<?php echo $new_user_uri; ?>" /></td>
     270      <td><input name="url" type="text" id="url" value="<?php echo $new_user_uri; ?>" /></td>
    326271    </tr>
    327272<?php
  • trunk/wp-includes/functions.php

    r2856 r2872  
    12641264}
    12651265
     1266function clean_user_cache($id) {
     1267    if ( isset( $cache_userdata[$id] ) )
     1268        unset( $cache_userdata[$id] );
     1269}
     1270
    12661271function wp_head() {
    12671272    do_action('wp_head');
  • trunk/wp-includes/pluggable-functions.php

    r2827 r2872  
    320320endif;
    321321
     322if ( !function_exists('wp_new_user_notification') ) :
     323function wp_new_user_notification($user_id, $plaintext_pass = '') {
     324    $user = new WP_User($user_id);
     325   
     326    $stars = '';
     327    for ($i = 0; $i < strlen($pass1); $i = $i + 1)
     328        $stars .= '*';
     329   
     330    $user_login = stripslashes($user->data->user_login);
     331    $user_email = stripslashes($user->data->user_email);
     332   
     333    $message  = sprintf(__('New user registration on your blog %s:'), get_settings('blogname')) . "\r\n\r\n";
     334    $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
     335    $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
     336   
     337    @wp_mail(get_settings('admin_email'), sprintf(__('[%s] New User Registration'), get_settings('blogname')), $message);
     338
     339    if ( empty($plaintext_pass) )
     340        return;
     341
     342    $message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
     343    $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
     344    $message .= get_settings('siteurl') . "/wp-login.php\r\n";
     345       
     346    wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_settings('blogname')), $message);
     347   
     348}
     349endif;
     350
    322351?>
  • trunk/wp-includes/registration-functions.php

    r2735 r2872  
    99}
    1010
    11 function create_user( $username, $password, $email, $user_level ) {
     11function wp_insert_user($userdata) {
    1212    global $wpdb;
    13     $username = $wpdb->escape( $username );
    14     $email    = $wpdb->escape( $email );
    15     $password = md5( $password );
    16     $user_nicename = sanitize_title( $username );
    17     $now = gmdate('Y-m-d H:i:s');
    1813
    19     $query = "INSERT INTO $wpdb->users
    20         (user_login, user_pass, user_email, user_registered, user_nicename, display_name)
     14    extract($userdata);
     15
     16    // Are we updating or creating?
     17    if ( !empty($ID) ) {
     18        $update = true;
     19    } else {
     20        $update = false;
     21        // Password is not hashed when creating new user.
     22        $user_pass = md5($user_pass);
     23    }
     24   
     25    if ( empty($user_nicename) )
     26        $user_nicename = sanitize_title( $user_login );
     27
     28    if ( empty($display_name) )
     29        $display_name = $user_login;
     30       
     31    if ( empty($nickname) )
     32        $nickname = $user_login;
     33           
     34    if ( empty($user_registered) )
     35        $user_registered = gmdate('Y-m-d H:i:s');
     36
     37    if ( $update ) {
     38        $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'";
     39        $query = apply_filters('update_user_query', $query);
     40        $wpdb->query( $query );
     41        $user_id = $ID;
     42    } else {
     43        $query = "INSERT INTO $wpdb->users
     44        (user_login, user_pass, user_email, user_url, user_registered, user_nicename, display_name)
    2145    VALUES
    22         ('$username', '$password', '$email', '$now', '$user_nicename', '$username')";
    23     $query = apply_filters('create_user_query', $query);
    24     $wpdb->query( $query );
    25     $user_id = $wpdb->insert_id;
     46        ('$user_login', '$user_pass', '$user_email', '$user_url', '$user_registered', '$user_nicename', '$display_name')";
     47        $query = apply_filters('create_user_query', $query);
     48        $wpdb->query( $query );
     49        $user_id = $wpdb->insert_id;
     50    }
     51   
     52    clean_user_cache($user_id);
     53    clean_user_cache($user_login);
    2654
    27     $user_level = (int) $user_level;
    28     update_usermeta( $user_id, $wpdb->prefix . 'user_level', $user_level);
    29     $user = new WP_User($user_id);
    30     $user->set_role(get_settings('default_role'));
     55    update_usermeta( $user_id, 'first_name', $first_name);
     56    update_usermeta( $user_id, 'last_name', $last_name);
     57    update_usermeta( $user_id, 'nickname', $nickname );
     58    update_usermeta( $user_id, 'description', $description );
     59    update_usermeta( $user_id, 'jabber', $jabber );
     60    update_usermeta( $user_id, 'aim', $aim );
     61    update_usermeta( $user_id, 'yim', $yim );
     62   
     63    if ( !$update ) {
     64        $user = new WP_User($user_id);
     65        $user->set_role(get_settings('default_role'));
     66    }
     67   
     68    if ( $update )
     69        do_action('profile_update', $user_id);
     70    else
     71        do_action('user_register', $user_id);
     72       
     73    return $user_id;   
     74}
     75
     76function wp_update_user($userdata) {
     77    global $wpdb;
     78
     79    $ID = (int) $userdata['ID'];
     80   
     81    // First, get all of the original fields
     82    $user = get_userdata($ID); 
     83
     84    // Escape data pulled from DB.
     85    $user = add_magic_quotes(get_object_vars($user));
     86
     87    // If password is changing, hash it now.
     88    if ( ! empty($userdata['user_pass']) ) {
     89        $plaintext_pass = $userdata['user_pass'];
     90        $userdata['user_pass'] = md5($userdata['user_pass']);
     91    }
     92   
     93    // Merge old and new fields with new fields overwriting old ones.
     94    $userdata = array_merge($user, $userdata);
     95    $user_id = wp_insert_user($userdata);
     96
     97    // Update the cookies if the password changed. 
     98    if ( isset($plaintext_pass) ) {
     99        wp_clearcookie();
     100        wp_setcookie($userdata['user_login'], $plaintext_pass);
     101    }
    31102   
    32103    return $user_id;
    33104}
    34105
     106function wp_create_user( $username, $password, $email ) {
     107    global $wpdb;
     108   
     109    $user_login = $wpdb->escape( $username );
     110    $user_email = $wpdb->escape( $email );
     111    $user_pass = $password;
     112
     113    $userdata = compact('user_login', 'user_email', 'user_pass');
     114    return wp_insert_user($userdata);
     115}
     116
     117
     118function create_user( $username, $password, $email ) {
     119    return wp_create_user( $username, $password, $email ); 
     120}
     121
     122
    35123?>
  • trunk/wp-register.php

    r2732 r2872  
    3131        $errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');
    3232
    33     $password = substr( md5( uniqid( microtime() ) ), 0, 7);
     33    if ( 0 == count($errors) ) {
     34        $password = substr( md5( uniqid( microtime() ) ), 0, 7);
    3435
    35     $user_id = create_user( $user_login, $password, $user_email, 0 );
    36     if ( !$user_id ) {
    37         $errors['user_id'] = sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_settings('admin_email'));
     36        $user_id = wp_create_user( $user_login, $password, $user_email );
     37        if ( !$user_id )
     38            $errors['user_id'] = sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_settings('admin_email'));
     39        else
     40            wp_new_user_notification($user_id, $password);
    3841    }
    39 
    40     if(count($errors) == 0) {
    41         $user = new WP_User($user_id);
    42         $user->set_role(get_settings('default_role'));
    4342   
    44         do_action('user_register', $user_id);
    45    
    46    
    47         $stars = '';
    48         for ($i = 0; $i < strlen($pass1); $i = $i + 1) {
    49             $stars .= '*';
    50         }
    51        
    52         $message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
    53         $message .= sprintf(__('Password: %s'), $password) . "\r\n";
    54         $message .= get_settings('siteurl') . "/wp-login.php\r\n";
    55        
    56         wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_settings('blogname')), $message);
    57    
    58         $message  = sprintf(__('New user registration on your blog %s:'), get_settings('blogname')) . "\r\n\r\n";
    59         $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
    60         $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
    61    
    62         @wp_mail(get_settings('admin_email'), sprintf(__('[%s] New User Registration'), get_settings('blogname')), $message);
    63 
     43    if ( 0 == count($errors) ) {
     44           
    6445    ?>
    6546<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Note: See TracChangeset for help on using the changeset viewer.