WP_Http_Cookie example

/** * Retrieves cookies from the response. * * @since 4.6.0 * * @return WP_HTTP_Cookie[] List of cookie objects. */
    public function get_cookies() {
        $cookies = array();
        foreach ( $this->response->cookies as $cookie ) {
            $cookies[] = new WP_Http_Cookie(
                array(
                    'name'      => $cookie->name,
                    'value'     => urldecode( $cookie->value ),
                    'expires'   => isset( $cookie->attributes['expires'] ) ? $cookie->attributes['expires'] : null,
                    'path'      => isset( $cookie->attributes['path'] ) ? $cookie->attributes['path'] : null,
                    'domain'    => isset( $cookie->attributes['domain'] ) ? $cookie->attributes['domain'] : null,
                    'host_only' => isset( $cookie->flags['host-only'] ) ? $cookie->flags['host-only'] : null,
                )
            );
        }

        
$value = trim( $value );

            if ( isset( $newheaders[ $key ] ) ) {
                if ( ! is_array( $newheaders[ $key ] ) ) {
                    $newheaders[ $key ] = array( $newheaders[ $key ] );
                }
                $newheaders[ $key ][] = $value;
            } else {
                $newheaders[ $key ] = $value;
            }
            if ( 'set-cookie' === $key ) {
                $cookies[] = new WP_Http_Cookie( $value$url );
            }
        }

        // Cast the Response Code to an int.         $response['code'] = (int) $response['code'];

        return array(
            'response' => $response,
            'headers'  => $newheaders,
            'cookies'  => $cookies,
        );
    }
Home | Imprint | This part of the site doesn't use cookies.