Documentation

Utilities
in package

AbstractYes

A few tools for managing things.

Table of Contents

Constants

PLUGIN_UPDATE_TRANSIENT  = \tp\TouchPointWP\TouchPointWP::SETTINGS_PREFIX . "plugin_update_data"
PLUGIN_UPDATE_TRANSIENT_TTL  = 43200

Methods

checkForUpdate()  : object|null
Returns true if a new release is available.
checkForUpdate_transient()  : mixed
createGuid()  : string
Generates a Microsoft-friendly globally unique identifier (Guid).
dateTimeNow()  : DateTimeImmutable
fileHeadersFromString()  : array<string|int, mixed>|null
fileHeadersFromWeb()  : array<string|int, mixed>|null
getAllHeaders()  : array<string|int, mixed>
Get all HTTP request headers.
getClientIp()  : string|null
getColorFor()  : string
Arbitrarily pick a unique-ish color for a value.
getDayOfWeekShortForNumber()  : string
getDayOfWeekShortForNumber_noI18n()  : string
NOT internationalized, such as for slugs
getPluralDayOfWeekNameForNumber()  : string
Gets the plural form of a weekday name.
getPluralDayOfWeekNameForNumber_noI18n()  : string
Gets the plural form of a weekday name, but without translation for use in places like slugs.
getPostContentWithShortcode()  : array<string|int, object>
Gets the post content for all posts that contain a particular shortcode.
getTimeOfDayTermForTime()  : string
Gets the non-specific time of day in words.
getTimeOfDayTermForTime_noI18n()  : string
hslToHex()  : string
Convert HSL color to RGB Color
idArrayToIntArray()  : array<string|int, int>|string
Convert a list (string or array) to an int array. Strips out non-numerics and explodes.
insertTerm()  : array<string|int, mixed>|WP_Error
Wrapper for the WordPress wp_insert_term function to reduce database calls
standardizeHTags()  : string
standardizeHtml()  : string
stringArrayToListString()  : string
Join an array of strings into a properly-formatted (English-style) list. Uses commas and ampersands by default.
termExists()  : mixed
Wrapper for the WordPress term_exists function to reduce database calls
toFloatOrNull()  : float|null
updatePostImageFromUrl()  : void
Updates or removes a post's featured image from a URL (e.g. from TouchPoint).
validateMessage()  : bool
Determine if an email address or user should be accepted as a new registrant. (e.g. informal auth)
validateRegistrantEmailAddress()  : bool
Determine if an email address or user should be accepted as a new registrant. (e.g. informal auth)

Constants

PLUGIN_UPDATE_TRANSIENT

public mixed PLUGIN_UPDATE_TRANSIENT = \tp\TouchPointWP\TouchPointWP::SETTINGS_PREFIX . "plugin_update_data"

PLUGIN_UPDATE_TRANSIENT_TTL

public mixed PLUGIN_UPDATE_TRANSIENT_TTL = 43200

Methods

checkForUpdate()

Returns true if a new release is available.

public static checkForUpdate() : object|null
Return values
object|null

checkForUpdate_transient()

public static checkForUpdate_transient(mixed $transient) : mixed
Parameters
$transient : mixed

createGuid()

Generates a Microsoft-friendly globally unique identifier (Guid).

public static createGuid() : string
Return values
string

A new random globally unique identifier.

dateTimeNow()

public static dateTimeNow() : DateTimeImmutable
Return values
DateTimeImmutable

fileHeadersFromString()

public static fileHeadersFromString(string $data[, array<string|int, mixed> $headers = [] ]) : array<string|int, mixed>|null
Parameters
$data : string
$headers : array<string|int, mixed> = []
Return values
array<string|int, mixed>|null

fileHeadersFromWeb()

public static fileHeadersFromWeb(string $url[, array<string|int, mixed> $headers = [] ]) : array<string|int, mixed>|null
Parameters
$url : string
$headers : array<string|int, mixed> = []
Return values
array<string|int, mixed>|null

getAllHeaders()

Get all HTTP request headers.

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

getClientIp()

public static getClientIp() : string|null
Return values
string|null

getColorFor()

Arbitrarily pick a unique-ish color for a value.

public static getColorFor(string $itemName, string $setName) : string
Parameters
$itemName : string

The name of the item. e.g. PA

$setName : string

The name of the set to which the item belongs, within which there should be uniqueness. e.g. States

Return values
string

The color in hex, starting with '#'.

getDayOfWeekShortForNumber()

public static getDayOfWeekShortForNumber(int $dayNum) : string
Parameters
$dayNum : int
Return values
string

getDayOfWeekShortForNumber_noI18n()

NOT internationalized, such as for slugs

public static getDayOfWeekShortForNumber_noI18n(int $dayNum) : string
Parameters
$dayNum : int
Return values
string

getPluralDayOfWeekNameForNumber()

Gets the plural form of a weekday name.

public static getPluralDayOfWeekNameForNumber(int $dayNum) : string
Parameters
$dayNum : int
Return values
string

Plural weekday (e.g. Mondays)

getPluralDayOfWeekNameForNumber_noI18n()

Gets the plural form of a weekday name, but without translation for use in places like slugs.

public static getPluralDayOfWeekNameForNumber_noI18n(int $dayNum) : string
Parameters
$dayNum : int
Return values
string

Plural weekday (e.g. Mondays)

getPostContentWithShortcode()

Gets the post content for all posts that contain a particular shortcode.

public static getPostContentWithShortcode( $shortcode) : array<string|int, object>
Parameters
$shortcode :

TODO MULTI: does not update for all sites in the network.

Return values
array<string|int, object>

getTimeOfDayTermForTime()

Gets the non-specific time of day in words.

public static getTimeOfDayTermForTime(DateTimeInterface $dt[, bool $i18n = true ]) : string

Translation: These are deliberately not scoped to TouchPoint-WP, so if the translation exists globally, it should work here.

Parameters
$dt : DateTimeInterface
$i18n : bool = true
Return values
string

getTimeOfDayTermForTime_noI18n()

public static getTimeOfDayTermForTime_noI18n(DateTimeInterface $dt) : string
Parameters
$dt : DateTimeInterface
Return values
string

hslToHex()

Convert HSL color to RGB Color

public static hslToHex(int $h, int $s, int $l) : string
Parameters
$h : int

Hue (0-365)

$s : int

Saturation (0-100)

$l : int

Luminosity (0-100)

Tags
cite

Adapted from https://stackoverflow.com/a/44134328/2339939

license

CC BY-SA 4.0

Return values
string

idArrayToIntArray()

Convert a list (string or array) to an int array. Strips out non-numerics and explodes.

public static idArrayToIntArray(string|array<string|int, mixed> $r[, mixed $explode = true ]) : array<string|int, int>|string
Parameters
$r : string|array<string|int, mixed>
$explode : mixed = true
Return values
array<string|int, int>|string

insertTerm()

Wrapper for the WordPress wp_insert_term function to reduce database calls

public static insertTerm(string $term, string $taxonomy[, array<string|int, mixed>|string $args = [] ]) : array<string|int, mixed>|WP_Error

Add a new term to the database.

A non-existent term is inserted in the following sequence:

  1. The term is added to the term table, then related to the taxonomy.
  2. If everything is correct, several actions are fired.
  3. The 'term_id_filter' is evaluated.
  4. The term cache is cleaned.
  5. Several more actions are fired.
  6. An array is returned containing the term_id and term_taxonomy_id.

If the 'slug' argument is not empty, then it is checked to see if the term is invalid. If it is not a valid, existing term, it is added and the term_id is given.

If the taxonomy is hierarchical, and the 'parent' argument is not empty, the term is inserted and the term_id will be given.

Error handling: If $taxonomy does not exist or $term is empty, a WP_Error object will be returned.

If the term already exists on the same hierarchical level, or the term slug and name are not unique, a WP_Error object will be returned.

Parameters
$term : string

The term name to add.

$taxonomy : string

The taxonomy to which to add the term.

$args : array<string|int, mixed>|string = []

{ Optional. Array or query string of arguments for inserting a term.

Tags
type

string $alias_of Slug of the term to make this term an alias of. Default empty string. Accepts a term slug.

type

string $description The term description. Default empty string.

type

int $parent The id of the parent term. Default 0.

type

string $slug The term slug to use. Default empty string. }

type

int $term_id The new term ID.

type

int|string $term_taxonomy_id The new term taxonomy ID. Can be a numeric string. }

see
wp_insert_term()
Return values
array<string|int, mixed>|WP_Error

{ An array of the new term data, WP_Error otherwise.

standardizeHTags()

public static standardizeHTags(int $maxAllowed, string $input) : string
Parameters
$maxAllowed : int

1 to 6, corresponding to h1 to h6.

$input : string

The string within which headings should be standardized.

Return values
string

standardizeHtml()

public static standardizeHtml(string $html[, string|null $context = null ]) : string
Parameters
$html : string

The HTML to be standardized.

$context : string|null = null

A context string to pass to hooks.

Return values
string

stringArrayToListString()

Join an array of strings into a properly-formatted (English-style) list. Uses commas and ampersands by default.

public static stringArrayToListString(array<string|int, string> $strings) : string

This will switch to written "and" when an ampersand is present in a string, and will use semi-colons instead of commas when commas are already present.

Turn ['apples', 'oranges', 'pears'] into "apples, oranges & pears"

Parameters
$strings : array<string|int, string>
Return values
string

termExists()

Wrapper for the WordPress term_exists function to reduce database calls

public static termExists(int|string $term[, string $taxonomy = "" ][, int|null $parent = null ]) : mixed
Parameters
$term : int|string

The term to check. Accepts term ID, slug, or name.

$taxonomy : string = ""

Optional. The taxonomy name to use.

$parent : int|null = null

Optional. ID of parent term under which to confine the exists search.

Tags
see
term_exists()
Return values
mixed

Returns null if the term does not exist. Returns the term ID if no taxonomy is specified and the term ID exists. Returns an array of the term ID and the term taxonomy ID if the taxonomy is specified and the pairing exists. Returns 0 if term ID 0 is passed to the function.

toFloatOrNull()

public static toFloatOrNull(mixed $numeric[, bool|int $round = false ]) : float|null
Parameters
$numeric : mixed
$round : bool|int = false

False to skip rounding. Otherwise, precision passed to round().

Tags
see
round()
Return values
float|null

updatePostImageFromUrl()

Updates or removes a post's featured image from a URL (e.g. from TouchPoint).

public static updatePostImageFromUrl(int $postId, string|null $newUrl, string $title) : void

If the $newUrl is blank or null, the image is removed.

Parameters
$postId : int
$newUrl : string|null
$title : string
Tags
since
0.0.24

validateMessage()

Determine if an email address or user should be accepted as a new registrant. (e.g. informal auth)

public static validateMessage(string|null $nickname, string|null $emailAddress, string|null $message[, string|null &$resultComment = null ]) : bool
Parameters
$nickname : string|null
$emailAddress : string|null
$message : string|null
$resultComment : string|null = null

If a spam provider provides a comment about why content was allowed or rejected, it goes here.

Return values
bool

True if acceptable, false if not acceptable.

validateRegistrantEmailAddress()

Determine if an email address or user should be accepted as a new registrant. (e.g. informal auth)

public static validateRegistrantEmailAddress(string|null $nickname, string|null $emailAddress[, string|null &$resultComment = null ]) : bool
Parameters
$nickname : string|null
$emailAddress : string|null
$resultComment : string|null = null

If a spam provider provides a comment about why content was allowed or rejected, it goes here.

Return values
bool

True if acceptable, false if not acceptable.


        
On this page

Search results