summaryrefslogtreecommitdiff
blob: af4aec419456d017804aae51f3aaba48879ab8e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
 * WP_Super_Cache sync module.
 *
 * @package automattic/jetpack-sync
 */

namespace Automattic\Jetpack\Sync\Modules;

/**
 * Class to handle sync for WP_Super_Cache.
 */
class WP_Super_Cache extends Module {
	/**
	 * Constructor.
	 *
	 * @todo Should we refactor this to use $this->set_defaults() instead?
	 */
	public function __construct() {
		add_filter( 'jetpack_sync_constants_whitelist', array( $this, 'add_wp_super_cache_constants_whitelist' ), 10 );
		add_filter( 'jetpack_sync_callable_whitelist', array( $this, 'add_wp_super_cache_callable_whitelist' ), 10 );
	}

	/**
	 * Whitelist for constants we are interested to sync.
	 *
	 * @access public
	 * @static
	 *
	 * @var array
	 */
	public static $wp_super_cache_constants = array(
		'WPLOCKDOWN',
		'WPSC_DISABLE_COMPRESSION',
		'WPSC_DISABLE_LOCKING',
		'WPSC_DISABLE_HTACCESS_UPDATE',
		'ADVANCEDCACHEPROBLEM',
	);

	/**
	 * Container for the whitelist for WP_Super_Cache callables we are interested to sync.
	 *
	 * @access public
	 * @static
	 *
	 * @var array
	 */
	public static $wp_super_cache_callables = array(
		'wp_super_cache_globals' => array( __CLASS__, 'get_wp_super_cache_globals' ),
	);

	/**
	 * Sync module name.
	 *
	 * @access public
	 *
	 * @return string
	 */
	public function name() {
		return 'wp-super-cache';
	}

	/**
	 * Retrieve all WP_Super_Cache callables we are interested to sync.
	 *
	 * @access public
	 *
	 * @global $wp_cache_mod_rewrite;
	 * @global $cache_enabled;
	 * @global $super_cache_enabled;
	 * @global $ossdlcdn;
	 * @global $cache_rebuild_files;
	 * @global $wp_cache_mobile;
	 * @global $wp_super_cache_late_init;
	 * @global $wp_cache_anon_only;
	 * @global $wp_cache_not_logged_in;
	 * @global $wp_cache_clear_on_post_edit;
	 * @global $wp_cache_mobile_enabled;
	 * @global $wp_super_cache_debug;
	 * @global $cache_max_time;
	 * @global $wp_cache_refresh_single_only;
	 * @global $wp_cache_mfunc_enabled;
	 * @global $wp_supercache_304;
	 * @global $wp_cache_no_cache_for_get;
	 * @global $wp_cache_mutex_disabled;
	 * @global $cache_jetpack;
	 * @global $cache_domain_mapping;
	 *
	 * @return array All WP_Super_Cache callables.
	 */
	public static function get_wp_super_cache_globals() {
		global $wp_cache_mod_rewrite;
		global $cache_enabled;
		global $super_cache_enabled;
		global $ossdlcdn;
		global $cache_rebuild_files;
		global $wp_cache_mobile;
		global $wp_super_cache_late_init;
		global $wp_cache_anon_only;
		global $wp_cache_not_logged_in;
		global $wp_cache_clear_on_post_edit;
		global $wp_cache_mobile_enabled;
		global $wp_super_cache_debug;
		global $cache_max_time;
		global $wp_cache_refresh_single_only;
		global $wp_cache_mfunc_enabled;
		global $wp_supercache_304;
		global $wp_cache_no_cache_for_get;
		global $wp_cache_mutex_disabled;
		global $cache_jetpack;
		global $cache_domain_mapping;

		return array(
			'wp_cache_mod_rewrite'         => $wp_cache_mod_rewrite,
			'cache_enabled'                => $cache_enabled,
			'super_cache_enabled'          => $super_cache_enabled,
			'ossdlcdn'                     => $ossdlcdn,
			'cache_rebuild_files'          => $cache_rebuild_files,
			'wp_cache_mobile'              => $wp_cache_mobile,
			'wp_super_cache_late_init'     => $wp_super_cache_late_init,
			'wp_cache_anon_only'           => $wp_cache_anon_only,
			'wp_cache_not_logged_in'       => $wp_cache_not_logged_in,
			'wp_cache_clear_on_post_edit'  => $wp_cache_clear_on_post_edit,
			'wp_cache_mobile_enabled'      => $wp_cache_mobile_enabled,
			'wp_super_cache_debug'         => $wp_super_cache_debug,
			'cache_max_time'               => $cache_max_time,
			'wp_cache_refresh_single_only' => $wp_cache_refresh_single_only,
			'wp_cache_mfunc_enabled'       => $wp_cache_mfunc_enabled,
			'wp_supercache_304'            => $wp_supercache_304,
			'wp_cache_no_cache_for_get'    => $wp_cache_no_cache_for_get,
			'wp_cache_mutex_disabled'      => $wp_cache_mutex_disabled,
			'cache_jetpack'                => $cache_jetpack,
			'cache_domain_mapping'         => $cache_domain_mapping,
		);
	}

	/**
	 * Add WP_Super_Cache constants to the constants whitelist.
	 *
	 * @param array $list Existing constants whitelist.
	 * @return array Updated constants whitelist.
	 */
	public function add_wp_super_cache_constants_whitelist( $list ) {
		return array_merge( $list, self::$wp_super_cache_constants );
	}

	/**
	 * Add WP_Super_Cache callables to the callables whitelist.
	 *
	 * @param array $list Existing callables whitelist.
	 * @return array Updated callables whitelist.
	 */
	public function add_wp_super_cache_callable_whitelist( $list ) {
		return array_merge( $list, self::$wp_super_cache_callables );
	}
}