2005-07-23 12:16:03 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function username_exists( $username ) {
|
|
|
|
global $wpdb;
|
|
|
|
$username = sanitize_user( $username );
|
2005-11-07 16:56:03 -05:00
|
|
|
$user = get_userdatabylogin($username);
|
|
|
|
if ( $user )
|
2005-12-23 18:16:01 -05:00
|
|
|
return $user->ID;
|
2005-11-07 16:56:03 -05:00
|
|
|
|
|
|
|
return null;
|
2005-07-23 12:16:03 -04:00
|
|
|
}
|
|
|
|
|
2006-02-09 03:11:26 -05:00
|
|
|
function email_exists( $email ) {
|
|
|
|
global $wpdb;
|
|
|
|
$email = addslashes( $email );
|
2006-04-27 00:24:14 -04:00
|
|
|
return $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_email = '$email'");
|
2006-02-09 03:11:26 -05:00
|
|
|
}
|
|
|
|
|
2006-01-24 22:09:16 -05:00
|
|
|
function validate_username( $username ) {
|
|
|
|
$name = sanitize_user($username, true);
|
|
|
|
$valid = true;
|
|
|
|
|
|
|
|
if ( $name != $username )
|
2006-02-12 02:53:23 -05:00
|
|
|
$valid = false;
|
2006-01-24 22:09:16 -05:00
|
|
|
|
2006-02-12 02:53:23 -05:00
|
|
|
return apply_filters('validate_username', $valid, $username);
|
2006-01-24 22:09:16 -05:00
|
|
|
}
|
|
|
|
|
2005-09-13 20:03:02 -04:00
|
|
|
function wp_insert_user($userdata) {
|
2005-07-23 12:16:03 -04:00
|
|
|
global $wpdb;
|
2005-09-13 20:03:02 -04:00
|
|
|
|
|
|
|
extract($userdata);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2006-01-24 22:09:16 -05:00
|
|
|
$user_login = sanitize_user($user_login, true);
|
|
|
|
|
2005-09-13 20:03:02 -04:00
|
|
|
if ( empty($user_nicename) )
|
|
|
|
$user_nicename = sanitize_title( $user_login );
|
|
|
|
|
|
|
|
if ( empty($display_name) )
|
|
|
|
$display_name = $user_login;
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2005-09-13 20:03:02 -04:00
|
|
|
if ( empty($nickname) )
|
|
|
|
$nickname = $user_login;
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2005-09-13 20:03:02 -04:00
|
|
|
if ( empty($user_registered) )
|
|
|
|
$user_registered = gmdate('Y-m-d H:i:s');
|
|
|
|
|
|
|
|
if ( $update ) {
|
2005-09-15 19:44:33 -04:00
|
|
|
$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'";
|
2005-09-13 20:03:02 -04:00
|
|
|
$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)
|
2005-07-23 12:16:03 -04:00
|
|
|
VALUES
|
2005-09-13 20:03:02 -04:00
|
|
|
('$user_login', '$user_pass', '$user_email', '$user_url', '$user_registered', '$user_nicename', '$display_name')";
|
|
|
|
$query = apply_filters('create_user_query', $query);
|
|
|
|
$wpdb->query( $query );
|
|
|
|
$user_id = $wpdb->insert_id;
|
|
|
|
}
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2005-09-13 20:03:02 -04:00
|
|
|
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', $description );
|
|
|
|
update_usermeta( $user_id, 'jabber', $jabber );
|
|
|
|
update_usermeta( $user_id, 'aim', $aim );
|
|
|
|
update_usermeta( $user_id, 'yim', $yim );
|
2005-11-05 22:58:52 -05:00
|
|
|
|
|
|
|
if ($update && !empty($role)) {
|
|
|
|
$user = new WP_User($user_id);
|
|
|
|
$user->set_role($role);
|
|
|
|
}
|
|
|
|
|
2005-09-13 20:03:02 -04:00
|
|
|
if ( !$update ) {
|
|
|
|
$user = new WP_User($user_id);
|
|
|
|
$user->set_role(get_settings('default_role'));
|
|
|
|
}
|
2005-11-07 16:56:03 -05:00
|
|
|
|
|
|
|
wp_cache_delete($user_id, 'users');
|
2005-12-19 14:14:22 -05:00
|
|
|
wp_cache_delete($user_login, 'userlogins');
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2005-09-13 20:03:02 -04:00
|
|
|
if ( $update )
|
|
|
|
do_action('profile_update', $user_id);
|
|
|
|
else
|
|
|
|
do_action('user_register', $user_id);
|
2006-02-12 02:53:23 -05:00
|
|
|
|
|
|
|
return $user_id;
|
2005-09-13 20:03:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function wp_update_user($userdata) {
|
2006-02-22 14:08:55 -05:00
|
|
|
global $wpdb;
|
2005-09-13 20:03:02 -04:00
|
|
|
|
|
|
|
$ID = (int) $userdata['ID'];
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2005-09-13 20:03:02 -04:00
|
|
|
// First, get all of the original fields
|
2006-02-12 02:53:23 -05:00
|
|
|
$user = get_userdata($ID);
|
2005-09-13 20:03:02 -04:00
|
|
|
|
|
|
|
// 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']);
|
|
|
|
}
|
2005-11-05 22:40:43 -05:00
|
|
|
|
2005-09-13 20:03:02 -04:00
|
|
|
// Merge old and new fields with new fields overwriting old ones.
|
|
|
|
$userdata = array_merge($user, $userdata);
|
|
|
|
$user_id = wp_insert_user($userdata);
|
2005-07-23 12:16:03 -04:00
|
|
|
|
2006-02-12 02:53:23 -05:00
|
|
|
// Update the cookies if the password changed.
|
2006-02-22 14:08:55 -05:00
|
|
|
$current_user = wp_get_current_user();
|
2005-09-20 13:55:16 -04:00
|
|
|
if( $current_user->id == $ID ) {
|
|
|
|
if ( isset($plaintext_pass) ) {
|
|
|
|
wp_clearcookie();
|
|
|
|
wp_setcookie($userdata['user_login'], $plaintext_pass);
|
|
|
|
}
|
2005-09-13 20:03:02 -04:00
|
|
|
}
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2005-07-23 12:16:03 -04:00
|
|
|
return $user_id;
|
|
|
|
}
|
|
|
|
|
2005-09-24 14:07:46 -04:00
|
|
|
function wp_create_user( $username, $password, $email = '') {
|
2005-09-13 20:03:02 -04:00
|
|
|
global $wpdb;
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2005-09-13 20:03:02 -04:00
|
|
|
$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 ) {
|
2006-02-12 02:53:23 -05:00
|
|
|
return wp_create_user( $username, $password, $email );
|
2005-09-13 20:03:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-05 22:40:43 -05:00
|
|
|
?>
|