Download the PHP package wp-forge/wp-cookie-manager without Composer
On this page you can find all versions of the php package wp-forge/wp-cookie-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wp-forge/wp-cookie-manager
More information about wp-forge/wp-cookie-manager
Files in wp-forge/wp-cookie-manager
Package wp-cookie-manager
Short Description A WordPress library to simplify cookie management.
License GPL-2.0-or-later
Informations about the package wp-cookie-manager
WordPress Cookie Manager
A WordPress library to simplify cookie management.
What It Does
Abstracts away all the PHP cookie management and WordPress cookie constants so you can just get and set cookies.
How to Use It
-
Add to your project via Composer:
-
Make sure you have added the Composer autoloader to your project:
- Start managing cookies
Using the Underlying Cookie Class
The CookieManager provides you with a global way to configure and manage working with cookies. However, if you need to
work with a cookie that needs a very different configuration, you can use the Cookie class directly.
Note that using the Cookie class directly will not use the smart defaults provided by the CookieManager.
Advanced Usage
By default, the CookieManager will use smart, WordPress-specific defaults. These defaults can be overridden and
the steps to do so are outlined below.
Customizable properties
Name Prefix
By default, all cookie names are prefixed with wp-. This can be changed by setting the $namePrefix property.
Name Suffix
By default, all cookie names are suffixed with a - followed by the WordPress COOKIEHASH constant. This can be
changed by setting the$nameSuffix property.
Path
By default, the cookie path is set to the WordPress COOKIEPATH constant. This can be changed by setting the$path
property.
Domain
By default, the cookie domain is set to the WordPress COOKIE_DOMAIN constant. If the COOKIE_DOMAIN is empty, it
falls back to the $_SERVER['HTTP_HOST'] value (i.e. the current domain). This can be overwritten by setting
the$domain property.
Secure
By default, the $secure property is set to the value returned by the is_ssl() WordPress function. Setting the value
to true will ensure that the cookie is only sent over an HTTPS connection. Setting the value to false will ensure
that the cookie is always sent, regardless of whether the connection is encrypted.
HTTP Only
By default, the $httpOnly property is set to false, which means that the cookie will be available in all contexts.
Setting the value to true will ensure that the cookie is only accessible in PHP, not JavaScript. This can be useful to
help prevent identify theft via XSS attacks.