kollapsminoriteten/wp-content/plugins/health-check/HealthCheck/WP_CLI/class-status.php

75 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2019-11-15 23:26:29 +01:00
<?php
2022-12-15 17:42:06 +01:00
namespace HealthCheck\WP_CLI;
2019-11-15 23:26:29 +01:00
2022-12-15 17:42:06 +01:00
class Status {
private $format;
public function __construct( $format ) {
$this->format = $format;
}
2019-11-15 23:26:29 +01:00
2022-12-15 17:42:06 +01:00
public function run() {
2023-09-26 10:24:36 +02:00
$health_check_site_status = \WP_Site_Health::get_instance();
2019-11-15 23:26:29 +01:00
2023-09-26 10:24:36 +02:00
$tests = $health_check_site_status::get_tests();
2019-11-15 23:26:29 +01:00
$test_result = array();
2023-09-26 10:24:36 +02:00
foreach ( $tests['direct'] as $test ) {
if ( is_string( $test['test'] ) ) {
$test_function = sprintf(
'get_test_%s',
$test['test']
);
2019-11-15 23:26:29 +01:00
2023-09-26 10:24:36 +02:00
if ( method_exists( $health_check_site_status, $test_function ) && is_callable( array( $health_check_site_status, $test_function ) ) ) {
$test_output = apply_filters( 'site_status_test_result', call_user_func( array( $health_check_site_status, $test_function ) ) );
$test_result[] = array(
'test' => $test['label'],
'type' => wp_kses( $test_output['badge']['label'], array() ),
'result' => wp_kses( $test_output['status'], array() ),
);
continue;
}
}
if ( is_callable( $test['test'] ) ) {
$test_output = apply_filters( 'site_status_test_result', call_user_func( $test['test'] ) );
$test_result[] = array(
'test' => $test['label'],
'type' => wp_kses( $test_output['badge']['label'], array() ),
'result' => wp_kses( $test_output['status'], array() ),
);
}
2019-11-15 23:26:29 +01:00
}
2023-09-26 10:24:36 +02:00
foreach ( $tests['async'] as $test ) {
if ( isset( $test['async_direct_test'] ) && is_callable( $test['async_direct_test'] ) ) {
$test_output = apply_filters( 'site_status_test_result', call_user_func( $test['async_direct_test'] ) );
$test_result[] = array(
'test' => $test['label'],
'type' => wp_kses( $test_output['badge']['label'], array() ),
'result' => wp_kses( $test_output['status'], array() ),
);
}
2019-11-15 23:26:29 +01:00
}
2022-12-15 17:42:06 +01:00
if ( 'json' === $this->format ) {
2023-09-26 10:24:36 +02:00
\WP_CLI\Utils\format_items( 'json', $test_result, array( 'test', 'type', 'result' ) );
2022-12-15 17:42:06 +01:00
} elseif ( 'csv' === $this->format ) {
2023-09-26 10:24:36 +02:00
\WP_CLI\Utils\format_items( 'csv', $test_result, array( 'test', 'type', 'result' ) );
2022-12-15 17:42:06 +01:00
} elseif ( 'yaml' === $this->format ) {
2023-09-26 10:24:36 +02:00
\WP_CLI\Utils\format_items( 'yaml', $test_result, array( 'test', 'type', 'result' ) );
2019-11-15 23:26:29 +01:00
} else {
2023-09-26 10:24:36 +02:00
\WP_CLI\Utils\format_items( 'table', $test_result, array( 'test', 'type', 'result' ) );
2019-11-15 23:26:29 +01:00
}
}
2022-12-15 17:42:06 +01:00
}