admin-caching.php
3.98 KB
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
157
158
159
160
161
162
163
164
165
166
<?php
/**
* @package Password Protected
* @subpackage Admin Caching
*
* @since 2.1
*/
class Password_Protected_Admin_Caching {
/**
* Plugin
*
* @since 2.1
*
* @var Password_Protected|null
*/
private $plugin = null;
/**
* Constructor
*
* @since 2.1
*
* @internal Private. This class should only be instantiated once by the plugin.
*/
public function __construct( $plugin ) {
$this->plugin = $plugin;
add_action( 'admin_init', array( $this, 'cache_settings_info' ) );
}
/**
* Cache Settings Info
*
* Displays information on the settings page for helping
* to configure Password Protected to work with caching setups.
*
* @since 2.1
*/
public function cache_settings_info() {
// Caching Section
add_settings_section(
'password_protected_compat_caching',
__( 'Having issue with Caching?', 'password-protected' ),
array( $this, 'section_caching' ),
'password-protected-compat'
);
// Cookies
add_settings_field(
'password_protected_compat_caching_cookie',
__( 'Cookie Name', 'password-protected' ),
array( $this, 'field_cookies' ),
'password-protected-compat',
'password_protected_compat_caching'
);
// WP Engine Hosting
if ( $this->test_wp_engine() ) {
add_settings_field(
'password_protected_compat_caching_wp_engine',
__( 'WP Engine Hosting', 'password-protected' ),
array( $this, 'field_wp_engine' ),
'password-protected-compat',
'password_protected_compat_caching'
);
}
// W3 Total Cache
if ( $this->test_w3_total_cache() ) {
add_settings_field(
'password_protected_compat_caching_w3_total_cache',
__( 'W3 Total Cache', 'password-protected' ),
array( $this, 'field_w3_total_cache' ),
'password-protected-compat',
'password_protected_compat_caching'
);
}
}
/**
* Caching Section
*
* @since 2.1
*/
public function section_caching() {
echo '<p>' . __( 'Password Protected does not always work well with sites that use caching.', 'password-protected' ) . '<br />
' . __( 'If your site uses a caching plugin or your web hosting uses server-side caching, you may need to configure your caching setup to disable caching for the Password Protected cookie:', 'password-protected' ) . '</p>';
}
/**
* Password Protection Status Field
*
* @since 2.1
*/
public function field_cookies() {
echo '<p><code>' . esc_html( $this->plugin->cookie_name() ) . '</code></p>';
echo '<p class="description">' . __( 'Can be changed using the `password_protected_cookie_name` filter.', 'password-protected' ) . '</p>';
}
/**
* WP Engine Hosting
*
* @since 2.1
*/
public function field_wp_engine() {
echo '<p>' . __( 'We have detected your site may be running on WP Engine hosting.', 'password-protected' ) . '<br />
' . __( 'In order for Password Protected to work with WP Engine\'s caching configuration you must ask them to disable caching for the Password Protected cookie.', 'password-protected' ) . '</p>';
}
/**
* W3 Total Cache Plugin
*
* @since 2.1
*/
public function field_w3_total_cache() {
echo '<p>' . __( 'It looks like you may be using the W3 Total Cache plugin?', 'password-protected' ) . '<br />
' . __( 'In order for Password Protected to work with W3 Total Cache you must disable caching when the Password Protected cookie is set.', 'password-protected' ) . '
' . sprintf( __( 'You can adjust the cookie settings for W3 Total Cache under <a href="%s">Performance > Page Cache > Advanced > Rejected Cookies</a>.', 'password-protected' ), admin_url( '/admin.php?page=w3tc_pgcache#advanced' ) ) . '</p>';
}
/**
* Test: WP Engine
*
* @since 2.1
*
* @return boolean
*/
private function test_wp_engine() {
return ( function_exists( 'is_wpe' ) && is_wpe() ) || ( function_exists( 'is_wpe_snapshot' ) && is_wpe_snapshot() );
}
/**
* Test: W3 Total Cache
*
* @since 2.1
*
* @return boolean
*/
private function test_w3_total_cache() {
return defined( 'W3TC' ) && W3TC;
}
}