diff --git a/wp-includes/http-functions.php b/wp-includes/http-functions.php index 748be1c855..e4e8507cc3 100644 --- a/wp-includes/http-functions.php +++ b/wp-includes/http-functions.php @@ -285,6 +285,66 @@ function wp_remote_retrieve_body( $response ) { return $response['body']; } +/** + * Retrieve only the body from the raw response. + * + * @since 4.4.0 + * + * @param array $response HTTP response. + * @return array An array of `WP_Http_Cookie` objects from the response. Empty array if there are none, or the response is a WP_Error. + */ +function wp_remote_retrieve_cookies( $response ) { + if ( is_wp_error( $response ) || empty( $response['cookies'] ) ) { + return array(); + } + + return $response['cookies']; +} + +/** + * Retrieve a single cookie by name from the raw response. + * + * @since 4.4.0 + * + * @param array $response HTTP response. + * @param string $name The name of the cookie to retrieve. + * @return WP_Http_Cookie|string The `WP_Http_Cookie` object. Empty string if the cookie isn't present in the response. + */ +function wp_remote_retrieve_cookie( $response, $name ) { + $cookies = wp_remote_retrieve_cookies( $response ); + + if ( empty( $cookies ) ) { + return ''; + } + + foreach ( $cookies as $cookie ) { + if ( $cookie->name === $name ) { + return $cookie; + } + } + + return ''; +} + +/** + * Retrieve a single cookie's value by name from the raw response. + * + * @since 4.4.0 + * + * @param array $response HTTP response. + * @param string $name The name of the cookie to retrieve. + * @return string The value of the cookie. Empty string if the cookie isn't present in the response. + */ +function wp_remote_retrieve_cookie_value( $response, $name ) { + $cookie = wp_remote_retrieve_cookie( $response, $name ); + + if ( ! is_a( $cookie, 'WP_Http_Cookie' ) ) { + return ''; + } + + return $cookie->value; +} + /** * Determines if there is an HTTP Transport that can process this request. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 15652337b5..453f3aa261 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34368'; +$wp_version = '4.4-alpha-34369'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.