Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Cache_Compatibility
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
4.05
0.00% covered (danger)
0.00%
0 / 1
 has_cache
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
4.05
1<?php
2/**
3 * Compatibility class for caching plugins.
4 */
5
6namespace Automattic\Jetpack_Boost\Lib;
7
8/**
9 * Compatibility class for caching plugins.
10 */
11class Cache_Compatibility {
12    /**
13     * Checks if the site has a caching plugin.
14     *
15     * Supports:
16     * - Endurance Page Cache
17     *
18     * @since 4.0.0
19     *
20     * @return bool True if the site has a caching plugin, false otherwise.
21     */
22    public static function has_cache() {
23        /**
24         * Filters whether the site has a caching plugin.
25         * Useful for testing.
26         *
27         * @since 4.0.0
28         *
29         * @param bool $has_cache True if the site has a caching plugin, false otherwise.
30         */
31        $has_cache = apply_filters( 'jetpack_boost_compatibility_has_cache', false );
32        if ( $has_cache ) {
33            return true;
34        }
35
36        /*
37         * Disable Page Cache on sites that run Newfold's caching service.
38         * Their cache is considered enabled when the endurance_cache_level option is set to 2 or 3.
39         *
40         * @link https://github.com/bluehost/endurance-page-cache/blob/59fe9993d2cb8a03d1df6da8325f73ad0851ba0a/endurance-page-cache.php#L343
41         */
42        if (
43            class_exists( '\\Endurance_Page_Cache' )
44            && 2 <= (int) get_option( 'endurance_cache_level' )
45        ) {
46            return true;
47        }
48
49        return false;
50    }
51}