| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @package Password Protected |
| 5 |
* @subpackage Admin Caching |
| 6 |
* |
| 7 |
* @since 2.1 |
| 8 |
*/ |
| 9 |
|
| 10 |
class Password_Protected_Admin_Caching { |
| 11 |
|
| 12 |
/** |
| 13 |
* Plugin |
| 14 |
* |
| 15 |
* @since 2.1 |
| 16 |
* |
| 17 |
* @var Password_Protected|null |
| 18 |
*/ |
| 19 |
private $plugin = null; |
| 20 |
|
| 21 |
/** |
| 22 |
* Constructor |
| 23 |
* |
| 24 |
* @since 2.1 |
| 25 |
* |
| 26 |
* @internal Private. This class should only be instantiated once by the plugin. |
| 27 |
*/ |
| 28 |
public function __construct( $plugin ) { |
| 29 |
|
| 30 |
$this->plugin = $plugin; |
| 31 |
|
| 32 |
add_action( 'admin_init', array( $this, 'cache_settings_info' ) ); |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Cache Settings Info |
| 38 |
* |
| 39 |
* Displays information on the settings page for helping |
| 40 |
* to configure Password Protected to work with caching setups. |
| 41 |
* |
| 42 |
* @since 2.1 |
| 43 |
*/ |
| 44 |
public function cache_settings_info() { |
| 45 |
|
| 46 |
// Caching Section |
| 47 |
add_settings_section( |
| 48 |
'password_protected_compat_caching', |
| 49 |
__( 'Caching', 'password-protected' ), |
| 50 |
array( $this, 'section_caching' ), |
| 51 |
'password-protected-compat' |
| 52 |
); |
| 53 |
|
| 54 |
// Cookies |
| 55 |
add_settings_field( |
| 56 |
'password_protected_compat_caching_cookie', |
| 57 |
__( 'Cookies', 'password-protected' ), |
| 58 |
array( $this, 'field_cookies' ), |
| 59 |
'password-protected-compat', |
| 60 |
'password_protected_compat_caching' |
| 61 |
); |
| 62 |
|
| 63 |
// WP Engine Hosting |
| 64 |
if ( $this->test_wp_engine() ) { |
| 65 |
|
| 66 |
add_settings_field( |
| 67 |
'password_protected_compat_caching_wp_engine', |
| 68 |
__( 'WP Engine Hosting', 'password-protected' ), |
| 69 |
array( $this, 'field_wp_engine' ), |
| 70 |
'password-protected-compat', |
| 71 |
'password_protected_compat_caching' |
| 72 |
); |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
// W3 Total Cache |
| 77 |
if ( $this->test_w3_total_cache() ) { |
| 78 |
|
| 79 |
add_settings_field( |
| 80 |
'password_protected_compat_caching_w3_total_cache', |
| 81 |
__( 'W3 Total Cache', 'password-protected' ), |
| 82 |
array( $this, 'field_w3_total_cache' ), |
| 83 |
'password-protected-compat', |
| 84 |
'password_protected_compat_caching' |
| 85 |
); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Caching Section |
| 93 |
* |
| 94 |
* @since 2.1 |
| 95 |
*/ |
| 96 |
public function section_caching() { |
| 97 |
|
| 98 |
echo '<p>' . __( 'Password Protected does not always work well with sites that use caching.', 'password-protected' ) . '<br /> |
| 99 |
' . __( 'If your site uses a caching plugin or your web hosting uses server-side caching, you may need to configure your setup to disable caching for the Password Protected cookie:', 'password-protected' ) . '</p>'; |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Password Protection Status Field |
| 105 |
* |
| 106 |
* @since 2.1 |
| 107 |
*/ |
| 108 |
public function field_cookies() { |
| 109 |
|
| 110 |
echo '<p><input type="text" value="' . esc_attr( $this->plugin->cookie_name() ) . '" class="regular-text code" /></p>'; |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* WP Engine Hosting |
| 116 |
* |
| 117 |
* @since 2.1 |
| 118 |
*/ |
| 119 |
public function field_wp_engine() { |
| 120 |
|
| 121 |
echo '<p>' . __( 'We have detected your site may be running on WP Engine hosting.', 'password-protected' ) . '<br /> |
| 122 |
' . __( '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>'; |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* W3 Total Cache Plugin |
| 128 |
* |
| 129 |
* @since 2.1 |
| 130 |
*/ |
| 131 |
public function field_w3_total_cache() { |
| 132 |
|
| 133 |
echo '<p>' . __( 'It looks like you may be using the W3 Total Cache plugin?', 'password-protected' ) . '<br /> |
| 134 |
' . __( 'In order for Password Protected to work with W3 Total Cache you must disable caching when the Password Protected cookie is set.', 'password-protected' ) . ' |
| 135 |
' . 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>'; |
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Test: WP Engine |
| 141 |
* |
| 142 |
* @since 2.1 |
| 143 |
* |
| 144 |
* @return boolean |
| 145 |
*/ |
| 146 |
private function test_wp_engine() { |
| 147 |
|
| 148 |
return ( function_exists( 'is_wpe' ) && is_wpe() ) || ( function_exists( 'is_wpe_snapshot' ) && is_wpe_snapshot() ); |
| 149 |
|
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Test: W3 Total Cache |
| 154 |
* |
| 155 |
* @since 2.1 |
| 156 |
* |
| 157 |
* @return boolean |
| 158 |
*/ |
| 159 |
private function test_w3_total_cache() { |
| 160 |
|
| 161 |
return defined( 'W3TC' ) && W3TC; |
| 162 |
|
| 163 |
} |
| 164 |
|
| 165 |
} |
| 166 |
|