Documentation

Utils
in package

Utility helpers.

Table of Contents

Constants

HOST_TYPE_CURRENT  = 'current'
feat.nip.io
HOST_TYPE_CURRENT_PROTOCOL  = 'current+protocol'
https://feat.nip.io
HOST_TYPE_CURRENT_WITH_ALL_SUBDOMAINS  = 'current+subdomains'
HOST_TYPE_MAIN  = 'main'
nip.io
HOST_TYPE_MAIN_WITH_ALL_SUBDOMAINS  = 'main+subdomains'
PREINSTALLED_ENV_IONOS  = 'ionos'

Methods

anyPluginActive()  : mixed
Checks if any of the given plugins is active. It supports also slugs.
array_flatten()  : mixed
Flatten an array.
currentContentTypeIs()  : mixed
Check if current content type is the given mime type.
endsWith()  : mixed
Check if a string starts with a given needle.
get_admin_colors()  : array<string|int, string>
Get the currently used admin color scheme.
getIpAddress()  : mixed
Get the IP address of the current request.
getOptionRaw()  : mixed
Get the raw value of a `wp_options` value by respecting the object cache. It is not modified through option-filters.
getOriginalHomeUrl()  : mixed
This is needed to get the home_url without any additional pathes (e.g. WPML).
getPermalink()  : string|false
Always create a clone of the post cause we need to force the `post_status` to get the valid permalink.
getPreviewUrl()  : mixed
Get preview or of given post.
getRandomWeightedElement()  : mixed
Pass in an associative array, such as array('A'=>5, 'B'=>45, 'C'=>50).
getRequestUrl()  : mixed
Get the current requested URL.
giveHost()  : mixed
Remove all subdomains from host string.
hash()  : mixed
Hash a passed string. It uses PHP `hash` and md5 as fallback as `hash` is not available in all environments.
host()  : mixed
Get a host URL for technical cookie definitions.
isCLI()  : mixed
Check if current request is coming from WP CLI.
isDownload()  : mixed
Check if the current page request is a download.
isFrontend()  : mixed
Check if current page is frontend page of WordPress.
isPageBuilder()  : mixed
Check if the current request is the editor of a page builder.
isPluginActive()  : mixed
Check if a single plugin is active. It supports also slugs.
isPreinstalledEnvironment()  : string|false
Check if the current installation is a preinstalled environment.
isThemeActive()  : mixed
Check if a single theme is active. It supports parent theme.
posts_where_find_in_set()  : mixed
Allow `find_in_set` in `meta_query` compare functionality.
removeNonPermalinkQueryFromUrl()  : mixed
Remove all query arguments not designed in our permalink structure.
setCookie()  : mixed
Support samesite cookie flag in both php 7.2 (current production) and php >= 7.3 (when we get there) From: https://github.com/GoogleChromeLabs/samesite-examples/blob/master/php.md and https://stackoverflow.com/a/46971326/2308553
startsWith()  : mixed
Check if a string starts with a given needle.

Constants

HOST_TYPE_CURRENT

feat.nip.io

public mixed HOST_TYPE_CURRENT = 'current'

HOST_TYPE_CURRENT_PROTOCOL

https://feat.nip.io

public mixed HOST_TYPE_CURRENT_PROTOCOL = 'current+protocol'

HOST_TYPE_CURRENT_WITH_ALL_SUBDOMAINS

public mixed HOST_TYPE_CURRENT_WITH_ALL_SUBDOMAINS = 'current+subdomains'

.feat.nip.io

HOST_TYPE_MAIN

nip.io

public mixed HOST_TYPE_MAIN = 'main'

HOST_TYPE_MAIN_WITH_ALL_SUBDOMAINS

public mixed HOST_TYPE_MAIN_WITH_ALL_SUBDOMAINS = 'main+subdomains'

.nip.io

PREINSTALLED_ENV_IONOS

public mixed PREINSTALLED_ENV_IONOS = 'ionos'

Methods

anyPluginActive()

Checks if any of the given plugins is active. It supports also slugs.

public static anyPluginActive(string|array<string|int, string> $plugins) : mixed
Parameters
$plugins : string|array<string|int, string>

array_flatten()

Flatten an array.

public static array_flatten(array<string|int, mixed> $array[, bool $recursive = false ]) : mixed
Parameters
$array : array<string|int, mixed>
$recursive : bool = false

endsWith()

Check if a string starts with a given needle.

public static endsWith(string $haystack, string $needle) : mixed
Parameters
$haystack : string

The string to search in

$needle : string

The starting string

Tags
see
https://stackoverflow.com/a/834355/5506547

get_admin_colors()

Get the currently used admin color scheme.

public static get_admin_colors() : array<string|int, string>
Return values
array<string|int, string>

getIpAddress()

Get the IP address of the current request.

public static getIpAddress() : mixed

getOptionRaw()

Get the raw value of a `wp_options` value by respecting the object cache. It is not modified through option-filters.

public static getOptionRaw(string $optionName[, mixed $default = false ]) : mixed
Parameters
$optionName : string
$default : mixed = false

getOriginalHomeUrl()

This is needed to get the home_url without any additional pathes (e.g. WPML).

public static getOriginalHomeUrl() : mixed

Always create a clone of the post cause we need to force the `post_status` to get the valid permalink.

public static getPermalink(WP_Post|number $post) : string|false

This also returns a valid permalink even for trashed or draft posts.

Parameters
$post : WP_Post|number
Tags
see
https://wordpress.stackexchange.com/a/42988/83335
Return values
string|false

getPreviewUrl()

Get preview or of given post.

public static getPreviewUrl(WP_Post $post) : mixed
Parameters
$post : WP_Post

getRequestUrl()

Get the current requested URL.

public static getRequestUrl() : mixed

hash()

Hash a passed string. It uses PHP `hash` and md5 as fallback as `hash` is not available in all environments.

public static hash(string $data) : mixed
Parameters
$data : string

isFrontend()

Check if current page is frontend page of WordPress.

public static isFrontend() : mixed

isPageBuilder()

Check if the current request is the editor of a page builder.

public static isPageBuilder() : mixed

isPluginActive()

Check if a single plugin is active. It supports also slugs.

public static isPluginActive(string $plugin) : mixed
Parameters
$plugin : string

isPreinstalledEnvironment()

Check if the current installation is a preinstalled environment.

public static isPreinstalledEnvironment() : string|false
Return values
string|false

isThemeActive()

Check if a single theme is active. It supports parent theme.

public static isThemeActive(string $slug) : mixed
Parameters
$slug : string

posts_where_find_in_set()

Allow `find_in_set` in `meta_query` compare functionality.

public static posts_where_find_in_set(array<string|int, mixed> $where, object $query) : mixed
Parameters
$where : array<string|int, mixed>
$query : object
Tags
see
https://gist.github.com/mikeschinkel/6402058

removeNonPermalinkQueryFromUrl()

Remove all query arguments not designed in our permalink structure.

public static removeNonPermalinkQueryFromUrl(string $url) : mixed
Parameters
$url : string

setCookie()

Support samesite cookie flag in both php 7.2 (current production) and php >= 7.3 (when we get there) From: https://github.com/GoogleChromeLabs/samesite-examples/blob/master/php.md and https://stackoverflow.com/a/46971326/2308553

public static setCookie(string $name[, string $value = '' ][, int $expire = 0 ][, string $path = '' ][, string $domain = '' ][, bool $secure = false ][, bool $httponly = false ][, string $samesite = '' ]) : mixed
Parameters
$name : string
$value : string = ''
$expire : int = 0
$path : string = ''
$domain : string = ''
$secure : bool = false
$httponly : bool = false
$samesite : string = ''
Tags
see
https://stackoverflow.com/a/59654832/5506547
see
https://developer.mozilla.org/de/docs/Web/HTTP/Headers/Set-Cookie/SameSite

startsWith()

Check if a string starts with a given needle.

public static startsWith(string $haystack, string $needle) : mixed
Parameters
$haystack : string

The string to search in

$needle : string

The starting string

Tags
see
https://stackoverflow.com/a/834355/5506547

        
On this page

Search results