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\Testing
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 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
Colors
Convert colors between hexadecimal and rgb(a) notation.
Key public methods
public function hex_to_rgba(string $color, float $transparency = 1.0): stringpublic function rgba_to_hex(string $rgba): string
Example
<?php
use Lipe\Lib\Util\Colors;
$rgba = Colors::in()->hex_to_rgba('#ff0000', 0.5);
// rgba(255,0,0,0.5)
Crypt
Encrypts and decrypts strings using a custom key, compatible with JS encryption/decryption via crypto-js.
Key public methods
public function __construct(string $key)public function decrypt(string $message): ?stringpublic function encrypt(string $plaintext): ?stringpublic static function is_encrypted(string $data): boolpublic static function factory(string $key): static
Example
<?php
use Lipe\Lib\Util\Crypt;
$crypt = Crypt::factory('my-secret-key');
$encrypted = $crypt->encrypt('sensitive data');
$decrypted = $crypt->decrypt($encrypted);
Files
Filesystem helpers backed by the WordPress filesystem API.
Key public methods
public function copy_directory(string $source, string $destination): boolpublic function get_wp_filesystem(): \WP_Filesystem_Base
Logger
Main entry point for logging messages to all registered log handles.
Key public methods
public function warn(string $message, array $context = []): voidpublic function error(string $message, array $context = []): voidpublic function notice(string $message, array $context = []): voidpublic function debug(string $message, array $context = []): voidpublic static function factory(string $id): static
Example
<?php
use Lipe\Lib\Util\Logger;
Logger::factory('acme/books')->notice('Catalog synchronized', ['count' => 12]);
Strings
String utilities.
Key public methods
public function pluralize(string $word): stringpublic function unformat_money_value(string|int|float $value): float
Testing
Utility class for testing purposes, including a test-safe exit() and error capture.
Key public methods
public function exit(): voidpublic function error_log(string $message): voidpublic function is_wp_debug(): bool
Url
Url helpers.
Key public methods
public function get_current_url(bool $with_query = true): stringpublic function get_query_arg(string $url, string $key): array|string|null
Versions
Run callable based on a version or simply run an item only once.
Key public methods
public function get_version(): stringpublic function once(string $key, callable $callback, mixed $args = null): voidpublic function add_update(float|string $version, callable $callback, mixed $args = null): void
Example
<?php
use Lipe\Lib\Util\Versions;
Versions::in()->add_update('2.0', function( $args ) {
// Run only when the stored version is below 2.0.
}, ['migrate' => true] );
Versions::in()->once('acme/seed-data', function() {
// Run exactly once, ever.
} );
Error_Log
Logs messages to the PHP error log. Implements Logger\Handle.
Key public methods
public function provide_context(array $context): voidpublic function log(string $id, Level $level, string $message): void
Handle
Contract for a Logger handle.
Methods
public function log(string $id, Level $level, string $message): voidpublic function provide_context(array $context): void
Handles
Registered handles for the Logger. Registers query-monitor and error-log handles by default, plus testing when WP_TESTS_DIR is defined.
Key public methods
public function __construct()public function get_handles(): arraypublic function register_handle(string $name, Handle $handle): voidpublic function unregister_handle(string $name): void
Level
Enum of supported log severity levels: Debug, Notice, Warning, Error.
Query_Monitor
Logs messages to the Query Monitor plugin. Implements Logger\Handle.
Key public methods
public function provide_context(array $context): voidpublic function log(string $id, Level $level, string $message): void
Testing (Logger\Testing)
Stores log messages during unit tests. Implements Logger\Handle.
Key public methods
public function get_messages(bool $with_context = false): arraypublic function provide_context(array $context): voidpublic function log(string $id, Level $level, string $message): void