WordPress at a glance
Home All Function Functions APIs HTTP API

wp_remote_retrieve_cookie_value() WP 4.4.0

Retrieve the value of the specified cookie from the passed query response.

No Hooks.

Return

String. The value of the cookie. Empty string if the cookie isn't present in the response.

Usage

wp_remote_retrieve_cookie_value( $response, $name );
$response(array) (required)
HTTP response. The result of any of wp_remote_*() functions.
$name(string) (required)
The name of the cookie to retrieve.

Examples

#1 Basic usage

$url = 'https://example.com/cookies/set?mycookie=mycookievalue';

$response = wp_remote_get( $url );

$mycookie = wp_remote_retrieve_cookie_value( $response, 'mycookie' ); //> mycookievalue

Code of wp remote retrieve cookie value: wp-includes/http.php WP 5.2.1

<?php
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;
}

Related Functions

From tag: HTTP API (curl remote)

No comments
    Hello, !     Log In . Register