wp_remote_retrieve_cookie

Retrieve a single cookie by name from the raw response.

Description

(WP_Http_Cookie|string) wp_remote_retrieve_cookie( (array) $response, (string) $name ); 

Returns (WP_Http_Cookie|string)

The `WP_Http_Cookie` object. Empty string if the cookie isn't present in the response.

Parameters (2)

0. $response (array)
HTTP response.
1. $name (string)
The name of the cookie to retrieve.

Usage

  1. if ( !function_exists( 'wp_remote_retrieve_cookie' ) ) { 
  2. require_once ABSPATH . WPINC . '/http.php'; 
  3.  
  4. // HTTP response. 
  5. $response = array(); 
  6.  
  7. // The name of the cookie to retrieve. 
  8. $name = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_remote_retrieve_cookie($response, $name); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/http.php  
  1. function wp_remote_retrieve_cookie( $response, $name ) { 
  2. $cookies = wp_remote_retrieve_cookies( $response ); 
  3.  
  4. if ( empty( $cookies ) ) { 
  5. return ''; 
  6.  
  7. foreach ( $cookies as $cookie ) { 
  8. if ( $cookie->name === $name ) { 
  9. return $cookie; 
  10.  
  11. return '';