X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/6c8f14c09105d0afa4c1574215c59b5021040e76..11be15bd505d66a91e2c80062190b13e315a04a9:/wp-includes/user.php diff --git a/wp-includes/user.php b/wp-includes/user.php index 7bdc37cc..bc583a57 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -87,18 +87,18 @@ function wp_authenticate_username_password($user, $username, $password) { $user = get_user_by('login', $username); if ( !$user ) - return new WP_Error('invalid_username', sprintf(__('ERROR: Invalid username. Lost your password?'), wp_lostpassword_url())); + return new WP_Error( 'invalid_username', sprintf( __( 'ERROR: Invalid username. Lost your password?' ), wp_lostpassword_url() ) ); if ( is_multisite() ) { // Is user marked as spam? - if ( 1 == $user->spam) - return new WP_Error('invalid_username', __('ERROR: Your account has been marked as a spammer.')); + if ( 1 == $user->spam ) + return new WP_Error( 'spammer_account', __( 'ERROR: Your account has been marked as a spammer.' ) ); // Is a user's blog marked as spam? - if ( !is_super_admin( $user->ID ) && isset($user->primary_blog) ) { + if ( !is_super_admin( $user->ID ) && isset( $user->primary_blog ) ) { $details = get_blog_details( $user->primary_blog ); if ( is_object( $details ) && $details->spam == 1 ) - return new WP_Error('blog_suspended', __('Site Suspended.')); + return new WP_Error( 'blog_suspended', __( 'Site Suspended.' ) ); } } @@ -276,11 +276,6 @@ function update_user_option( $user_id, $option_name, $newvalue, $global = false if ( !$global ) $option_name = $wpdb->prefix . $option_name; - // For backward compatibility. See differences between update_user_meta() and deprecated update_usermeta(). - // http://core.trac.wordpress.org/ticket/13088 - if ( is_null( $newvalue ) || is_scalar( $newvalue ) && empty( $newvalue ) ) - return delete_user_meta( $user_id, $option_name ); - return update_user_meta( $user_id, $option_name, $newvalue ); } @@ -397,8 +392,10 @@ class WP_User_Query { $qv['fields'] = array_unique( $qv['fields'] ); $this->query_fields = array(); - foreach ( $qv['fields'] as $field ) - $this->query_fields[] = $wpdb->users . '.' . esc_sql( $field ); + foreach ( $qv['fields'] as $field ) { + $field = 'ID' === $field ? 'ID' : sanitize_key( $field ); + $this->query_fields[] = "$wpdb->users.$field"; + } $this->query_fields = implode( ',', $this->query_fields ); } elseif ( 'all' == $qv['fields'] ) { $this->query_fields = "$wpdb->users.*"; @@ -474,12 +471,14 @@ class WP_User_Query { $search_columns = array('user_email'); elseif ( is_numeric($search) ) $search_columns = array('user_login', 'ID'); - elseif ( preg_match('|^https?://|', $search) && ! wp_is_large_network( 'users' ) ) + elseif ( preg_match('|^https?://|', $search) && ! ( is_multisite() && wp_is_large_network( 'users' ) ) ) $search_columns = array('user_url'); else $search_columns = array('user_login', 'user_nicename'); } + $search_columns = apply_filters( 'user_search_columns', $search_columns, $search, $this ); + $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild ); } @@ -794,7 +793,7 @@ function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) { * @param string $meta_key Metadata name. * @param mixed $meta_value Metadata value. * @param bool $unique Optional, default is false. Whether the same key should not be added. - * @return bool False for failure. True for success. + * @return int|bool Meta ID on success, false on failure. */ function add_user_meta($user_id, $meta_key, $meta_value, $unique = false) { return add_metadata('user', $user_id, $meta_key, $meta_value, $unique); @@ -814,7 +813,7 @@ function add_user_meta($user_id, $meta_key, $meta_value, $unique = false) { * @param int $user_id user ID * @param string $meta_key Metadata name. * @param mixed $meta_value Optional. Metadata value. - * @return bool False for failure. True for success. + * @return bool True on success, false on failure. */ function delete_user_meta($user_id, $meta_key, $meta_value = '') { return delete_metadata('user', $user_id, $meta_key, $meta_value); @@ -853,7 +852,7 @@ function get_user_meta($user_id, $key = '', $single = false) { * @param string $meta_key Metadata key. * @param mixed $meta_value Metadata value. * @param mixed $prev_value Optional. Previous value to check before removing. - * @return bool False on failure, true if success. + * @return bool True on success, false on failure. */ function update_user_meta($user_id, $meta_key, $meta_value, $prev_value = '') { return update_metadata('user', $user_id, $meta_key, $meta_value, $prev_value); @@ -1032,7 +1031,7 @@ function wp_dropdown_users( $args = '' ) { extract( $r, EXTR_SKIP ); $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); - $query_args['fields'] = array( 'ID', $show ); + $query_args['fields'] = array( 'ID', 'user_login', $show ); $users = get_users( $query_args ); $output = ''; @@ -1390,7 +1389,7 @@ function wp_insert_user( $userdata ) { } $data = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' ); - $data = stripslashes_deep( $data ); + $data = wp_unslash( $data ); if ( $update ) { $wpdb->update( $wpdb->users, $data, compact( 'ID' ) ); @@ -1429,9 +1428,6 @@ function wp_insert_user( $userdata ) { * It is possible to update a user's password by specifying the 'user_pass' * value in the $userdata parameter array. * - * If $userdata does not contain an 'ID' key, then a new user will be created - * and the new user's ID will be returned. - * * If current user's password is being updated, then the cookies will be * cleared. * @@ -1452,6 +1448,8 @@ function wp_update_user($userdata) { // First, get all of the original fields $user_obj = get_userdata( $ID ); + if ( ! $user_obj ) + return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); $user = $user_obj->to_array(); @@ -1502,8 +1500,8 @@ function wp_update_user($userdata) { * @return int The new user's ID. */ function wp_create_user($username, $password, $email = '') { - $user_login = esc_sql( $username ); - $user_email = esc_sql( $email ); + $user_login = wp_slash( $username ); + $user_email = wp_slash( $email ); $user_pass = $password; $userdata = compact('user_login', 'user_email', 'user_pass'); @@ -1525,7 +1523,9 @@ function _get_additional_user_keys( $user ) { } /** - * Set up the default contact methods. + * Set up the contact methods. + * + * Default contact methods were removed in 3.6. A filter dictates contact methods. * * @since 2.9.0 * @access private @@ -1534,10 +1534,13 @@ function _get_additional_user_keys( $user ) { * @return array $user_contactmethods Array of contact methods and their labels. */ function _wp_get_user_contactmethods( $user = null ) { - $user_contactmethods = array( - 'aim' => __('AIM'), - 'yim' => __('Yahoo IM'), - 'jabber' => __('Jabber / Google Talk') - ); + $user_contactmethods = array(); + if ( get_site_option( 'initial_db_version' ) < 23588 ) { + $user_contactmethods = array( + 'aim' => __( 'AIM' ), + 'yim' => __( 'Yahoo IM' ), + 'jabber' => __( 'Jabber / Google Talk' ) + ); + } return apply_filters( 'user_contactmethods', $user_contactmethods, $user ); }