WooCommerce Code Reference

Util
in package

Utility functions.

Table of Contents

array_flatten()  : RecursiveIteratorIterator
Flatten an array.
array_to_insert_sql()  : false|string
Convert an array to an insert SQL query.
camel_to_snake()  : string
Convert a string from camelCase to snake_case.
delete_dir()  : void
Recursively delete a directory.
ensure_wp_content_path()  : string
Ensure that the given path is a valid path within the WP_CONTENT_DIR.
index_array()  : array<string|int, mixed>
Index an array using a callback function.
is_valid_wp_plugin_slug()  : bool
Check to see if given string is a valid WordPress plugin slug.
snake_to_camel()  : string
Convert a string from snake_case to camelCase.

Methods

array_flatten()

Flatten an array.

public static array_flatten(array<string|int, mixed> $array_to_flatten) : RecursiveIteratorIterator
Parameters
$array_to_flatten : array<string|int, mixed>

The array to be flattened.

Return values
RecursiveIteratorIterator

array_to_insert_sql()

Convert an array to an insert SQL query.

public static array_to_insert_sql(array<string|int, mixed> $row, string $table[, string $type = 'insert ignore' ]) : false|string
Parameters
$row : array<string|int, mixed>

Array row with key and value.

$table : string

Name of the table.

$type : string = 'insert ignore'

One of insert, insert ignore, replace into.

Return values
false|string

camel_to_snake()

Convert a string from camelCase to snake_case.

public static camel_to_snake(string $input) : string
Parameters
$input : string

The string to be converted.

Return values
string

delete_dir()

Recursively delete a directory.

public static delete_dir(string $dir_path) : void
Parameters
$dir_path : string

The path to the directory.

Tags
throws
InvalidArgumentException

If $dir_path is not a directory.

Return values
void

ensure_wp_content_path()

Ensure that the given path is a valid path within the WP_CONTENT_DIR.

public static ensure_wp_content_path(string $path) : string
Parameters
$path : string

The path to be validated.

Tags
throws
InvalidArgumentException

If the path is invalid.

Return values
string

index_array()

Index an array using a callback function.

public static index_array(array<string|int, mixed> $array, callable $callback) : array<string|int, mixed>
Parameters
$array : array<string|int, mixed>

The array to be indexed.

$callback : callable

The callback function to be called for each element.

Return values
array<string|int, mixed>

is_valid_wp_plugin_slug()

Check to see if given string is a valid WordPress plugin slug.

public static is_valid_wp_plugin_slug(string $slug) : bool
Parameters
$slug : string

The slug to be validated.

Return values
bool

snake_to_camel()

Convert a string from snake_case to camelCase.

public static snake_to_camel(string $string_to_convert) : string
Parameters
$string_to_convert : string

The string to be converted.

Return values
string