From 37c3399a0c705c4e7cc33707374396f69c1ec8ea Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Thu, 8 Aug 2013 02:43:36 +0000 Subject: [PATCH] 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 git-svn-id: https://develop.svn.wordpress.org/trunk@25016 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-http.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-http.php b/src/wp-includes/class-http.php index 12e73bbb86..9e559c6683 100644 --- a/src/wp-includes/class-http.php +++ b/src/wp-includes/class-http.php @@ -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; }