Solution for WP Engine issues
Password Protected will not work with WP Engine due to their page caching.
Suggestion is to implement a Javascript redirection fallback and display a message to users in admin. Also in the readme file.
http://wordpress.org/support/topic/plugin-not-working-with-wpenging-cache
Development in wpengine branch: https://github.com/benhuson/password-protected/tree/wpengine
Bummer... One of the reasons I liked this plugin was simple blocking of "the general public" and search engines on development sites where I could give clients a simple password to see the site without being a logged in user.
I'm guessing however that this JS method won't block search engines. Maybe I need to test.
Have you ever tested sending a Vary header for Cookie? This should let caching know to cache a different page depending on what cookies someone has. See this great Stack Overflow answer for an example of Vary: Cookie.
I believe the WordPress filter wp_headers can be used to send custom HTTP Headers:
function add_cookie_to_vary($headers) {
if (
isset($headers['Vary']) &&
0 === preg_match('/(^|,)\s*Cookie\s*(,|$)/i', $headers['Vary'])
) {
$headers['Vary'] .= ',Cookie';
} else {
$headers['Vary'] = 'Cookie';
}
return $headers;
}
add_filter('wp_headers', 'add_cookie_to_vary');
Note that I do not use WP Engine. I just came upon this plugin by chance and saw this issue. I’ll leave the testing and possible pull request to others.
@Zegnat I have contacted WP Engine to ask it this might work with their caching setup
Hi @benhuson, did you have any luck with your discussions with WP Engine?
Possibly using the DONOTCACHEPAGE constant might be a solution? If defined and set to true, I think WP Engine won't cache the pages.
WooCommerce do a similar thing for the cart/checkout pages: https://github.com/woothemes/woocommerce/blob/9bc14a4aa5c7ce6cfd1f36e14c03e7c8a7ee9862/includes/class-wc-cache-helper.php
Thanks, I'll try adding that anyway as it is probably needed for other caching implementations too.
Thanks @benhuson,
I think most of the major caching solutions (WP Super Cache, W3TC, etc) all obey that constant.
And I suspect WP Engine's caching mechanism also does too.
James
Just noticed I already do that: https://github.com/benhuson/password-protected/blob/master/password-protected.php#L88
I might split it out from the is_active() method to make it more obvious in the code.
Hello there, Customers also want to use this plugin on Pantheon and have caching issues. Is there any way you will consider allowing the plugin to bypass Varnish for compatibility? https://pantheon.io/docs/caching-advanced-topics/
~Tara
Was anyone able to get this working on WP Engine?
I no longer use this plugin, I mostly use 10ups Restriced Site Access plugin (not necessarily better, just what I use). It too has some issues with WPE, but they can be gotten around: https://wordpress.org/support/topic/incompatibility-with-wp-engine-plus-fix/
I don't recall exactly how this plugin functioned, but maybe that can work here too (and on Pantheon)
Note however that on WPE you do have this built in option (which was what we actually use on WPE): ttps://wpengine.com/blog/announcing-password-protection-sites-development/ That's not suitable to all cases obviously...