wp_remote_retrieve_cookie() - WordPress 函数参考中文文档

返回介绍

wp_remote_retrieve_cookie()

发布于 2017-09-11 字数 2064 浏览 936 评论 0

wp_remote_retrieve_cookie( array $response,  string $name )

Retrieve a single cookie by name from the raw response.


描述


参数

$response

(array)
(Required)
HTTP response.

$name

(string)
(Required)
The name of the cookie to retrieve.


返回值

(WP_Http_Cookie|string) The WP_Http_Cookie object. Empty string if the cookie isn’t present in the response.


源代码

File: wp-includes/http.php

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 '';
}

更新日志

Version 描述
4.4.0 Introduced.

相关函数

Uses

  • wp-includes/http.php:
    wp_remote_retrieve_cookies()

Used By

  • wp-includes/http.php:
    wp_remote_retrieve_cookie_value()

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Aamer Shahzad

    
    $json = wp_remote_get( 'http://localhost/wp-rest-api/wp-json/wp/v2/posts/' );
    $sess_cookie = wp_remote_retrieve_cookie($json, 'PHPSESSID');
    
    echo '<pre>';
    print_r($sess_cookie);
    echo '</pre>';
    

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!