Make WordPress Core

Changeset 16009


Ignore:
Timestamp:
10/27/2010 10:46:24 AM (13 years ago)
Author:
nacin
Message:

Move registration.php functions to user.php. Deprecate registration.php, everything is now included by default. fixes #13761.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-activate.php

    r16007 r16009  
    1111    die();
    1212}
    13 
    14 require_once( ABSPATH . WPINC . '/registration.php');
    1513
    1614if ( is_object( $wp_object_cache ) )
  • trunk/wp-admin/admin-ajax.php

    r15963 r16009  
    854854    if ( !current_user_can('create_users') )
    855855        die('-1');
    856     require_once(ABSPATH . WPINC . '/registration.php');
    857856    if ( !$user_id = add_user() )
    858857        die('0');
  • trunk/wp-admin/includes/admin.php

    r15954 r16009  
    5252require_once(ABSPATH . 'wp-admin/includes/update.php');
    5353
    54 /** WordPress Registration API */
    55 require_once(ABSPATH . WPINC . '/registration.php');
    56 
    5754/** WordPress Deprecated Administration API */
    5855require_once(ABSPATH . 'wp-admin/includes/deprecated.php');
  • trunk/wp-admin/user-new.php

    r15830 r16009  
    1515if ( is_multisite() && !get_site_option( 'add_new_users' ) )
    1616    wp_die( __('Page disabled by the administrator') );
    17 
    18 /** WordPress Registration API */
    19 require_once( ABSPATH . WPINC . '/registration.php');
    2017
    2118if ( is_multisite() ) {
  • trunk/wp-admin/users.php

    r15956 r16009  
    99/** WordPress Administration Bootstrap */
    1010require_once( './admin.php' );
    11 
    12 /** WordPress Registration API */
    13 require_once( ABSPATH . WPINC . '/registration.php');
    1411
    1512$wp_list_table = get_list_table('WP_Users_Table');
  • trunk/wp-includes/registration-functions.php

    r12535 r16009  
    11<?php
    22/**
    3  * Deprecated. Use registration.php.
     3 * Deprecated. No longer needed.
    44 *
    55 * @package WordPress
    66 */
    7 _deprecated_file( basename(__FILE__), '2.1', WPINC .  '/registration.php' );
    8 require_once(ABSPATH . WPINC .  '/registration.php');
     7_deprecated_file( basename(__FILE__), '2.1', null, __( 'This file no longer needs to be included.' ) );
    98?>
  • trunk/wp-includes/registration.php

    r15896 r16009  
    11<?php
    22/**
    3  * User Registration API
     3 * Deprecated. No longer needed.
    44 *
    55 * @package WordPress
    66 */
    7 
    8 /**
    9  * Checks whether the given username exists.
    10  *
    11  * @since 2.0.0
    12  *
    13  * @param string $username Username.
    14  * @return null|int The user's ID on success, and null on failure.
    15  */
    16 function username_exists( $username ) {
    17     if ( $user = get_userdatabylogin( $username ) ) {
    18         return $user->ID;
    19     } else {
    20         return null;
    21     }
    22 }
    23 
    24 /**
    25  * Checks whether the given email exists.
    26  *
    27  * @since 2.1.0
    28  * @uses $wpdb
    29  *
    30  * @param string $email Email.
    31  * @return bool|int The user's ID on success, and false on failure.
    32  */
    33 function email_exists( $email ) {
    34     if ( $user = get_user_by_email($email) )
    35         return $user->ID;
    36 
    37     return false;
    38 }
    39 
    40 /**
    41  * Checks whether an username is valid.
    42  *
    43  * @since 2.0.1
    44  * @uses apply_filters() Calls 'validate_username' hook on $valid check and $username as parameters
    45  *
    46  * @param string $username Username.
    47  * @return bool Whether username given is valid
    48  */
    49 function validate_username( $username ) {
    50     $sanitized = sanitize_user( $username, true );
    51     $valid = ( $sanitized == $username );
    52     return apply_filters( 'validate_username', $valid, $username );
    53 }
    54 
    55 /**
    56  * Insert an user into the database.
    57  *
    58  * Can update a current user or insert a new user based on whether the user's ID
    59  * is present.
    60  *
    61  * Can be used to update the user's info (see below), set the user's role, and
    62  * set the user's preference on whether they want the rich editor on.
    63  *
    64  * Most of the $userdata array fields have filters associated with the values.
    65  * The exceptions are 'rich_editing', 'role', 'jabber', 'aim', 'yim',
    66  * 'user_registered', and 'ID'. The filters have the prefix 'pre_user_' followed
    67  * by the field name. An example using 'description' would have the filter
    68  * called, 'pre_user_description' that can be hooked into.
    69  *
    70  * The $userdata array can contain the following fields:
    71  * 'ID' - An integer that will be used for updating an existing user.
    72  * 'user_pass' - A string that contains the plain text password for the user.
    73  * 'user_login' - A string that contains the user's username for logging in.
    74  * 'user_nicename' - A string that contains a nicer looking name for the user.
    75  *      The default is the user's username.
    76  * 'user_url' - A string containing the user's URL for the user's web site.
    77  * 'user_email' - A string containing the user's email address.
    78  * 'display_name' - A string that will be shown on the site. Defaults to user's
    79  *      username. It is likely that you will want to change this, for both
    80  *      appearance and security through obscurity (that is if you don't use and
    81  *      delete the default 'admin' user).
    82  * 'nickname' - The user's nickname, defaults to the user's username.
    83  * 'first_name' - The user's first name.
    84  * 'last_name' - The user's last name.
    85  * 'description' - A string containing content about the user.
    86  * 'rich_editing' - A string for whether to enable the rich editor. False
    87  *      if not empty.
    88  * 'user_registered' - The date the user registered. Format is 'Y-m-d H:i:s'.
    89  * 'role' - A string used to set the user's role.
    90  * 'jabber' - User's Jabber account.
    91  * 'aim' - User's AOL IM account.
    92  * 'yim' - User's Yahoo IM account.
    93  *
    94  * @since 2.0.0
    95  * @uses $wpdb WordPress database layer.
    96  * @uses apply_filters() Calls filters for most of the $userdata fields with the prefix 'pre_user'. See note above.
    97  * @uses do_action() Calls 'profile_update' hook when updating giving the user's ID
    98  * @uses do_action() Calls 'user_register' hook when creating a new user giving the user's ID
    99  *
    100  * @param array $userdata An array of user data.
    101  * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not be created.
    102  */
    103 function wp_insert_user($userdata) {
    104     global $wpdb;
    105 
    106     extract($userdata, EXTR_SKIP);
    107 
    108     // Are we updating or creating?
    109     if ( !empty($ID) ) {
    110         $ID = (int) $ID;
    111         $update = true;
    112         $old_user_data = get_userdata($ID);
    113     } else {
    114         $update = false;
    115         // Hash the password
    116         $user_pass = wp_hash_password($user_pass);
    117     }
    118 
    119     $user_login = sanitize_user($user_login, true);
    120     $user_login = apply_filters('pre_user_login', $user_login);
    121 
    122     //Remove any non-printable chars from the login string to see if we have ended up with an empty username
    123     $user_login = trim($user_login);
    124 
    125     if ( empty($user_login) )
    126         return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') );
    127 
    128     if ( !$update && username_exists( $user_login ) )
    129         return new WP_Error('existing_user_login', __('This username is already registered.') );
    130 
    131     if ( empty($user_nicename) )
    132         $user_nicename = sanitize_title( $user_login );
    133     $user_nicename = apply_filters('pre_user_nicename', $user_nicename);
    134 
    135     if ( empty($user_url) )
    136         $user_url = '';
    137     $user_url = apply_filters('pre_user_url', $user_url);
    138 
    139     if ( empty($user_email) )
    140         $user_email = '';
    141     $user_email = apply_filters('pre_user_email', $user_email);
    142 
    143     if ( !$update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) )
    144         return new WP_Error('existing_user_email', __('This email address is already registered.') );
    145 
    146     if ( empty($display_name) )
    147         $display_name = $user_login;
    148     $display_name = apply_filters('pre_user_display_name', $display_name);
    149 
    150     if ( empty($nickname) )
    151         $nickname = $user_login;
    152     $nickname = apply_filters('pre_user_nickname', $nickname);
    153 
    154     if ( empty($first_name) )
    155         $first_name = '';
    156     $first_name = apply_filters('pre_user_first_name', $first_name);
    157 
    158     if ( empty($last_name) )
    159         $last_name = '';
    160     $last_name = apply_filters('pre_user_last_name', $last_name);
    161 
    162     if ( empty($description) )
    163         $description = '';
    164     $description = apply_filters('pre_user_description', $description);
    165 
    166     if ( empty($rich_editing) )
    167         $rich_editing = 'true';
    168 
    169     if ( empty($comment_shortcuts) )
    170         $comment_shortcuts = 'false';
    171 
    172     if ( empty($admin_color) )
    173         $admin_color = 'fresh';
    174     $admin_color = preg_replace('|[^a-z0-9 _.\-@]|i', '', $admin_color);
    175 
    176     if ( empty($use_ssl) )
    177         $use_ssl = 0;
    178 
    179     if ( empty($user_registered) )
    180         $user_registered = gmdate('Y-m-d H:i:s');
    181 
    182     $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $user_nicename, $user_login));
    183 
    184     if ( $user_nicename_check ) {
    185         $suffix = 2;
    186         while ($user_nicename_check) {
    187             $alt_user_nicename = $user_nicename . "-$suffix";
    188             $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $alt_user_nicename, $user_login));
    189             $suffix++;
    190         }
    191         $user_nicename = $alt_user_nicename;
    192     }
    193 
    194     $data = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
    195     $data = stripslashes_deep( $data );
    196 
    197     if ( $update ) {
    198         $wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
    199         $user_id = (int) $ID;
    200     } else {
    201         $wpdb->insert( $wpdb->users, $data + compact( 'user_login' ) );
    202         $user_id = (int) $wpdb->insert_id;
    203     }
    204 
    205     update_user_meta( $user_id, 'first_name', $first_name);
    206     update_user_meta( $user_id, 'last_name', $last_name);
    207     update_user_meta( $user_id, 'nickname', $nickname );
    208     update_user_meta( $user_id, 'description', $description );
    209     update_user_meta( $user_id, 'rich_editing', $rich_editing);
    210     update_user_meta( $user_id, 'comment_shortcuts', $comment_shortcuts);
    211     update_user_meta( $user_id, 'admin_color', $admin_color);
    212     update_user_meta( $user_id, 'use_ssl', $use_ssl);
    213 
    214     $user = new WP_User($user_id);
    215 
    216     foreach ( _wp_get_user_contactmethods( $user ) as $method => $name ) {
    217         if ( empty($$method) )
    218             $$method = '';
    219 
    220         update_user_meta( $user_id, $method, $$method );
    221     }
    222 
    223     if ( isset($role) )
    224         $user->set_role($role);
    225     elseif ( !$update )
    226         $user->set_role(get_option('default_role'));
    227 
    228     wp_cache_delete($user_id, 'users');
    229     wp_cache_delete($user_login, 'userlogins');
    230 
    231     if ( $update )
    232         do_action('profile_update', $user_id, $old_user_data);
    233     else
    234         do_action('user_register', $user_id);
    235 
    236     return $user_id;
    237 }
    238 
    239 /**
    240  * Update an user in the database.
    241  *
    242  * It is possible to update a user's password by specifying the 'user_pass'
    243  * value in the $userdata parameter array.
    244  *
    245  * If $userdata does not contain an 'ID' key, then a new user will be created
    246  * and the new user's ID will be returned.
    247  *
    248  * If current user's password is being updated, then the cookies will be
    249  * cleared.
    250  *
    251  * @since 2.0.0
    252  * @see wp_insert_user() For what fields can be set in $userdata
    253  * @uses wp_insert_user() Used to update existing user or add new one if user doesn't exist already
    254  *
    255  * @param array $userdata An array of user data.
    256  * @return int The updated user's ID.
    257  */
    258 function wp_update_user($userdata) {
    259     $ID = (int) $userdata['ID'];
    260 
    261     // First, get all of the original fields
    262     $user = get_userdata($ID);
    263 
    264     // Escape data pulled from DB.
    265     $user = add_magic_quotes(get_object_vars($user));
    266 
    267     // If password is changing, hash it now.
    268     if ( ! empty($userdata['user_pass']) ) {
    269         $plaintext_pass = $userdata['user_pass'];
    270         $userdata['user_pass'] = wp_hash_password($userdata['user_pass']);
    271     }
    272 
    273     wp_cache_delete($user[ 'user_email' ], 'useremail');
    274 
    275     // Merge old and new fields with new fields overwriting old ones.
    276     $userdata = array_merge($user, $userdata);
    277     $user_id = wp_insert_user($userdata);
    278 
    279     // Update the cookies if the password changed.
    280     $current_user = wp_get_current_user();
    281     if ( $current_user->id == $ID ) {
    282         if ( isset($plaintext_pass) ) {
    283             wp_clear_auth_cookie();
    284             wp_set_auth_cookie($ID);
    285         }
    286     }
    287 
    288     return $user_id;
    289 }
    290 
    291 /**
    292  * A simpler way of inserting an user into the database.
    293  *
    294  * Creates a new user with just the username, password, and email. For a more
    295  * detail creation of a user, use wp_insert_user() to specify more infomation.
    296  *
    297  * @since 2.0.0
    298  * @see wp_insert_user() More complete way to create a new user
    299  *
    300  * @param string $username The user's username.
    301  * @param string $password The user's password.
    302  * @param string $email The user's email (optional).
    303  * @return int The new user's ID.
    304  */
    305 function wp_create_user($username, $password, $email = '') {
    306     $user_login = esc_sql( $username );
    307     $user_email = esc_sql( $email    );
    308     $user_pass = $password;
    309 
    310     $userdata = compact('user_login', 'user_email', 'user_pass');
    311     return wp_insert_user($userdata);
    312 }
    313 
    314 
    315 /**
    316  * Set up the default contact methods
    317  *
    318  * @access private
    319  * @since
    320  *
    321  * @param object $user User data object (optional)
    322  * @return array $user_contactmethods Array of contact methods and their labels.
    323  */
    324 function _wp_get_user_contactmethods( $user = null ) {
    325     $user_contactmethods = array(
    326         'aim' => __('AIM'),
    327         'yim' => __('Yahoo IM'),
    328         'jabber' => __('Jabber / Google Talk')
    329     );
    330     return apply_filters( 'user_contactmethods', $user_contactmethods, $user );
    331 }
    332 
     7_deprecated_file( basename(__FILE__), '3.1', null, __( 'This file no longer needs to be included.' ) );
    3338?>
  • trunk/wp-includes/user.php

    r15883 r16009  
    11971197}
    11981198
     1199/**
     1200 * Checks whether the given username exists.
     1201 *
     1202 * @since 2.0.0
     1203 *
     1204 * @param string $username Username.
     1205 * @return null|int The user's ID on success, and null on failure.
     1206 */
     1207function username_exists( $username ) {
     1208    if ( $user = get_userdatabylogin( $username ) ) {
     1209        return $user->ID;
     1210    } else {
     1211        return null;
     1212    }
     1213}
     1214
     1215/**
     1216 * Checks whether the given email exists.
     1217 *
     1218 * @since 2.1.0
     1219 * @uses $wpdb
     1220 *
     1221 * @param string $email Email.
     1222 * @return bool|int The user's ID on success, and false on failure.
     1223 */
     1224function email_exists( $email ) {
     1225    if ( $user = get_user_by_email($email) )
     1226        return $user->ID;
     1227
     1228    return false;
     1229}
     1230
     1231/**
     1232 * Checks whether an username is valid.
     1233 *
     1234 * @since 2.0.1
     1235 * @uses apply_filters() Calls 'validate_username' hook on $valid check and $username as parameters
     1236 *
     1237 * @param string $username Username.
     1238 * @return bool Whether username given is valid
     1239 */
     1240function validate_username( $username ) {
     1241    $sanitized = sanitize_user( $username, true );
     1242    $valid = ( $sanitized == $username );
     1243    return apply_filters( 'validate_username', $valid, $username );
     1244}
     1245
     1246/**
     1247 * Insert an user into the database.
     1248 *
     1249 * Can update a current user or insert a new user based on whether the user's ID
     1250 * is present.
     1251 *
     1252 * Can be used to update the user's info (see below), set the user's role, and
     1253 * set the user's preference on whether they want the rich editor on.
     1254 *
     1255 * Most of the $userdata array fields have filters associated with the values.
     1256 * The exceptions are 'rich_editing', 'role', 'jabber', 'aim', 'yim',
     1257 * 'user_registered', and 'ID'. The filters have the prefix 'pre_user_' followed
     1258 * by the field name. An example using 'description' would have the filter
     1259 * called, 'pre_user_description' that can be hooked into.
     1260 *
     1261 * The $userdata array can contain the following fields:
     1262 * 'ID' - An integer that will be used for updating an existing user.
     1263 * 'user_pass' - A string that contains the plain text password for the user.
     1264 * 'user_login' - A string that contains the user's username for logging in.
     1265 * 'user_nicename' - A string that contains a nicer looking name for the user.
     1266 *      The default is the user's username.
     1267 * 'user_url' - A string containing the user's URL for the user's web site.
     1268 * 'user_email' - A string containing the user's email address.
     1269 * 'display_name' - A string that will be shown on the site. Defaults to user's
     1270 *      username. It is likely that you will want to change this, for both
     1271 *      appearance and security through obscurity (that is if you don't use and
     1272 *      delete the default 'admin' user).
     1273 * 'nickname' - The user's nickname, defaults to the user's username.
     1274 * 'first_name' - The user's first name.
     1275 * 'last_name' - The user's last name.
     1276 * 'description' - A string containing content about the user.
     1277 * 'rich_editing' - A string for whether to enable the rich editor. False
     1278 *      if not empty.
     1279 * 'user_registered' - The date the user registered. Format is 'Y-m-d H:i:s'.
     1280 * 'role' - A string used to set the user's role.
     1281 * 'jabber' - User's Jabber account.
     1282 * 'aim' - User's AOL IM account.
     1283 * 'yim' - User's Yahoo IM account.
     1284 *
     1285 * @since 2.0.0
     1286 * @uses $wpdb WordPress database layer.
     1287 * @uses apply_filters() Calls filters for most of the $userdata fields with the prefix 'pre_user'. See note above.
     1288 * @uses do_action() Calls 'profile_update' hook when updating giving the user's ID
     1289 * @uses do_action() Calls 'user_register' hook when creating a new user giving the user's ID
     1290 *
     1291 * @param array $userdata An array of user data.
     1292 * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not be created.
     1293 */
     1294function wp_insert_user($userdata) {
     1295    global $wpdb;
     1296
     1297    extract($userdata, EXTR_SKIP);
     1298
     1299    // Are we updating or creating?
     1300    if ( !empty($ID) ) {
     1301        $ID = (int) $ID;
     1302        $update = true;
     1303        $old_user_data = get_userdata($ID);
     1304    } else {
     1305        $update = false;
     1306        // Hash the password
     1307        $user_pass = wp_hash_password($user_pass);
     1308    }
     1309
     1310    $user_login = sanitize_user($user_login, true);
     1311    $user_login = apply_filters('pre_user_login', $user_login);
     1312
     1313    //Remove any non-printable chars from the login string to see if we have ended up with an empty username
     1314    $user_login = trim($user_login);
     1315
     1316    if ( empty($user_login) )
     1317        return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') );
     1318
     1319    if ( !$update && username_exists( $user_login ) )
     1320        return new WP_Error('existing_user_login', __('This username is already registered.') );
     1321
     1322    if ( empty($user_nicename) )
     1323        $user_nicename = sanitize_title( $user_login );
     1324    $user_nicename = apply_filters('pre_user_nicename', $user_nicename);
     1325
     1326    if ( empty($user_url) )
     1327        $user_url = '';
     1328    $user_url = apply_filters('pre_user_url', $user_url);
     1329
     1330    if ( empty($user_email) )
     1331        $user_email = '';
     1332    $user_email = apply_filters('pre_user_email', $user_email);
     1333
     1334    if ( !$update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) )
     1335        return new WP_Error('existing_user_email', __('This email address is already registered.') );
     1336
     1337    if ( empty($display_name) )
     1338        $display_name = $user_login;
     1339    $display_name = apply_filters('pre_user_display_name', $display_name);
     1340
     1341    if ( empty($nickname) )
     1342        $nickname = $user_login;
     1343    $nickname = apply_filters('pre_user_nickname', $nickname);
     1344
     1345    if ( empty($first_name) )
     1346        $first_name = '';
     1347    $first_name = apply_filters('pre_user_first_name', $first_name);
     1348
     1349    if ( empty($last_name) )
     1350        $last_name = '';
     1351    $last_name = apply_filters('pre_user_last_name', $last_name);
     1352
     1353    if ( empty($description) )
     1354        $description = '';
     1355    $description = apply_filters('pre_user_description', $description);
     1356
     1357    if ( empty($rich_editing) )
     1358        $rich_editing = 'true';
     1359
     1360    if ( empty($comment_shortcuts) )
     1361        $comment_shortcuts = 'false';
     1362
     1363    if ( empty($admin_color) )
     1364        $admin_color = 'fresh';
     1365    $admin_color = preg_replace('|[^a-z0-9 _.\-@]|i', '', $admin_color);
     1366
     1367    if ( empty($use_ssl) )
     1368        $use_ssl = 0;
     1369
     1370    if ( empty($user_registered) )
     1371        $user_registered = gmdate('Y-m-d H:i:s');
     1372
     1373    $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $user_nicename, $user_login));
     1374
     1375    if ( $user_nicename_check ) {
     1376        $suffix = 2;
     1377        while ($user_nicename_check) {
     1378            $alt_user_nicename = $user_nicename . "-$suffix";
     1379            $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $alt_user_nicename, $user_login));
     1380            $suffix++;
     1381        }
     1382        $user_nicename = $alt_user_nicename;
     1383    }
     1384
     1385    $data = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
     1386    $data = stripslashes_deep( $data );
     1387
     1388    if ( $update ) {
     1389        $wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
     1390        $user_id = (int) $ID;
     1391    } else {
     1392        $wpdb->insert( $wpdb->users, $data + compact( 'user_login' ) );
     1393        $user_id = (int) $wpdb->insert_id;
     1394    }
     1395
     1396    update_user_meta( $user_id, 'first_name', $first_name);
     1397    update_user_meta( $user_id, 'last_name', $last_name);
     1398    update_user_meta( $user_id, 'nickname', $nickname );
     1399    update_user_meta( $user_id, 'description', $description );
     1400    update_user_meta( $user_id, 'rich_editing', $rich_editing);
     1401    update_user_meta( $user_id, 'comment_shortcuts', $comment_shortcuts);
     1402    update_user_meta( $user_id, 'admin_color', $admin_color);
     1403    update_user_meta( $user_id, 'use_ssl', $use_ssl);
     1404
     1405    $user = new WP_User($user_id);
     1406
     1407    foreach ( _wp_get_user_contactmethods( $user ) as $method => $name ) {
     1408        if ( empty($$method) )
     1409            $$method = '';
     1410
     1411        update_user_meta( $user_id, $method, $$method );
     1412    }
     1413
     1414    if ( isset($role) )
     1415        $user->set_role($role);
     1416    elseif ( !$update )
     1417        $user->set_role(get_option('default_role'));
     1418
     1419    wp_cache_delete($user_id, 'users');
     1420    wp_cache_delete($user_login, 'userlogins');
     1421
     1422    if ( $update )
     1423        do_action('profile_update', $user_id, $old_user_data);
     1424    else
     1425        do_action('user_register', $user_id);
     1426
     1427    return $user_id;
     1428}
     1429
     1430/**
     1431 * Update an user in the database.
     1432 *
     1433 * It is possible to update a user's password by specifying the 'user_pass'
     1434 * value in the $userdata parameter array.
     1435 *
     1436 * If $userdata does not contain an 'ID' key, then a new user will be created
     1437 * and the new user's ID will be returned.
     1438 *
     1439 * If current user's password is being updated, then the cookies will be
     1440 * cleared.
     1441 *
     1442 * @since 2.0.0
     1443 * @see wp_insert_user() For what fields can be set in $userdata
     1444 * @uses wp_insert_user() Used to update existing user or add new one if user doesn't exist already
     1445 *
     1446 * @param array $userdata An array of user data.
     1447 * @return int The updated user's ID.
     1448 */
     1449function wp_update_user($userdata) {
     1450    $ID = (int) $userdata['ID'];
     1451
     1452    // First, get all of the original fields
     1453    $user = get_userdata($ID);
     1454
     1455    // Escape data pulled from DB.
     1456    $user = add_magic_quotes(get_object_vars($user));
     1457
     1458    // If password is changing, hash it now.
     1459    if ( ! empty($userdata['user_pass']) ) {
     1460        $plaintext_pass = $userdata['user_pass'];
     1461        $userdata['user_pass'] = wp_hash_password($userdata['user_pass']);
     1462    }
     1463
     1464    wp_cache_delete($user[ 'user_email' ], 'useremail');
     1465
     1466    // Merge old and new fields with new fields overwriting old ones.
     1467    $userdata = array_merge($user, $userdata);
     1468    $user_id = wp_insert_user($userdata);
     1469
     1470    // Update the cookies if the password changed.
     1471    $current_user = wp_get_current_user();
     1472    if ( $current_user->id == $ID ) {
     1473        if ( isset($plaintext_pass) ) {
     1474            wp_clear_auth_cookie();
     1475            wp_set_auth_cookie($ID);
     1476        }
     1477    }
     1478
     1479    return $user_id;
     1480}
     1481
     1482/**
     1483 * A simpler way of inserting an user into the database.
     1484 *
     1485 * Creates a new user with just the username, password, and email. For a more
     1486 * detail creation of a user, use wp_insert_user() to specify more infomation.
     1487 *
     1488 * @since 2.0.0
     1489 * @see wp_insert_user() More complete way to create a new user
     1490 *
     1491 * @param string $username The user's username.
     1492 * @param string $password The user's password.
     1493 * @param string $email The user's email (optional).
     1494 * @return int The new user's ID.
     1495 */
     1496function wp_create_user($username, $password, $email = '') {
     1497    $user_login = esc_sql( $username );
     1498    $user_email = esc_sql( $email    );
     1499    $user_pass = $password;
     1500
     1501    $userdata = compact('user_login', 'user_email', 'user_pass');
     1502    return wp_insert_user($userdata);
     1503}
     1504
     1505
     1506/**
     1507 * Set up the default contact methods
     1508 *
     1509 * @access private
     1510 * @since
     1511 *
     1512 * @param object $user User data object (optional)
     1513 * @return array $user_contactmethods Array of contact methods and their labels.
     1514 */
     1515function _wp_get_user_contactmethods( $user = null ) {
     1516    $user_contactmethods = array(
     1517        'aim' => __('AIM'),
     1518        'yim' => __('Yahoo IM'),
     1519        'jabber' => __('Jabber / Google Talk')
     1520    );
     1521    return apply_filters( 'user_contactmethods', $user_contactmethods, $user );
     1522}
     1523
    11991524?>
  • trunk/wp-login.php

    r16008 r16009  
    497497    $user_email = '';
    498498    if ( $http_post ) {
    499         require_once( ABSPATH . WPINC . '/registration.php');
    500 
    501499        $user_login = $_POST['user_login'];
    502500        $user_email = $_POST['user_email'];
  • trunk/wp-signup.php

    r16008 r16009  
    77
    88require( './wp-blog-header.php' );
    9 require_once( ABSPATH . WPINC . '/registration.php' );
    109
    1110if ( is_array( get_site_option( 'illegal_names' )) && isset( $_GET[ 'new' ] ) && in_array( $_GET[ 'new' ], get_site_option( 'illegal_names' ) ) == true ) {
Note: See TracChangeset for help on using the changeset viewer.