WordPress.org

Make WordPress Core

Ticket #4383: 4383.diff

File 4383.diff, 3.0 KB (added by rob1n, 11 years ago)
  • wp-includes/registration.php

     
    11<?php
    22
     3/**
     4 * Checks whether the given username exists.
     5 * @param string $username Username.
     6 * @return mixed The user's ID on success, and null on failure.
     7 */
    38function username_exists( $username ) {
    4         global $wpdb;
    5         $username = sanitize_user( $username );
    6         $user = get_userdatabylogin($username);
    7         if ( $user )
     9        if ( $user = get_userdatabylogin( sanitize_user( $username ) ) ) {
    810                return $user->ID;
    9 
    10         return null;
     11        } else {
     12                return null;
     13        }
    1114}
    1215
    13 
     16/**
     17 * Checks whether the given email exists.
     18 * @global object $wpdb WordPress database layer.
     19 * @param string $email Email.
     20 * @return mixed The user's ID on success, and false on failure.
     21 */
    1422function email_exists( $email ) {
    1523        global $wpdb;
    16         $email = addslashes( $email );
    17         return $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_email = '$email'");
     24        $email = $wpdb->escape( $email );
     25        return $wpdb->get_var( "SELECT ID FROM $wpdb->users WHERE user_email = '$email'" );
    1826}
    1927
    20 
     28/**
     29 * Checks whether an username is valid.
     30 * @param string $username Username.
     31 * @return bool A filtered boolean.
     32 */
    2133function validate_username( $username ) {
    22         $name = sanitize_user($username, true);
    23         $valid = true;
    24 
    25         if ( $name != $username )
    26                 $valid = false;
    27 
    28         return apply_filters('validate_username', $valid, $username);
     34        $sanitized = sanitize_user( $username, true );
     35        $valid = ( $sanitized == $username );
     36        return apply_filters( 'validate_username', $valid, $username );
    2937}
    3038
    31 
     39/**
     40 * Insert an user into the database.
     41 * @global object $wpdb WordPress database layer.
     42 * @param array $userdata An array of user data.
     43 * @return int The newly created user's ID.
     44 */
    3245function wp_insert_user($userdata) {
    3346        global $wpdb;
    3447
     
    130143        return $user_id;
    131144}
    132145
    133 
     146/**
     147 * Update an user in the database.
     148 * @global object $wpdb WordPress database layer.
     149 * @param array $userdata An array of user data.
     150 * @return int The updated user's ID.
     151 */
    134152function wp_update_user($userdata) {
    135153        global $wpdb;
    136154
     
    164182        return $user_id;
    165183}
    166184
    167 
     185/**
     186 * A simpler way of inserting an user into the database.
     187 * See also: wp_insert_user().
     188 * @global object $wpdb WordPress database layer.
     189 * @param string $username The user's username.
     190 * @param string $password The user's password.
     191 * @param string $email The user's email (optional).
     192 * @return int The new user's ID.
     193 */
    168194function wp_create_user($username, $password, $email = '') {
    169195        global $wpdb;
    170196
     
    176202        return wp_insert_user($userdata);
    177203}
    178204
    179 
     205/**
     206 * An alias of wp_create_user().
     207 * @param string $username The user's username.
     208 * @param string $password The user's password.
     209 * @param string $email The user's email (optional).
     210 * @return int The new user's ID.
     211 * @deprecated
     212 */
    180213function create_user($username, $password, $email) {
    181214        return wp_create_user($username, $password, $email);
    182215}