+/**
+ * Authenticate the user using the WordPress auth cookie.
+ */
+function wp_authenticate_cookie($user, $username, $password) {
+ if ( is_a($user, 'WP_User') ) { return $user; }
+
+ if ( empty($username) && empty($password) ) {
+ $user_id = wp_validate_auth_cookie();
+ if ( $user_id )
+ return new WP_User($user_id);
+
+ global $auth_secure_cookie;
+
+ if ( $auth_secure_cookie )
+ $auth_cookie = SECURE_AUTH_COOKIE;
+ else
+ $auth_cookie = AUTH_COOKIE;
+
+ if ( !empty($_COOKIE[$auth_cookie]) )
+ return new WP_Error('expired_session', __('Please log in again.'));
+
+ // If the cookie is not set, be silent.
+ }
+
+ return $user;
+}
+
+/**
+ * Retrieve user data based on field.
+ *
+ * Use get_profile() will make a database query to get the value of the table
+ * column. The value might be cached using the query cache, but care should be
+ * taken when using the function to not make a lot of queries for retrieving
+ * user profile information.
+ *
+ * If the $user parameter is not used, then the user will be retrieved from a
+ * cookie of the user. Therefore, if the cookie does not exist, then no value
+ * might be returned. Sanity checking must be done to ensure that when using
+ * get_profile() that empty/null/false values are handled and that something is
+ * at least displayed.
+ *
+ * @since 1.5.0
+ * @uses $wpdb WordPress database object to create queries.
+ *
+ * @param string $field User field to retrieve.
+ * @param string $user Optional. User username.
+ * @return string The value in the field.
+ */