Util

Utilities

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

Table of Contents

add_inline_script_params()  : mixed
Helper function to replace wp_localize_script
associate_attachment()  : mixed
Associated attachment to post.
create_page()  : int
Create a page and store the ID in an option. (adapted from WooCommerce)
disassociate_attachment()  : mixed
Disassociate attachment to post.
get_document_display_fields()  : array<string|int, mixed>
Retrieve the single document display option.
get_document_fields()  : array<string|int, mixed>
Retrive the Document post type fields.
get_the_fake_linked_term_names()  : string
Retrieve a linked list of terms (for Author and File Types).
is_acf_active()  : bool
Check if the Advanced Custom Fields plugin is active.
is_ept_active()  : bool
Check if the Easy Post Types plugin is active.
normalize_user_arguments()  : array<string|int, mixed>
Normalize user arguments provided to shortcode.
round()  : float
Round a number using the built-in `round` function, but unless the value to round is numeric (a number or a string that can be parsed as a number), apply 'floatval' first to it (so it will convert it to 0 in most cases).
sanitize_array_recursive()  : mixed
Sanitize array recursively.
str_ends_with()  : bool
Determins if a string ends with another string
string_to_bool()  : bool
Converts a string (e.g. 'yes' or 'no') to a bool.

Methods

add_inline_script_params()

Helper function to replace wp_localize_script

public static add_inline_script_params(string $script_handle, string $variable_name, array<string|int, mixed> $script_params) : mixed
Parameters
$script_handle : string
$variable_name : string
$script_params : array<string|int, mixed>
Tags
Return values
mixed

associate_attachment()

Associated attachment to post.

public static associate_attachment(mixed $attachment_id, mixed $post_id) : mixed
Parameters
$attachment_id : mixed
$post_id : mixed
Tags
Return values
mixed

create_page()

Create a page and store the ID in an option. (adapted from WooCommerce)

public static create_page(mixed $slug[, string $option = '' ][, string $page_title = '' ][, string $page_content = '' ], int $post_parent) : int
Parameters
$slug : mixed

Slug for the new page.

$option : string = ''

Option name to store the page's ID.

$page_title : string = ''

(default: '') Title for the new page.

$page_content : string = ''

(default: '') Content for the new page.

$post_parent : int

(default: 0) Parent for the new page.

Tags
Return values
int

page ID.

disassociate_attachment()

Disassociate attachment to post.

public static disassociate_attachment(mixed $attachment_id) : mixed
Parameters
$attachment_id : mixed
Tags
Return values
mixed

get_document_display_fields()

Retrieve the single document display option.

public static get_document_display_fields() : array<string|int, mixed>
Tags
deprecated
Return values
array<string|int, mixed>

get_document_fields()

Retrive the Document post type fields.

public static get_document_fields() : array<string|int, mixed>
Tags
deprecated
Return values
array<string|int, mixed>

get_the_fake_linked_term_names()

Retrieve a linked list of terms (for Author and File Types).

public static get_the_fake_linked_term_names(WP_Post $post, string $taxonomy[, string $sep = ', ' ]) : string
Parameters
$post : WP_Post
$taxonomy : string
$sep : string = ', '
Tags
Return values
string

is_acf_active()

Check if the Advanced Custom Fields plugin is active.

public static is_acf_active() : bool
Tags
Return values
bool

is_ept_active()

Check if the Easy Post Types plugin is active.

public static is_ept_active() : bool
Tags
Return values
bool

normalize_user_arguments()

Normalize user arguments provided to shortcode.

public static normalize_user_arguments(array<string|int, mixed> $args) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed>
Tags
deprecated
Return values
array<string|int, mixed>

round()

Round a number using the built-in `round` function, but unless the value to round is numeric (a number or a string that can be parsed as a number), apply 'floatval' first to it (so it will convert it to 0 in most cases).

public static round(mixed $val, int $precision[, int $mode = PHP_ROUND_HALF_UP ]) : float

This is needed because in PHP 7 applying round to a non-numeric value returns 0, but in PHP 8 it throws an error. Specifically, in WooCommerce we have a few places where round('') is often executed.

Parameters
$val : mixed

The value to round.

$precision : int

The optional number of decimal digits to round to.

$mode : int = PHP_ROUND_HALF_UP

A constant to specify the mode in which rounding occurs.

Tags
Return values
float

The value rounded to the given precision as a float, or the supplied default value.

sanitize_array_recursive()

Sanitize array recursively.

public static sanitize_array_recursive(mixed $array) : mixed
Parameters
$array : mixed
Tags
Return values
mixed

str_ends_with()

Determins if a string ends with another string

public static str_ends_with(string $haystack, string $needle) : bool
Parameters
$haystack : string
$needle : string
Tags
Return values
bool

string_to_bool()

Converts a string (e.g. 'yes' or 'no') to a bool.

public static string_to_bool(string|bool $string) : bool
Parameters
$string : string|bool

String to convert. If a bool is passed it will be returned as-is.

Tags
Return values
bool

Search results