Util
Overview
The Util module gathers the library’s general-purpose helpers: actions, arrays, autoloading, cache, colors, cryptography, files, logging, strings, testing, URLs, and version orchestration.
Types in this module
Lipe\Lib\Util\ActionsLipe\Lib\Util\ArraysLipe\Lib\Util\AutoloaderLipe\Lib\Util\CacheLipe\Lib\Util\ColorsLipe\Lib\Util\CryptLipe\Lib\Util\FilesLipe\Lib\Util\LoggerLipe\Lib\Util\StringsLipe\Lib\Util\TestingLipe\Lib\Util\UrlLipe\Lib\Util\VersionsLipe\Lib\Util\Logger\Error_LogLipe\Lib\Util\Logger\Handle(interface)Lipe\Lib\Util\Logger\HandlesLipe\Lib\Util\Logger\Level(enum)Lipe\Lib\Util\Logger\Query_MonitorLipe\Lib\Util\Logger\TestingLipe\Lib\Util\Logger\WithContext(interface)
Actions
Helper methods for advanced action/filter registration patterns.
Key public methods
public function add_filter_as_action(string $filter, callable $callback, int $priority = 10): voidpublic function add_action_all(array $actions, callable $callback, int $priority = 10): voidpublic function add_filter_all(array $filters, callable $callback, int $priority = 10): voidpublic function add_single_filter(string $filter, callable $callback, int $priority = 10): voidpublic function add_single_action(string $action, callable $callback, int $priority = 10): voidpublic function remove_action_always(string $action, callable $callback, int $priority = 10): voidpublic function remove_filter_always(string $filter, callable $callback, int $priority = 10): voidpublic function add_filter_during(string $filter, callable $callback, string $start, string $end, int $priority = 10): voidpublic function add_looping_action(string $action, callable $callback, int $priority = 10): voidpublic function add_looping_filter(string $filter, callable $callback, int $priority = 10): void
Arrays
Array transformation helpers.
Key public methods
public function chunk_to_associative(array $input_array): arraypublic function clean(array $input_array, bool $preserve_keys = true): arraypublic function map_recursive(callable $callback, array $input_array): arraypublic function merge_recursive(array $args, array $defaults): arraypublic function map_assoc(callable $callback, array $input_array): arraypublic function recursive_unset(string $key, array $input_array): arraypublic function find(array $items, callable $callback)public function find_index(array $items, callable $callback)public function flatten_assoc(callable $callback, array $input_array): arraypublic function list_pluck(array $input_array, array $keys): array
Autoloader
Simple namespace-to-path autoloader.
Key public methods
public function __construct()public static function add(string $name_space, string $path): voidpublic function register(bool $prepend = true): voidpublic function unregister(): voidpublic function maybe_load_class(string $class_name): void
Cache
Object-cache helper with support for complex keys and group flushing.
Key public methods
public function hook(): voidpublic function set(object|array|int|string $key, mixed $value, string $group = self::DEFAULT_GROUP, int $expire_in_seconds = 0): boolpublic function get(object|array|int|string $key, string $group = self::DEFAULT_GROUP): mixedpublic function delete(object|array|int|string $key, string $group = self::DEFAULT_GROUP): boolpublic function flush_group(string $group = self::DEFAULT_GROUP): voidpublic function flush_runtime_cache(): voidpublic function add_admin_bar_button(\WP_Admin_Bar $admin_bar): void
Other utility classes
Colorsconverts betweenhexandrgbaviahex_to_rgba()andrgba_to_hex().Cryptencrypts and decrypts strings viaencrypt(),decrypt(),is_encrypted(), andfactory().Filesexposescopy_directory()andget_wp_filesystem().Stringsprovidespluralize()andunformat_money_value().Testingwraps test-only behaviors such asexit(),error_log(), andis_wp_debug().Urlprovidesget_current_url()andget_query_arg().Versionscoordinates one-time and versioned updates throughget_version(),once(), andadd_update().
Logging subsystem
Loggeris the main entry point and exposeswarn(),error(),notice(),debug(), andfactory().Logger\Handledefinespublic function log(string $id, Level $level, string $message): void.Logger\WithContextaddspublic function provide_context(array $context): void.Logger\Handlesstores named log handles viaget_handles(),register_handle(), andunregister_handle().Logger\Error_Log,Logger\Query_Monitor, andLogger\Testingare concrete handle implementations.Logger\Levelis the enum of supported log levels.
Example
<?php
use Lipe\Lib\Util\Logger;
Logger::factory('acme/books')->notice('Catalog synchronized', ['count' => 12]);