| | 293 | * Retrieve only the body from the raw response. |
| | 294 | * |
| | 295 | * @since 4.4.0 |
| | 296 | * |
| | 297 | * @param array $response HTTP response. |
| | 298 | * @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. |
| | 299 | */ |
| | 300 | function wp_remote_retrieve_cookies( $response ) { |
| | 301 | if ( is_wp_error( $response ) || empty( $response['cookies'] ) ) { |
| | 302 | return array(); |
| | 303 | } |
| | 304 | |
| | 305 | return $response['cookies']; |
| | 306 | } |
| | 307 | |
| | 308 | /** |
| | 309 | * Retrieve a single cookie by name from the raw response. |
| | 310 | * |
| | 311 | * @since 4.4.0 |
| | 312 | * |
| | 313 | * @param array $response HTTP response. |
| | 314 | * @param string $name The name of the cookie to retrieve. |
| | 315 | * @return WP_Http_Cookie|string The `WP_Http_Cookie` object. Empty string if the cookie isn't present in the response. |
| | 316 | */ |
| | 317 | function wp_remote_retrieve_cookie( $response, $name ) { |
| | 318 | $cookies = wp_remote_retrieve_cookies( $response ); |
| | 319 | |
| | 320 | if ( empty( $cookies ) ) { |
| | 321 | return ''; |
| | 322 | } |
| | 323 | |
| | 324 | foreach ( $cookies as $cookie ) { |
| | 325 | if ( $cookie->name === $name ) { |
| | 326 | return $cookie; |
| | 327 | } |
| | 328 | } |
| | 329 | |
| | 330 | return ''; |
| | 331 | } |
| | 332 | |
| | 333 | /** |
| | 334 | * Retrieve a single cookie's value by name from the raw response. |
| | 335 | * |
| | 336 | * @since 4.4.0 |
| | 337 | * |
| | 338 | * @param array $response HTTP response. |
| | 339 | * @param string $name The name of the cookie to retrieve. |
| | 340 | * @return string The value of the cookie. Empty string if the cookie isn't present in the response. |
| | 341 | */ |
| | 342 | function wp_remote_retrieve_cookie_value( $response, $name ) { |
| | 343 | $cookie = wp_remote_retrieve_cookie( $response, $name ); |
| | 344 | |
| | 345 | if ( ! is_a( $cookie, 'WP_Http_Cookie' ) ) { |
| | 346 | return ''; |
| | 347 | } |
| | 348 | |
| | 349 | return $cookie->value; |
| | 350 | } |
| | 351 | |
| | 352 | /** |