Skip to content

Core Functions

make_clickable()

/**
 * Turn all URLs into clickable links.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $value
 * @param array  $protocols  http/https, ftp, mail, twitter
 * @param array  $attributes
 * @return string
 */
function make_clickable(string $value, array $protocols = ['http', 'mail'], array $attributes = []): string;

remote_file_exists()

/**
 * Checks if a remote file exists.
 *
 * @file App/Shared/Helpers/core.php
 * @return bool True on success, false otherwise.
 */
function remote_file_exists(string $url): bool;

get_file_size()

/**
 * @file App/Shared/Helpers/core.php
 * @param string $file Filepath
 * @param int $digits Digits to display.
 * @return string|bool Size (KB, MB, GB, TB) on success or false otherwise.
 */
function get_file_size(string $file, int $digits = 2): string|bool;

checked()

/**
 * Outputs the html checked attribute.
 *
 * Compares the first two arguments and if identical marks as checked.
 *
 * @file App/Shared/Helpers/core.php
 * @param mixed $checked One of the values to compare
 * @param mixed $current (true) The other value to compare if not just true.
 * @param bool $echo Whether to echo or just return the string.
 * @return string html attribute or empty string
 */
function checked(mixed $checked, mixed $current = true, bool $echo = true): string;

selected()

/**
 * Outputs the html selected attribute.
 *
 * Compares the first two arguments and if identical marks as selected.
 *
 * @file App/Shared/Helpers/core.php
 * @param mixed $selected One of the values to compare.
 * @param mixed $current (true) The other value to compare if not just true.
 * @param bool $echo Whether to echo or just return the string.
 * @return string html attribute or empty string
 */
function selected(mixed $selected, mixed $current = true, bool $echo = true): string;

disabled()

/**
 * Outputs the html disabled attribute.
 *
 * Compares the first two arguments and if identical marks as disabled.
 *
 * @file App/Shared/Helpers/core.php
 * @param mixed $disabled One of the values to compare.
 * @param mixed $current (true) The other value to compare if not just true.
 * @param bool $echo Whether to echo or just return the string.
 * @return string html attribute or empty string
 */
function disabled(mixed $disabled, mixed $current = true, bool $echo = true): string;

checked_selected_helper()

/**
 * Private helper function for checked, selected, and disabled.
 *
 * Compares the first two arguments and if identical marks as $type.
 *
 * @access private
 *
 * @file App/Shared/Helpers/core.php
 * @param mixed $helper One of the values to compare.
 * @param mixed $current (true) The other value to compare if not just true.
 * @param bool $echo Whether to echo or just return the string.
 * @param string $type The type of checked|selected|disabled we are doing.
 * @return string html attribute or empty string
 */
function checked_selected_helper(mixed $helper, mixed $current, bool $echo, string $type): string;

seconds_to_minutes()

/**
 * @file App/Shared/Helpers/core.php
 * @param float|int $seconds
 * @return string
 */
function seconds_to_minutes(float|int $seconds): string;

is_ssl()

/**
 * Determines if SSL is used.
 *
 * @file App/Shared/Helpers/core.php
 * @return bool True if SSL, false otherwise.
 */
function is_ssl(): bool;

normalize_path()

/**
 * Normalize a filesystem path.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $path Path to normalize.
 * @return array|string|null Normalized path.
 */
function normalize_path(string $path): array|string|null;

beautify_filename()

/**
 * Beautifies a filename for use.
 *
 * Uses `beautified_filename` filter hook.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $filename Filename to beautify.
 * @return string Beautified filename.
 * @throws Exception
 * @throws ReflectionException
 */
function beautify_filename(string $filename): string;

sanitize_filename()

/**
 * Sanitizes a filename.
 *
 * Uses `sanitized_filename` filter hook.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $filename Name of file to sanitize.
 * @param bool $beautify Whether to beautify the sanitized filename.
 * @return string Sanitized filename for use.
 * @throws Exception
 * @throws ReflectionException
 */
function sanitize_filename(string $filename, bool $beautify = true): string;

get_functions()

/**
 * Returns an array of function names in a file.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $filename The path to the file.
 * @param bool $sort If true, sort results by function name.
 */
function get_functions(string $filename, bool $sort = false): array;

is_duplicate_function()

/**
 * Checks a given file for any duplicated named user functions.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $filename
 * @return Error|false
 */
function is_duplicate_function(string $filename): Error|false;

check_includes()

/**
 * Performs a check within a php script and returns any other files
 * that might have been required or included.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $filename PHP script to check.
 */
function check_includes(string $filename): array|string;

check_syntax()

/**
 * Performs a syntax and error check of a given PHP script.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $filename PHP script/file to check.
 * @param bool $checkIncludes If set to true, will check if other files have been included.
 * @return Error
 * @throws NotFoundException If file does not exist or is not readable.
 * @throws Exception If file contains duplicate function names.
 */
function check_syntax(string $filename, bool $checkIncludes = true): Error;

mdir__()

/**
 * Removes directory recursively along with any files.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $dir Directory that should be removed.
 */
function rmdir__(string $dir): void;

generate_timezone_list()

/**
 * Prints a list of timezones which includes
 * current time.
 *
 * @file App/Shared/Helpers/core.php
 * @return array Timezone list.
 * @throws DateInvalidTimeZoneException
 * @throws DateMalformedStringException
 */
function generate_timezone_list(): array;

get_age()

/**
 * Get age by birthdate.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $birthdate User's birthdate.
 * @return string|int
 */
function get_age(string $birthdate = '0000-00-00'): string|int;

generate_unique_key()

/**
 * Generates a unique key.
 *
 * @file App/Shared/Helpers/core.php
 * @param int $length
 * @return string
 */
function generate_unique_key(int $length = 6): string;

generate_site_key()

/**
 * A private function for generating unique site key.
 *
 * @access private
 * @throws ContainerExceptionInterface
 * @throws ReflectionException
 * @throws NotFoundExceptionInterface
 */
function generate_site_key(int $length = 6): string;

convert_date_to_gmt()

/**
 * Converts date to GMT format.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $string The date to be converted.
 * @param string $format The format string for the converted date.
 * @return string
 */
function convert_date_to_gmt(string $string = 'now', string $format = 'Y-m-d H:i:s'): string;

convert_seconds_to_time()

/**
 * Converts seconds to time format.
 *
 * @file App/Shared/Helpers/core.php
 * @param int $seconds
 * @return string
 */
function convert_seconds_to_time(int $seconds): string;

set_email_template()

/**
 * Add the template to the message body.
 *
 * Looks for {content} into the template and replaces it with the message.
 *
 * Uses `email_template` filter hook.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $body The message to templatize.
 * @return string $email The email surrounded by template.
 * @throws Exception
 * @throws ReflectionException
 */
function set_email_template(string $body): string;

replace_template_vars()

/**
 * Replace variables in the template.
 *
 * Uses `email_template_tags` filter hook.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $template Template with variables.
 * @return string Template with variables replaced.
 * @throws ContainerExceptionInterface
 * @throws Exception
 * @throws InvalidArgumentException
 * @throws NotFoundExceptionInterface
 * @throws ReflectionException
 */
function replace_template_vars(string $template): string;

process_email_html()

/**
 * Process the HTML version of the text.
 *
 * Uses `email_template_body` filter hook.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $text
 * @param string $title
 * @return string
 * @throws ContainerExceptionInterface
 * @throws Exception
 * @throws InvalidArgumentException
 * @throws NotFoundExceptionInterface
 * @throws ReflectionException
 */
function process_email_html(string $text, string $title): string;

get_domain_name()

/**
 * Retrieve the domain name.
 *
 * @file App/Shared/Helpers/core.php
 * @return string
 */
function get_domain_name(): string;

cms_enqueue_css()

/**
 * Enqueues stylesheets.
 *
 * Uses `default_css_pipeline`, `plugin_css_pipeline` and `theme_css_pipeline`
 * filter hooks.
 *
 * Example Usage:
 *
 *      cms_enqueue_css('default', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css')
 *      cms_enqueue_css('plugin', ['fontawesome','select2-css'], false, Plugin::basename( dirname(__FILE__) ))
 *      cms_enqueue_css('theme', 'theme-slug/assets/css/style.css')
 *
 * @file App/Shared/Helpers/core.php
 * @param string $config Set whether to use `default` config or `plugin` config.
 * @param string|array $asset Relative path or URL to stylesheet(s) to enqueue.
 * @param bool|string $minify Enable css assets pipeline (concatenation and minification).
 *                            Use a string that evaluates to `true` to provide the salt of the pipeline hash.
 *                            Use 'auto' to automatically calculate the salt from your assets last modification time.
 * @param string|null $pluginSlug Plugin slug to set plugin's asset location
 * @return void
 * @throws Exception
 * @throws ReflectionException
 */
function cms_enqueue_css(
    string $config,
    string|array $asset,
    bool|string $minify = false,
    ?string $pluginSlug = null
): void;

cms_enqueue_js()

/**
 * Enqueues javascript.
 *
 * Uses `default_js_pipeline`, `plugin_js_pipeline` and `theme_js_pipeline`
 * filter hooks.
 *
 * Example Usage:
 *
 *      cms_enqueue_js('default', 'jquery-ui')
 *      cms_enqueue_js('plugin', 'select2-js', false, Plugin::basename( dirname(__FILE__) ))
 *      cms_enqueue_js('theme', 'theme-slug/assets/js/config.js')
 *
 * @file App/Shared/Helpers/core.php
 * @param string $config Set whether to use `default`, `plugin`  or `theme` config.
 * @param string|array $asset Relative path or URL to javascripts(s) to enqueue.
 * @param bool|string $minify Enable js assets pipeline (concatenation and minification).
 *                            Use a string that evaluates to `true` to provide the salt of the pipeline hash.
 *                            Use 'auto' to automatically calculate the salt from your assets last modification time.
 * @param string|null $pluginSlug Plugin slug to set plugin's asset location.
 * @return void
 * @throws Exception
 * @throws ReflectionException
 */
function cms_enqueue_js(
    string $config,
    array|string $asset,
    bool|string $minify = false,
    ?string $pluginSlug = null
): void;

generate_random_username()

/**
 * Generates a random username.
 *
 * @file App/Shared/Helpers/core.php
 * @param int $length
 * @return string
 */
function generate_random_username(int $length = 6): string;

generate_random_password()

/**
 * Generates a random password drawn from the defined set of characters.
 *
 * Uses `random_lib` library to create passwords with far less predictability.
 *
 * @file App/Shared/Helpers/core.php
 * @param int $length Optional. The length of password to generate. Default 12.
 * @param bool $specialChars Optional. Whether to include standard special characters.
 *                                Default true.
 * @param bool $extraSpecialChars Optional. Whether to include other special characters.
 *                                Default false.
 * @return string The system generated password.
 * @throws Exception
 * @throws ReflectionException
 */
function generate_random_password(
    int $length = 12,
    bool $specialChars = true,
    bool $extraSpecialChars = false
): string;

get_current_screen()

/**
 * Get the current screen.
 *
 * @file App/Shared/Helpers/core.php
 * @return string|null Current screen or null if screen is not defined.
 * @throws ReflectionException
 * @throws ContainerExceptionInterface
 * @throws NotFoundExceptionInterface
 */
function get_current_screen(): ?string;

_cms_image_optimizer()

/**
 * Image optimizer.
 *
 * @access private
 * 
 * @file App/Shared/Helpers/core.php
 * @param string $pathToImage Path to original image.
 * @param string $pathToOptimized Path to where optimized image should be saved.
 * @return void Optimized image.
 */
function _cms_image_optimizer(string $pathToImage, string $pathToOptimized): void;

sort_list()

/**
 * Sort array of objects by field.
 *
 * Example Usage:
 *
 *      sort_list($content,'content_id','ASC', false);
 *
 * @file App/Shared/Helpers/core.php
 * @param array $objects        Array of objects to sort.
 * @param array|string $orderby Name of field or array of fields to filter by.
 * @param string $order         (ASC|DESC)
 * @param bool $preserveKeys   Whether to preserve keys.
 * @return array Returns a sorted array.
 */
function sort_list(
    array &$objects,
    array|string $orderby = [],
    string $order = 'ASC',
    bool $preserveKeys = false
): array;

site_path()

/**
 * Site path.
 *
 * @file App/Shared/Helpers/core.php
 * @param string|null $path
 * @return string
 * @throws ContainerExceptionInterface
 * @throws NotFoundExceptionInterface
 * @throws ReflectionException
 */
function site_path(?string $path = null): string;

encrypt()

/**
 * Encrypt function.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $string
 * @return string
 * @throws BadFormatException
 * @throws EnvironmentIsBrokenException
 */
function encrypt(string $string): string;

decrypt()

/**
 * Decrypt function.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $string
 * @return string
 * @throws BadFormatException
 * @throws EnvironmentIsBrokenException
 * @throws WrongKeyOrModifiedCiphertextException
 */
function decrypt(string $string): string;

maybe_serialize()

/**
 * Serializes data if necessary.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $data Data to be serialized.
 * @return string Serialized data or original string.
 * @throws TypeException
 */
function maybe_serialize(mixed $data): string;

maybe_unserialize()

/**
 * Unserializes data if necessary.
 *
 * @file App/Shared/Helpers/core.php
 * @param mixed $data Data that should be unserialzed.
 * @return string Unserialized data or original input.
 */
function maybe_unserialize(mixed $data): string;

is_serialized()

/**
 * Checks if data is serialized.
 *
 * @file App/Shared/Helpers/core.php
 * @param object|array|string $data
 * @param bool $strict
 * @return bool
 */
function is_serialized(object|array|string $data, bool $strict = true): bool;

set_registry_entry()

/**
 * Sets a registry parameter.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $key
 * @param mixed $value
 * @return void
 * @throws ReflectionException
 */
function set_registry_entry(string $key, mixed $value): void;

get_registry_entry()

/**
 * Finds an entry of the registry by its identifier and returns it.
 *
 * @file App/Shared/Helpers/core.php
 * @param string $key
 * @return mixed
 * @throws ContainerExceptionInterface
 * @throws NotFoundExceptionInterface
 * @throws ReflectionException
 */
function get_registry_entry(string $key): mixed;

urrent_screen()

/**
 * @param string $key
 * @param string $value
 * @return string
 * @throws ContainerExceptionInterface
 * @throws NotFoundExceptionInterface
 * @throws ReflectionException
 */
function current_screen(string $key, string $value): string;