Utilities
Common utility methods.
Tags
Table of Contents
- createLdJsonTag() : string
- createLinkTag() : string
- createMetaPropertyTag() : string
- createMetaTag() : string
- getImageDimension() : int
- Retrieve the image size dimension. For example, to retrieve the height dimension of a "large" Wordpress/Timber image:
- getRemoteImageDim() : array<string|int, mixed>
- Fetch a remote image's size dimensions.
- hasKey() : bool
- Performs a case-insensitive key check.
- splitter() : array<string|int, string>
- Splits a string by a token. Default token is a space. Essentially a wrapper for explode() to catch errors.
- staticUrl() : string
- Builds a static assets URL. The constant ASSETS_URL should be set to generate absolute URLs.
- stringArrayUnique() : array<string|int, string>
- Returns a unique array of strings. If $removeEmpty is set, the function will remove any empty values by applying array_filter().
- toCarbonObj() : Carbon
- Converts a mixed value (int|string) into a Carbon date object. An optional timezone can be passed. If no timezone is passed, the value of wp_timezone() is assumed.
- triggerError() : void
- Shortcut to log an error and then display the error to the user (Wordpress default behavior).
- validateUrlExtension() : bool
- Validates that a URL string uses an allowed extension.
Methods
createLdJsonTag()
public
static createLdJsonTag(array<string|int, mixed> $src) : string
Parameters
- $src : array<string|int, mixed>
Return values
string —createLinkTag()
public
static createLinkTag(string $rel, string $url[, string $type = '' ][, string $title = '' ]) : string
Parameters
- $rel : string
- $url : string
- $type : string = ''
- $title : string = ''
Return values
string —createMetaPropertyTag()
public
static createMetaPropertyTag(string $name, string $value) : string
Parameters
- $name : string
- $value : string
Return values
string —createMetaTag()
public
static createMetaTag(string $name, string $value) : string
Parameters
- $name : string
- $value : string
Return values
string —getImageDimension()
Retrieve the image size dimension. For example, to retrieve the height dimension of a "large" Wordpress/Timber image:
public
static getImageDimension(Image $image, string $size, string $dim) : int
getImageDimension($image, 'large', 'height');
Parameters
- $image : Image
- $size : string
- $dim : string
Return values
int —getRemoteImageDim()
Fetch a remote image's size dimensions.
public
static getRemoteImageDim(string $url[, array<string|int, mixed> $allowed = [] ]) : array<string|int, mixed>
Parameters
- $url : string
- $allowed : array<string|int, mixed> = []
-
Optional, allowed image types. e.g. png, gif, jpg...
Tags
Return values
array<string|int, mixed> —hasKey()
Performs a case-insensitive key check.
public
static hasKey(mixed $key, array<string|int, mixed> $array) : bool
Parameters
- $key : mixed
- $array : array<string|int, mixed>
Return values
bool —splitter()
Splits a string by a token. Default token is a space. Essentially a wrapper for explode() to catch errors.
public
static splitter(string $str[, string $token = ' ' ]) : array<string|int, string>
Parameters
- $str : string
- $token : string = ' '
-
Optional
Return values
array<string|int, string> —staticUrl()
Builds a static assets URL. The constant ASSETS_URL should be set to generate absolute URLs.
public
static staticUrl(string $path) : string
Parameters
- $path : string
-
The relative path of the asset.
Return values
string —stringArrayUnique()
Returns a unique array of strings. If $removeEmpty is set, the function will remove any empty values by applying array_filter().
public
static stringArrayUnique(array<string|int, mixed> $strings[, bool $removeEmpty = false ]) : array<string|int, string>
Parameters
- $strings : array<string|int, mixed>
- $removeEmpty : bool = false
-
Optional, default is false.
Return values
array<string|int, string> —toCarbonObj()
Converts a mixed value (int|string) into a Carbon date object. An optional timezone can be passed. If no timezone is passed, the value of wp_timezone() is assumed.
public
static toCarbonObj(mixed $value[, string $timezone = null ]) : Carbon
Parameters
- $value : mixed
- $timezone : string = null
-
Optional, default is wp_timezone().
Return values
Carbon —triggerError()
Shortcut to log an error and then display the error to the user (Wordpress default behavior).
public
static triggerError(LoggerInterface $logger, string $message[, array<string|int, mixed> $extra = [] ]) : void
Parameters
- $logger : LoggerInterface
- $message : string
- $extra : array<string|int, mixed> = []
Return values
void —validateUrlExtension()
Validates that a URL string uses an allowed extension.
public
static validateUrlExtension(string $url, array<string|int, mixed> $allowed) : bool
Parameters
- $url : string
- $allowed : array<string|int, mixed>