Make WordPress Core


Ignore:
Timestamp:
08/08/2013 02:43:36 AM (12 years ago)
Author:
dd32
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-http.php

    r24894 r25016  
    410410     * Takes the arguments for a ::request() and checks for the cookie array.
    411411     *
    412      * If it's found, then it's assumed to contain WP_Http_Cookie objects, which are each parsed
    413      * into strings and added to the Cookie: header (within the arguments array). Edits the array by
    414      * reference.
     412     * If it's found, then it upgrades any basic name => value pairs to WP_Http_Cookie instances,
     413     * which are each parsed into strings and added to the Cookie: header (within the arguments array).
     414     * Edits the array by reference.
    415415     *
    416416     * @access public
     
    422422    public static function buildCookieHeader( &$r ) {
    423423        if ( ! empty($r['cookies']) ) {
     424            // Upgrade any name => value cookie pairs to WP_HTTP_Cookie instances
     425            foreach ( $r['cookies'] as $name => $value ) {
     426                if ( ! is_object( $value ) )
     427                    $r['cookies'][ $name ] = new WP_HTTP_Cookie( array( 'name' => $name, 'value' => $value ) );
     428            }
     429
    424430            $cookies_header = '';
    425431            foreach ( (array) $r['cookies'] as $cookie ) {
    426432                $cookies_header .= $cookie->getHeaderValue() . '; ';
    427433            }
     434
    428435            $cookies_header = substr( $cookies_header, 0, -2 );
    429436            $r['headers']['cookie'] = $cookies_header;
Note: See TracChangeset for help on using the changeset viewer.