+ if ( false !== $user_id ) {
+ if ( $user = wp_cache_get( $user_id, 'users' ) )
+ return $user;
+ }
+
+ if ( !$user = $wpdb->get_row( $wpdb->prepare(
+ "SELECT * FROM $wpdb->users WHERE $db_field = %s", $value
+ ) ) )
+ return false;
+
+ update_user_caches( $user );
+
+ return $user;
+ }
+
+ /**
+ * Makes private/protected methods readable for backwards compatibility.
+ *
+ * @since 4.3.0
+ * @access public
+ *
+ * @param callable $name Method to call.
+ * @param array $arguments Arguments to pass when calling.
+ * @return mixed|false Return value of the callback, false otherwise.
+ */
+ public function __call( $name, $arguments ) {
+ if ( '_init_caps' === $name ) {
+ return call_user_func_array( array( $this, $name ), $arguments );
+ }
+ return false;
+ }
+
+ /**
+ * Magic method for checking the existence of a certain custom field
+ *
+ * @since 3.3.0
+ * @param string $key
+ * @return bool
+ */
+ public function __isset( $key ) {
+ if ( 'id' == $key ) {
+ _deprecated_argument( 'WP_User->id', '2.1', __( 'Use <code>WP_User->ID</code> instead.' ) );
+ $key = 'ID';
+ }
+
+ if ( isset( $this->data->$key ) )
+ return true;
+
+ if ( isset( self::$back_compat_keys[ $key ] ) )
+ $key = self::$back_compat_keys[ $key ];
+
+ return metadata_exists( 'user', $this->ID, $key );
+ }
+
+ /**
+ * Magic method for accessing custom fields
+ *
+ * @since 3.3.0
+ * @param string $key
+ * @return mixed
+ */
+ public function __get( $key ) {
+ if ( 'id' == $key ) {
+ _deprecated_argument( 'WP_User->id', '2.1', __( 'Use <code>WP_User->ID</code> instead.' ) );
+ return $this->ID;
+ }
+
+ if ( isset( $this->data->$key ) ) {
+ $value = $this->data->$key;
+ } else {
+ if ( isset( self::$back_compat_keys[ $key ] ) )
+ $key = self::$back_compat_keys[ $key ];
+ $value = get_user_meta( $this->ID, $key, true );
+ }
+
+ if ( $this->filter ) {
+ $value = sanitize_user_field( $key, $value, $this->ID, $this->filter );
+ }
+
+ return $value;
+ }
+
+ /**
+ * Magic method for setting custom fields
+ *
+ * @since 3.3.0
+ */
+ public function __set( $key, $value ) {
+ if ( 'id' == $key ) {
+ _deprecated_argument( 'WP_User->id', '2.1', __( 'Use <code>WP_User->ID</code> instead.' ) );
+ $this->ID = $value;
+ return;
+ }
+
+ $this->data->$key = $value;
+ }
+
+ /**
+ * Determine whether the user exists in the database.
+ *
+ * @since 3.4.0
+ * @access public
+ *
+ * @return bool True if user exists in the database, false if not.
+ */
+ public function exists() {
+ return ! empty( $this->ID );