includes/Admin/class-wppo-cli-command.php
WP-CLI integration for Performance Optimisation plugin.
Class WPPO_CLI_Command
Manages Performance Optimisation features via WP-CLI.
class WPPO_CLI_Command extends WP_CLI_Commandpublic cache()
public function cache(array $args, array $assoc_args): voidManage static HTML cache. Parameter Type Default Description $argsarray— Command positional arguments. $assoc_argsarray— Command associative arguments.
Return: void.
public database()
public function database(array $args, array $assoc_args): voidPerform database cleanup and optimization routines. Parameter Type Default Description $argsarray— Command positional arguments. $assoc_argsarray— Command associative arguments.
Return: void.
public image()
public function image(array $args, array $assoc_args): voidManage image conversion. Parameter Type Default Description $argsarray— Command positional arguments. $assoc_argsarray— Command associative arguments.
Return: void.
privatestatic get_default_settings()
private static function get_default_settings(): arrayGet default settings structure for fresh installs.
Return: array<string, — array<string, mixed>> Default settings keyed by tab.
privatestatic log_json()
private static function log_json($data): voidLog data as JSON, warning loudly when encoding fails. Parameter Type Default Description $datamixed— Data to encode and log.
Return: void.
public settings()
public function settings(array $args, array $assoc_args): voidView, update, export, or import plugin settings. Parameter Type Default Description $argsarray— Command positional arguments. $assoc_argsarray— Command associative arguments.
Return: void.
public object_cache()
public function object_cache(array $args, array $assoc_args): voidManage Redis Object Cache. Parameter Type Default Description $argsarray— Command positional arguments. $assoc_argsarray— Command associative arguments.
Return: void.
privatestatic get_redis_config_from_assoc()
private static function get_redis_config_from_assoc(array $assoc_args): arrayBuild a Redis config array from CLI associative arguments. Parameter Type Default Description $assoc_argsarray— The associative arguments from the command.
Return: array<string, — mixed> Redis connection configuration.
public pagespeed()
public function pagespeed(array $args, array $assoc_args): voidManage Google PageSpeed scans. Parameter Type Default Description $argsarray— Command positional arguments. $assoc_argsarray— Command associative arguments.
Return: void.
public system_info()
public function system_info(array $args, array $assoc_args): voidShow system information. Parameter Type Default Description $argsarray— Command positional arguments. $assoc_argsarray— Command associative arguments.
Return: void.
public verify()
public function verify(array $args, array $assoc_args): voidVerify live site state (self-verification gate for the autonomous maintenance loop). Parameter Type Default Description $argsarray— Command positional arguments. $assoc_argsarray— Command associative arguments.
Return: void.
publicstatic get_verify_check_names()
public static function get_verify_check_names(): arrayCanonical verify check names (single source for –check validation).
Return: string[].
publicstatic resolve_verify_domain()
public static function resolve_verify_domain(string $home_url): stringResolve the static-cache domain for a home URL (Cache::__construct convention). Parameter Type Default Description $home_urlstring— Home URL.
Return: string — Sanitized domain, or \’\’ when unresolvable.
publicstatic build_redis_config_from_settings()
public static function build_redis_config_from_settings(array $stored): arrayBuild a Redis config array from stored settings. Parameter Type Default Description $storedarray— Raw wppo_settings array.
Return: array<string, — mixed> Redis connection configuration.
publicstatic validate_settings_schema()
public static function validate_settings_schema(array $stored, ?array=null $allowed, ?array=null $schema): arrayValidate stored settings against the canonical schema (read-only). Parameter Type Default Description $storedarray— Raw wppo_settings array (live get_option). $allowed?array=null— Optional allowlist override (testing). $schema?array=null— Optional schema override (testing).
Return: array{check:string,status:string,detail:string} — Verify row.
publicstatic find_orphan_cron_hooks()
public static function find_orphan_cron_hooks(array $found_hooks): arraySplit found wppo_* cron hooks into orphans vs known-legacy (pure helper). Parameter Type Default Description $found_hooksarray— Hook names discovered in WP-Cron.
Return: array{orphans:string[],legacy:string[]} — Orphan and legacy lists.
publicstatic evaluate_litespeed_state()
public static function evaluate_litespeed_state(string $raw_mode, string $effective, bool $server_ls, bool $lscache, bool $esi_enabled, bool $esi_available): arrayEvaluate LiteSpeed coherence from live inputs (pure helper, no I/O). Parameter Type Default Description $raw_modestring— Raw configured mode string (unvalidated). $effectivestring— Resolved effective mode. $server_lsbool— Whether the server is LiteSpeed. $lscachebool— Whether the LSCache plugin is active. $esi_enabledbool— Whether the ESI bridge setting is on. $esi_availablebool— Whether native ESI is available (Enterprise).
Return: array{check:string,status:string,detail:string} — Verify row.
publicstatic find_unknown_wppo_options()
public static function find_unknown_wppo_options(array $found_names): arrayFind wppo_* options without a known live owner (pure helper). Parameter Type Default Description $found_namesarray— Option names from the options table.
Return: string[] — Unknown option names.
publicstatic build_verify_payload()
public static function build_verify_payload(array $rows, string=\'fail\' $severity): arrayBuild the machine-readable verify payload (pure helper). Parameter Type Default Description $rowsarray— Verify rows. $severitystring=\'fail\'— Exit-code gate (\’fail\’ or \’warn\’).
Return: array{overall:string,checks:array} — Payload for –format=json.
private check_verify_cache_dirs()
private function check_verify_cache_dirs(): arrayCheck 1 — cache directories live (writable + consistent).
Return: array{check:string,status:string,detail:string} — Verify row.
publicstatic classify_unwritable_cache_root()
public static function classify_unwritable_cache_root($euid, $stat, string $root): arrayClassify a cache root that is not writable by the current process. Parameter Type Default Description $euidint|null— Effective UID of the current process (null when posix is unavailable). $statarray|false— stat() result for the directory (false when stat failed). $rootstring— Absolute cache root path, used in the detail message.
Return: array{status:string,detail:string} — \’warn\’ when a foreign owner can write; \’fail\’ otherwise.
private check_verify_dropins()
private function check_verify_dropins(array $stored): arrayCheck 2 — drop-ins present & intended (incl. foreign). Parameter Type Default Description $storedarray— Raw wppo_settings array.
Return: array{check:string,status:string,detail:string} — Verify row.
private check_verify_redis()
private function check_verify_redis(array $stored): arrayCheck 3 — Redis reachable when enabled (live probe). Parameter Type Default Description $storedarray— Raw wppo_settings array.
Return: array{check:string,status:string,detail:string} — Verify row.
private check_verify_litespeed()
private function check_verify_litespeed(array $stored): arrayCheck 4 — LiteSpeed mode coherent. Parameter Type Default Description $storedarray— Raw wppo_settings array.
Return: array{check:string,status:string,detail:string} — Verify row.
private check_verify_cron()
private function check_verify_cron(array $stored): arrayCheck 6 — orphaned cron / Action Scheduler events. Parameter Type Default Description $storedarray— Raw wppo_settings array.
Return: array{check:string,status:string,detail:string} — Verify row.
private check_verify_uninstall_spot()
private function check_verify_uninstall_spot(): arrayCheck 7 — uninstall-completeness spot check (read-only).
Return: array{check:string,status:string,detail:string} — Verify row.
private read_small_file()
private function read_small_file(string $path): ?stringRead a small file via WP_Filesystem with a native fallback (size-guarded). Parameter Type Default Description $pathstring— Absolute path.
Return: string|null — Contents, or null when missing/unreadable/too large.