Util
Utility functions for Posts Table Pro.
Tags
Table of Contents
- TABLE_CLASS = 'posts-data-table'
- TABLE_WRAPPER_CLASS = 'posts-table-wrapper'
- array_diff_assoc() : array<string|int, mixed>
- Similar to <code>array_diff_assoc</code>, but does a loose type comparison on array values (== not ===).
- array_pad_and_slice() : array<string|int, mixed>
- Combination of array_pad and array_slice.
- convert_to_term_ids() : mixed
- doing_lazy_load() : mixed
- empty_if_false() : mixed
- format_post_link() : mixed
- get_acf_field_object() : mixed
- get_all_term_children() : mixed
- get_asset_url() : mixed
- get_image_size_width() : mixed
- get_language_strings() : mixed
- get_pages() : array<string|int, mixed>
- Get an array of WP Pages [ ID => Post Title ]
- get_table_class() : mixed
- get_the_term_names() : mixed
- get_wrapper_class() : mixed
- include_template() : mixed
- is_acf_active() : mixed
- is_european_date_format() : mixed
- is_unix_epoch_time() : bool
- Is the value passed a valid UNIX epoch time (i.e. seconds elapsed since 1st January 1970)?
- is_valid_search_term() : mixed
- jquery_to_php_date_format() : string
- Convert a jQuery date format to a PHP one. E.g. 'dd-mm-yy' becomes 'd-m-Y'.
- list_pluck_array() : array<string|int, mixed>
- Similar to <code>wp_list_pluck</code> or <code>array_column</code> but plucks several keys from the source array.
- maybe_parse_bool() : mixed
- parse_term_arg() : array<string|int, mixed>
- Parse a string term arg, as specified in the table shortcode, into a sorted array.
- sanitize_class_name() : mixed
- sanitize_enum() : mixed
- sanitize_enum_or_bool() : mixed
- sanitize_image_size() : mixed
- sanitize_list() : mixed
- sanitize_list_and_space() : mixed
- sanitize_list_arg() : mixed
- sanitize_list_arg_allow_space() : mixed
- sanitize_list_or_bool() : mixed
- sanitize_numeric_list() : mixed
- sanitize_numeric_list_arg() : mixed
- sanitize_string_or_bool_arg() : mixed
- set_object_vars() : mixed
- string_list_to_array() : mixed
- strtotime() : int|bool
- Convert a date string to a timestamp. A wrapper around strtotime which accounts for dates already formatted as a timestamp.
Constants
TABLE_CLASS
public
mixed
TABLE_CLASS
= 'posts-data-table'
Tags
TABLE_WRAPPER_CLASS
public
mixed
TABLE_WRAPPER_CLASS
= 'posts-table-wrapper'
Tags
Methods
array_diff_assoc()
Similar to <code>array_diff_assoc</code>, but does a loose type comparison on array values (== not ===).
public
static array_diff_assoc(array<string|int, mixed> $array1, array<string|int, mixed> $array2) : array<string|int, mixed>
Supports multi-dimensional arrays, but doesn't support passing more than two arrays.
Parameters
- $array1 : array<string|int, mixed>
-
The main array to compare against
- $array2 : array<string|int, mixed>
-
The array to compare with
Tags
Return values
array<string|int, mixed> —All entries in $array1 which are not present in $array2 (including key check)
array_pad_and_slice()
Combination of array_pad and array_slice.
public
static array_pad_and_slice(array<string|int, mixed> $array, int $size, mixed $pad) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>
-
Input array
- $size : int
-
The size of the array to return
- $pad : mixed
-
What to pad with
Tags
Return values
array<string|int, mixed> —The result
convert_to_term_ids()
public
static convert_to_term_ids(mixed $terms, mixed $taxonomy) : mixed
Parameters
- $terms : mixed
- $taxonomy : mixed
Tags
Return values
mixed —doing_lazy_load()
public
static doing_lazy_load() : mixed
Tags
Return values
mixed —empty_if_false()
public
static empty_if_false(mixed $var) : mixed
Parameters
- $var : mixed
Tags
Return values
mixed —format_post_link()
public
static format_post_link(mixed $post[, mixed $link_text = '' ][, mixed $link_class = '' ]) : mixed
Parameters
- $post : mixed
- $link_text : mixed = ''
- $link_class : mixed = ''
Tags
Return values
mixed —get_acf_field_object()
public
static get_acf_field_object(mixed $field[, mixed $post_id = false ]) : mixed
Parameters
- $field : mixed
- $post_id : mixed = false
Tags
Return values
mixed —get_all_term_children()
public
static get_all_term_children(mixed $term_ids, mixed $taxonomy[, mixed $include_parents = false ]) : mixed
Parameters
- $term_ids : mixed
- $taxonomy : mixed
- $include_parents : mixed = false
Tags
Return values
mixed —get_asset_url()
public
static get_asset_url([mixed $path = '' ]) : mixed
Parameters
- $path : mixed = ''
Tags
Return values
mixed —get_image_size_width()
public
static get_image_size_width(mixed $size) : mixed
Parameters
- $size : mixed
Tags
Return values
mixed —get_language_strings()
public
static get_language_strings(mixed $post_type) : mixed
Parameters
- $post_type : mixed
Tags
Return values
mixed —get_pages()
Get an array of WP Pages [ ID => Post Title ]
public
static get_pages() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_table_class()
public
static get_table_class() : mixed
Tags
Return values
mixed —get_the_term_names()
public
static get_the_term_names(mixed $post, mixed $taxonomy[, mixed $sep = ', ' ]) : mixed
Parameters
- $post : mixed
- $taxonomy : mixed
- $sep : mixed = ', '
Tags
Return values
mixed —get_wrapper_class()
public
static get_wrapper_class() : mixed
Tags
Return values
mixed —include_template()
public
static include_template(mixed $template_name) : mixed
Parameters
- $template_name : mixed
Tags
Return values
mixed —is_acf_active()
public
static is_acf_active() : mixed
Tags
Return values
mixed —is_european_date_format()
public
static is_european_date_format(mixed $format) : mixed
Parameters
- $format : mixed
Tags
Return values
mixed —is_unix_epoch_time()
Is the value passed a valid UNIX epoch time (i.e. seconds elapsed since 1st January 1970)?
public
static is_unix_epoch_time(mixed $value) : bool
Not a perfect implementation as it will return false for valid timestamps representing dates between 31st October 1966 and 3rd March 1973, but this is needed to prevent valid dates held in numeric formats (e.g. 20171201) being wrongly interpreted as timestamps.
Parameters
- $value : mixed
-
The value to check
Tags
Return values
bool —True if $value is a valid epoch timestamp
is_valid_search_term()
public
static is_valid_search_term(mixed $search_term) : mixed
Parameters
- $search_term : mixed
Tags
Return values
mixed —jquery_to_php_date_format()
Convert a jQuery date format to a PHP one. E.g. 'dd-mm-yy' becomes 'd-m-Y'.
public
static jquery_to_php_date_format(string $jquery_date_format) : string
Parameters
- $jquery_date_format : string
-
The jQuery date format to convert.
Tags
Return values
string —The equivalent PHP date format.
list_pluck_array()
Similar to <code>wp_list_pluck</code> or <code>array_column</code> but plucks several keys from the source array.
public
static list_pluck_array(array<string|int, mixed> $list[, array<string|int, mixed>|string $keys = [] ]) : array<string|int, mixed>
Parameters
- $list : array<string|int, mixed>
-
The array of arrays to extract the keys from
- $keys : array<string|int, mixed>|string = []
-
The list of keys to pluck
Tags
Return values
array<string|int, mixed> —An array returned in the same order as $list, but where each item in the array contains just the specified $keys
maybe_parse_bool()
public
static maybe_parse_bool(mixed $maybe_bool) : mixed
Parameters
- $maybe_bool : mixed
Tags
Return values
mixed —parse_term_arg()
Parse a string term arg, as specified in the table shortcode, into a sorted array.
public
static parse_term_arg(string $term_arg[, bool $include_relations = false ]) : array<string|int, mixed>
Terms args are specified as a list of items in the format taxonomy:slug or taxonomy:term_id. The slugs/ids can be specified without the taxonomy if they belong to the previous taxonomy, e.g. some_category:term1,term2,term3. Terms can be separated by a comma to denote term1 OR term2 or a plus (+) to denote term1 AND term2. The same notation can be used between taxonomies.
The result is an array of arrays, with each key being the taxonomy name, where the corresponding value is an array of terms to select in that taxonomy.
If $include_relations is true, an additional '_relations' key is returned in the result, which itself is an array of the form 'taxonomy' => 'relation', where 'relation' is either 'AND' or 'OR'. If there are 2 or more taxonomies specified, the '_relations' key will also contain an '_outer' key which denotes the relation between the taxonomies.
Example: parse_term_arg( 'document_type:policy+regulations,document_status:approved', true )
Returns: [ _relations => [ _outer => OR, document_type => AND ], document_type => [ policy, regulations ] document_status => [ approved ] ]
Parameters
- $term_arg : string
-
The term arg to parse.
- $include_relations : bool = false
-
Whether to include the relationships between terms and taxonomies (OR, AND, etc) in the result.
Tags
Return values
array<string|int, mixed> —The sorted terms, keyed by taxonomy.
sanitize_class_name()
public
static sanitize_class_name(mixed $class) : mixed
Parameters
- $class : mixed
Tags
Return values
mixed —sanitize_enum()
public
static sanitize_enum(mixed $value) : mixed
Parameters
- $value : mixed
Tags
Return values
mixed —sanitize_enum_or_bool()
public
static sanitize_enum_or_bool(mixed $value) : mixed
Parameters
- $value : mixed
Tags
Return values
mixed —sanitize_image_size()
public
static sanitize_image_size(mixed $image_size) : mixed
Parameters
- $image_size : mixed
Tags
Return values
mixed —sanitize_list()
public
static sanitize_list(mixed $value) : mixed
Parameters
- $value : mixed
Tags
Return values
mixed —sanitize_list_and_space()
public
static sanitize_list_and_space(mixed $value) : mixed
Parameters
- $value : mixed
Tags
Return values
mixed —sanitize_list_arg()
public
static sanitize_list_arg(mixed $arg[, mixed $allow_space = null ]) : mixed
Parameters
- $arg : mixed
- $allow_space : mixed = null
Tags
Return values
mixed —sanitize_list_arg_allow_space()
public
static sanitize_list_arg_allow_space(mixed $arg) : mixed
Parameters
- $arg : mixed
Tags
Return values
mixed —sanitize_list_or_bool()
public
static sanitize_list_or_bool(mixed $value) : mixed
Parameters
- $value : mixed
Tags
Return values
mixed —sanitize_numeric_list()
public
static sanitize_numeric_list(mixed $value) : mixed
Parameters
- $value : mixed
Tags
Return values
mixed —sanitize_numeric_list_arg()
public
static sanitize_numeric_list_arg(mixed $arg) : mixed
Parameters
- $arg : mixed
Tags
Return values
mixed —sanitize_string_or_bool_arg()
public
static sanitize_string_or_bool_arg(mixed $arg) : mixed
Parameters
- $arg : mixed
Tags
Return values
mixed —set_object_vars()
public
static set_object_vars(mixed $object, array<string|int, mixed> $vars) : mixed
Parameters
- $object : mixed
- $vars : array<string|int, mixed>
Tags
Return values
mixed —string_list_to_array()
public
static string_list_to_array(mixed $arg) : mixed
Parameters
- $arg : mixed
Tags
Return values
mixed —strtotime()
Convert a date string to a timestamp. A wrapper around strtotime which accounts for dates already formatted as a timestamp.
public
static strtotime(string $date) : int|bool
Parameters
- $date : string
-
The date to convert to a timestamp.
Tags
Return values
int|bool —The timestamp (number of seconds since the Epoch) for this date, or false on failure.