WP_Http::normalize_cookies() WordPress Method

The WP_Http::normalize_cookies() method is used to normalize cookies for use with the WP_Http class. This is done by providing an array of cookies as input and returning an array of normalized cookies.

WP_Http::normalize_cookies( array $cookies ) #

Normalizes cookies for using in Requests.


Parameters

$cookies

(array)(Required)Array of cookies to send with the request.


Top ↑

Return

(Requests_Cookie_Jar) Cookie holder object.


Top ↑

Source

File: wp-includes/class-wp-http.php

	public static function normalize_cookies( $cookies ) {
		$cookie_jar = new Requests_Cookie_Jar();

		foreach ( $cookies as $name => $value ) {
			if ( $value instanceof WP_Http_Cookie ) {
				$attributes                 = array_filter(
					$value->get_attributes(),
					static function( $attr ) {
						return null !== $attr;
					}
				);
				$cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $attributes, array( 'host-only' => $value->host_only ) );
			} elseif ( is_scalar( $value ) ) {
				$cookie_jar[ $name ] = new Requests_Cookie( $name, $value );
			}
		}

		return $cookie_jar;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.