Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
4.44% |
2 / 45 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Site_Health | |
4.44% |
2 / 45 |
|
33.33% |
1 / 3 |
37.41 | |
0.00% |
0 / 1 |
| init | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| add_check | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| do_checks | |
0.00% |
0 / 38 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\Jetpack_Boost\Lib; |
| 4 | |
| 5 | /** |
| 6 | * Site_Health. |
| 7 | * |
| 8 | * Displays performance issues in WordPress site health page. |
| 9 | */ |
| 10 | class Site_Health { |
| 11 | |
| 12 | /** |
| 13 | * Initialize hooks |
| 14 | * |
| 15 | * @access public |
| 16 | * @return void |
| 17 | */ |
| 18 | public static function init() { |
| 19 | if ( ! has_filter( 'site_status_tests', array( __CLASS__, 'add_check' ) ) ) { |
| 20 | add_filter( 'site_status_tests', array( __CLASS__, 'add_check' ), 99 ); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Add site-health page tests. |
| 26 | * |
| 27 | * @param array $checks Core checks. |
| 28 | * |
| 29 | * @access public |
| 30 | * @return array |
| 31 | */ |
| 32 | public static function add_check( $checks ) { |
| 33 | $checks['direct']['jetpack_boost_checks'] = array( |
| 34 | 'label' => __( 'Jetpack Boost checks', 'jetpack-boost' ), |
| 35 | 'test' => array( __CLASS__, 'do_checks' ), |
| 36 | ); |
| 37 | |
| 38 | return $checks; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Do site-health page checks |
| 43 | * |
| 44 | * @access public |
| 45 | * @return array |
| 46 | */ |
| 47 | public static function do_checks() { |
| 48 | $health = new Boost_Health(); |
| 49 | $total_issues = $health->get_total_issues(); |
| 50 | $issues = $health->get_all_issues(); |
| 51 | |
| 52 | /** |
| 53 | * Default, no issues found |
| 54 | */ |
| 55 | $result = array( |
| 56 | 'label' => __( 'No issues found', 'jetpack-boost' ), |
| 57 | 'status' => 'good', |
| 58 | 'badge' => array( |
| 59 | 'label' => __( 'Performance', 'jetpack-boost' ), |
| 60 | 'color' => 'gray', |
| 61 | ), |
| 62 | 'description' => sprintf( |
| 63 | '<p>%s</p>', |
| 64 | __( 'Jetpack Boost did not find any known performance issues with your site.', 'jetpack-boost' ) |
| 65 | ), |
| 66 | 'actions' => '', |
| 67 | 'test' => 'jetpack_boost_checks', |
| 68 | ); |
| 69 | |
| 70 | /** |
| 71 | * If issues found. |
| 72 | */ |
| 73 | if ( $total_issues ) { |
| 74 | $result['status'] = 'critical'; |
| 75 | /* translators: $d is the number of performance issues found. */ |
| 76 | $result['label'] = sprintf( _n( 'Your site is affected by %d performance issue', 'Your site is affected by %d performance issues', $total_issues, 'jetpack-boost' ), $total_issues ); |
| 77 | $result['description'] = __( 'Jetpack Boost detected the following performance issues with your site:', 'jetpack-boost' ); |
| 78 | |
| 79 | foreach ( $issues as $issue ) { |
| 80 | $result['description'] .= '<p>'; |
| 81 | $result['description'] .= "<span class='dashicons dashicons-warning' style='color: crimson;'></span>  "; |
| 82 | $result['description'] .= wp_kses( $issue, array( 'a' => array( 'href' => array() ) ) ); // Only allow a href HTML tags. |
| 83 | $result['description'] .= '</p>'; |
| 84 | } |
| 85 | $result['description'] .= '<p>'; |
| 86 | $result['description'] .= sprintf( |
| 87 | wp_kses( |
| 88 | /* translators: Link to Jetpack Boost. */ |
| 89 | __( 'Visit <a href="%s">Boost settings page</a> for more information.', 'jetpack-boost' ), |
| 90 | array( |
| 91 | 'a' => array( 'href' => array() ), |
| 92 | ) |
| 93 | ), |
| 94 | esc_url( admin_url( 'admin.php?page=jetpack-boost' ) ) |
| 95 | ); |
| 96 | $result['description'] .= '</p>'; |
| 97 | } |
| 98 | |
| 99 | return $result; |
| 100 | } |
| 101 | } |