$args * @param array $assoc */ public static function doctor(array $args, array $assoc): void { $results = Checks::run(); $rows = []; $bad = false; foreach ($results as $r) { $bad = $bad || $r['state'] === 'bad'; $rows[] = [ 'check' => $r['label'], 'result' => strtoupper($r['state']), 'detail' => trim($r['detail'] . ($r['fix'] !== null ? ' Fix: ' . $r['fix'][0] . '.' : '')), ]; } \WP_CLI\Utils\format_items('table', $rows, ['check', 'result', 'detail']); if ($bad) { \WP_CLI::error('Something needs fixing (see above).'); } \WP_CLI::success('Everything checked works.'); } /** * Prints the diagnostics report, or writes it to a file. Secrets, addresses and content * are left out. * * ## OPTIONS * * [--file=] * : Write the report here instead of printing it. * * ## EXAMPLES * * wp aipcf diagnostics export --file=aipcf-diagnostics.txt * * @param list $args * @param array $assoc */ public function export(array $args, array $assoc): void { $text = Report::text(); if (!empty($assoc['file'])) { if (file_put_contents((string) $assoc['file'], $text) === false) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents -- WP-CLI writes where the admin asked \WP_CLI::error('Could not write ' . $assoc['file']); } \WP_CLI::success('Written to ' . $assoc['file']); return; } \WP_CLI::log($text); } }