password-protected icon indicating copy to clipboard operation
password-protected copied to clipboard

Solution for WP Engine issues

Open benhuson opened this issue 12 years ago • 11 comments

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

benhuson avatar Feb 07 '13 10:02 benhuson

Development in wpengine branch: https://github.com/benhuson/password-protected/tree/wpengine

benhuson avatar Feb 09 '13 15:02 benhuson

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.

jb510 avatar Jun 16 '13 21:06 jb510

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 avatar Jan 05 '14 15:01 Zegnat

@Zegnat I have contacted WP Engine to ask it this might work with their caching setup

benhuson avatar Jan 10 '14 14:01 benhuson

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

thejamescollins avatar Apr 22 '14 04:04 thejamescollins

Thanks, I'll try adding that anyway as it is probably needed for other caching implementations too.

benhuson avatar Apr 22 '14 08:04 benhuson

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

thejamescollins avatar Apr 22 '14 08:04 thejamescollins

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.

benhuson avatar Apr 23 '14 08:04 benhuson

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

ttrowell avatar Mar 22 '16 20:03 ttrowell

Was anyone able to get this working on WP Engine?

ksr583 avatar Apr 20 '17 14:04 ksr583

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...

jb510 avatar Apr 20 '17 18:04 jb510