$user = get_user_by('login', $username);
if ( !$user )
- return new WP_Error('invalid_username', sprintf(__('<strong>ERROR</strong>: Invalid username. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), wp_lostpassword_url()));
+ return new WP_Error( 'invalid_username', sprintf( __( '<strong>ERROR</strong>: Invalid username. <a href="%s" title="Password Lost and Found">Lost your password</a>?' ), wp_lostpassword_url() ) );
if ( is_multisite() ) {
// Is user marked as spam?
- if ( 1 == $user->spam)
- return new WP_Error('invalid_username', __('<strong>ERROR</strong>: Your account has been marked as a spammer.'));
+ if ( 1 == $user->spam )
+ return new WP_Error( 'spammer_account', __( '<strong>ERROR</strong>: 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.' ) );
}
}
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 );
}
$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.*";
$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 );
}
* @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);
* @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);
* @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);
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 = '';
}
$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' ) );
* 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.
*
// 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();
* @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');
}
/**
- * 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
* @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 );
}