Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 49
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
WP_Super_Cache
0.00% covered (danger)
0.00%
0 / 47
0.00% covered (danger)
0.00%
0 / 5
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 name
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_wp_super_cache_globals
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 1
2
 add_wp_super_cache_constants_whitelist
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 add_wp_super_cache_callable_whitelist
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * WP_Super_Cache sync module.
4 *
5 * @package automattic/jetpack-sync
6 */
7
8namespace Automattic\Jetpack\Sync\Modules;
9
10if ( ! defined( 'ABSPATH' ) ) {
11    exit( 0 );
12}
13
14/**
15 * Class to handle sync for WP_Super_Cache.
16 */
17class WP_Super_Cache extends Module {
18    /**
19     * Constructor.
20     *
21     * @todo Should we refactor this to use $this->set_defaults() instead?
22     */
23    public function __construct() {
24        add_filter( 'jetpack_sync_constants_whitelist', array( $this, 'add_wp_super_cache_constants_whitelist' ), 10 );
25        add_filter( 'jetpack_sync_callable_whitelist', array( $this, 'add_wp_super_cache_callable_whitelist' ), 10 );
26    }
27
28    /**
29     * Whitelist for constants we are interested to sync.
30     *
31     * @access public
32     * @static
33     *
34     * @var array
35     */
36    public static $wp_super_cache_constants = array(
37        'WPLOCKDOWN',
38        'WPSC_DISABLE_COMPRESSION',
39        'WPSC_DISABLE_LOCKING',
40        'WPSC_DISABLE_HTACCESS_UPDATE',
41        'ADVANCEDCACHEPROBLEM',
42    );
43
44    /**
45     * Container for the whitelist for WP_Super_Cache callables we are interested to sync.
46     *
47     * @access public
48     * @static
49     *
50     * @var array
51     */
52    public static $wp_super_cache_callables = array(
53        'wp_super_cache_globals' => array( __CLASS__, 'get_wp_super_cache_globals' ),
54    );
55
56    /**
57     * Sync module name.
58     *
59     * @access public
60     *
61     * @return string
62     */
63    public function name() {
64        return 'wp-super-cache';
65    }
66
67    /**
68     * Retrieve all WP_Super_Cache callables we are interested to sync.
69     *
70     * @access public
71     *
72     * @global $wp_cache_mod_rewrite;
73     * @global $cache_enabled;
74     * @global $super_cache_enabled;
75     * @global $ossdlcdn;
76     * @global $cache_rebuild_files;
77     * @global $wp_cache_mobile;
78     * @global $wp_super_cache_late_init;
79     * @global $wp_cache_anon_only;
80     * @global $wp_cache_not_logged_in;
81     * @global $wp_cache_clear_on_post_edit;
82     * @global $wp_cache_mobile_enabled;
83     * @global $wp_super_cache_debug;
84     * @global $cache_max_time;
85     * @global $wp_cache_refresh_single_only;
86     * @global $wp_cache_mfunc_enabled;
87     * @global $wp_supercache_304;
88     * @global $wp_cache_no_cache_for_get;
89     * @global $wp_cache_mutex_disabled;
90     * @global $cache_jetpack;
91     * @global $cache_domain_mapping;
92     *
93     * @return array All WP_Super_Cache callables.
94     */
95    public static function get_wp_super_cache_globals() {
96        global $wp_cache_mod_rewrite;
97        global $cache_enabled;
98        global $super_cache_enabled;
99        global $ossdlcdn;
100        global $cache_rebuild_files;
101        global $wp_cache_mobile;
102        global $wp_super_cache_late_init;
103        global $wp_cache_anon_only;
104        global $wp_cache_not_logged_in;
105        global $wp_cache_clear_on_post_edit;
106        global $wp_cache_mobile_enabled;
107        global $wp_super_cache_debug;
108        global $cache_max_time;
109        global $wp_cache_refresh_single_only;
110        global $wp_cache_mfunc_enabled;
111        global $wp_supercache_304;
112        global $wp_cache_no_cache_for_get;
113        global $wp_cache_mutex_disabled;
114        global $cache_jetpack;
115        global $cache_domain_mapping;
116
117        return array(
118            'wp_cache_mod_rewrite'         => $wp_cache_mod_rewrite,
119            'cache_enabled'                => $cache_enabled,
120            'super_cache_enabled'          => $super_cache_enabled,
121            'ossdlcdn'                     => $ossdlcdn,
122            'cache_rebuild_files'          => $cache_rebuild_files,
123            'wp_cache_mobile'              => $wp_cache_mobile,
124            'wp_super_cache_late_init'     => $wp_super_cache_late_init,
125            'wp_cache_anon_only'           => $wp_cache_anon_only,
126            'wp_cache_not_logged_in'       => $wp_cache_not_logged_in,
127            'wp_cache_clear_on_post_edit'  => $wp_cache_clear_on_post_edit,
128            'wp_cache_mobile_enabled'      => $wp_cache_mobile_enabled,
129            'wp_super_cache_debug'         => $wp_super_cache_debug,
130            'cache_max_time'               => $cache_max_time,
131            'wp_cache_refresh_single_only' => $wp_cache_refresh_single_only,
132            'wp_cache_mfunc_enabled'       => $wp_cache_mfunc_enabled,
133            'wp_supercache_304'            => $wp_supercache_304,
134            'wp_cache_no_cache_for_get'    => $wp_cache_no_cache_for_get,
135            'wp_cache_mutex_disabled'      => $wp_cache_mutex_disabled,
136            'cache_jetpack'                => $cache_jetpack,
137            'cache_domain_mapping'         => $cache_domain_mapping,
138        );
139    }
140
141    /**
142     * Add WP_Super_Cache constants to the constants whitelist.
143     *
144     * @param array $list Existing constants whitelist.
145     * @return array Updated constants whitelist.
146     */
147    public function add_wp_super_cache_constants_whitelist( $list ) {
148        return array_merge( $list, self::$wp_super_cache_constants );
149    }
150
151    /**
152     * Add WP_Super_Cache callables to the callables whitelist.
153     *
154     * @param array $list Existing callables whitelist.
155     * @return array Updated callables whitelist.
156     */
157    public function add_wp_super_cache_callable_whitelist( $list ) {
158        return array_merge( $list, self::$wp_super_cache_callables );
159    }
160}