WP_HTTP: Allow name => value pairs to be passed in to the 'cookie' parameter, simplifies plugin code when needing to specify basic cookies. Fixes #21999
Built from https://develop.svn.wordpress.org/trunk@25016 git-svn-id: http://core.svn.wordpress.org/trunk@25008 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e629ddaba0
commit
da016d59b4
|
@ -409,9 +409,9 @@ class WP_Http {
|
|||
/**
|
||||
* Takes the arguments for a ::request() and checks for the cookie array.
|
||||
*
|
||||
* If it's found, then it's assumed to contain WP_Http_Cookie objects, which are each parsed
|
||||
* into strings and added to the Cookie: header (within the arguments array). Edits the array by
|
||||
* reference.
|
||||
* If it's found, then it upgrades any basic name => value pairs to WP_Http_Cookie instances,
|
||||
* which are each parsed into strings and added to the Cookie: header (within the arguments array).
|
||||
* Edits the array by reference.
|
||||
*
|
||||
* @access public
|
||||
* @version 2.8.0
|
||||
|
@ -421,10 +421,17 @@ class WP_Http {
|
|||
*/
|
||||
public static function buildCookieHeader( &$r ) {
|
||||
if ( ! empty($r['cookies']) ) {
|
||||
// Upgrade any name => value cookie pairs to WP_HTTP_Cookie instances
|
||||
foreach ( $r['cookies'] as $name => $value ) {
|
||||
if ( ! is_object( $value ) )
|
||||
$r['cookies'][ $name ] = new WP_HTTP_Cookie( array( 'name' => $name, 'value' => $value ) );
|
||||
}
|
||||
|
||||
$cookies_header = '';
|
||||
foreach ( (array) $r['cookies'] as $cookie ) {
|
||||
$cookies_header .= $cookie->getHeaderValue() . '; ';
|
||||
}
|
||||
|
||||
$cookies_header = substr( $cookies_header, 0, -2 );
|
||||
$r['headers']['cookie'] = $cookies_header;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue