WP_Http::normalize_cookies( array $cookies ): WpOrgRequestsCookieJar

Normalizes cookies for using in Requests.


Parameters

$cookies array Required
Array of cookies to send with the request.

Top ↑

Return

WpOrgRequestsCookieJar Cookie holder object.


Top ↑

Source

File: wp-includes/class-wp-http.php. View all references

public static function normalize_cookies( $cookies ) {
	$cookie_jar = new WpOrg\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 WpOrg\Requests\Cookie( $value->name, $value->value, $attributes, array( 'host-only' => $value->host_only ) );
		} elseif ( is_scalar( $value ) ) {
			$cookie_jar[ $name ] = new WpOrg\Requests\Cookie( $name, (string) $value );
		}
	}

	return $cookie_jar;
}


Top ↑

Changelog

Changelog
Version Description
4.6.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.