cookie_consent
cookie_consent trait - Advanced set cookies using WP Consent API
Tags
Table of Contents
- $cookie_default_service : string
- cookie_consent_patch() : void
- enqueue javascripts to patch consent interface between browser and server
- get_cookie() : string
- get a cookie (convenience method, since we have set_cookie)
- get_cookie_consent() : array<string|int, mixed>
- get a registered cookie consent array for a single cookie or all cookies
- has_cookie_consent() : bool
- check consent is loaded and category set (convenience method)
- set_cookie() : bool
- set a cookie supporting wp_consent if enabled
- set_cookie_consent() : array<string|int, mixed>
- set a cookie's consent information
- set_cookie_expiration() : array<string|int, mixed>
- set a cookie expiration as integer and string
Properties
$cookie_default_service
public
string
$cookie_default_service
= ''
default consent service name (set by using class)
Methods
cookie_consent_patch()
enqueue javascripts to patch consent interface between browser and server
public
cookie_consent_patch() : void
Return values
void —get_cookie()
get a cookie (convenience method, since we have set_cookie)
public
get_cookie(string|array<string|int, mixed> $name[, string $default = null ]) : string
Parameters
- $name : string|array<string|int, mixed>
-
the cookie name (and alternates)
- $default : string = null
-
if cookie not set
Return values
string —cookie value
get_cookie_consent()
get a registered cookie consent array for a single cookie or all cookies
public
get_cookie_consent([string $name = false ]) : array<string|int, mixed>
Parameters
- $name : string = false
-
the cookie name (optional)
Return values
array<string|int, mixed> —$consent or array of [name => $consent]
has_cookie_consent()
check consent is loaded and category set (convenience method)
public
has_cookie_consent([string $category = null ]) : bool
Parameters
- $category : string = null
-
consent category to check.
Return values
bool —set_cookie()
set a cookie supporting wp_consent if enabled
public
set_cookie(string|array<string|int, mixed> $name, mixed $value, string|int $expires[, array<string|int, mixed> $options = [] ][, mixed $consent = [] ]) : bool
Parameters
- $name : string|array<string|int, mixed>
-
the cookie name
- $value : mixed
-
the cookie value
- $expires : string|int
-
cookie expiration in seconds or timestamp or string 'delete', 'expired', 'session', 'n days', 'n months', etc.
- $options : array<string|int, mixed> = []
-
cookie parameters 'path', 'domain', 'secure', 'httponly', 'samesite'.
- $consent : mixed = []
-
(array) consent parameters or (string) category or true = already registered 'plugin_or_service', 'category', 'function', ...
Return values
bool —success or failure (as best we can tell)
set_cookie_consent()
set a cookie's consent information
public
set_cookie_consent(string $name, array<string|int, mixed>|string $consent[, bool $register = true ][, array<string|int, mixed> $defaults = [] ]) : array<string|int, mixed>
Parameters
- $name : string
-
the cookie name
- $consent : array<string|int, mixed>|string
-
consent parameters or category 'plugin_or_service', 'category', 'function', ...
- $register : bool = true
-
with wp_add_cookie_info()
- $defaults : array<string|int, mixed> = []
-
default consent parameters
Return values
array<string|int, mixed> —$consent
set_cookie_expiration()
set a cookie expiration as integer and string
public
set_cookie_expiration(string|int $expires[, bool $getString = true ]) : array<string|int, mixed>
Parameters
- $expires : string|int
-
cookie expiration in seconds or timestamp or string 'delete', 'expired', 'session', 'n days', 'n months', etc.
- $getString : bool = true
-
(false) return array when true
Return values
array<string|int, mixed> —[ $expInt, $expStr ]