Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
HealthChecks
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 add_hooks
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 add_health_checks
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace NewfoldLabs\WP\Module\Performance;
4
5use NewfoldLabs\WP\Module\Performance\HealthChecks\AutosaveIntervalHealthCheck;
6use NewfoldLabs\WP\Module\Performance\HealthChecks\BrowserCachingHealthCheck;
7use NewfoldLabs\WP\Module\Performance\HealthChecks\CloudflareHealthCheck;
8use NewfoldLabs\WP\Module\Performance\HealthChecks\ConcatenateCssHealthCheck;
9use NewfoldLabs\WP\Module\Performance\HealthChecks\ConcatenateJsHealthCheck;
10use NewfoldLabs\WP\Module\Performance\HealthChecks\CronLockTimeoutHealthCheck;
11use NewfoldLabs\WP\Module\Performance\HealthChecks\DeferNonEssentialJsHealthCheck;
12use NewfoldLabs\WP\Module\Performance\HealthChecks\EmptyTrashDaysHealthCheck;
13use NewfoldLabs\WP\Module\Performance\HealthChecks\LazyLoadingHealthCheck;
14use NewfoldLabs\WP\Module\Performance\HealthChecks\LinkPrefetchHealthCheck;
15use NewfoldLabs\WP\Module\Performance\HealthChecks\PageCachingHealthCheck;
16use NewfoldLabs\WP\Module\Performance\HealthChecks\PermalinksHealthCheck;
17use NewfoldLabs\WP\Module\Performance\HealthChecks\PersistentObjectCacheHealthCheck;
18use NewfoldLabs\WP\Module\Performance\HealthChecks\PostRevisionsHealthCheck;
19use NewfoldLabs\WP\Module\Performance\HealthChecks\PrioritizeCssHealthCheck;
20
21/**
22 * Add performance health checks.
23 */
24class HealthChecks {
25    /**
26     * Container.
27     *
28     * @var Container
29     */
30    private $container;
31
32    /**
33     * Constructor.
34     *
35     * @param Container $container Container.
36     */
37    public function __construct( $container ) {
38        $this->container = $container;
39        if ( function_exists( 'add_filter' ) ) {
40            $this->add_hooks();
41        }
42    }
43
44    /**
45     * Add hooks.
46     */
47    public function add_hooks() {
48        add_filter( 'site_status_tests', array( $this, 'add_health_checks' ) );
49    }
50
51    /**
52     * Add health checks.
53     *
54     * @param array $tests Site status tests.
55     *
56     * @return array Site status tests.
57     */
58    public function add_health_checks( $tests ) {
59        $health_checks = array(
60            new AutosaveIntervalHealthCheck(),
61            new PostRevisionsHealthCheck(),
62            new AutosaveIntervalHealthCheck(),
63            new BrowserCachingHealthCheck(),
64            new CloudflareHealthCheck(),
65            new ConcatenateCssHealthCheck(),
66            new ConcatenateJsHealthCheck(),
67            new CronLockTimeoutHealthCheck(),
68            new DeferNonEssentialJsHealthCheck(),
69            new EmptyTrashDaysHealthCheck(),
70            new LazyLoadingHealthCheck(),
71            new LinkPrefetchHealthCheck(),
72            new PageCachingHealthCheck(),
73            new PermalinksHealthCheck(),
74            new PostRevisionsHealthCheck(),
75            new PrioritizeCssHealthCheck(),
76        );
77
78        // Override the core persistent object cache health check, but only for Bluehost.
79        if ( 'bluehost' === $this->container->plugin()->brand ) {
80            $health_checks[] = new PersistentObjectCacheHealthCheck();
81        }
82
83        foreach ( $health_checks as $health_check ) {
84            $tests = $health_check->register_health_check( $tests );
85        }
86
87        return $tests;
88    }
89}