Code Monkey home page Code Monkey logo

Comments (10)

arunbasillal avatar arunbasillal commented on May 29, 2024 2

Hello @metelidrissi

I did some testing and found a work around for WP Rocket to work with Password Protected. So if my understanding is right, Password Protected sets bid_1_password_protected_auth as a cookie once the user enters the right password. If this cookie is set as a mandatory cookie in WP Rocket, then WP Rocket will only generate and serve cache files if the cookie is set.

To use this:

  • Please add the following snippet to the functions.php of your active theme.
  • Deactivate and then Reactivate WP Rocket. Clear WP Rocket cache.
/**
 * Add Password Protected plugin's cookie as mandatory cookie in WP Rocket 
 *
 * Password Protected plugin (https://wordpress.org/plugins/password-protected/) sets the cookie 'bid_1_password_protected_auth'
 * once the user enters the right password. WP Rocket will only generate and serve cache files if this cookie is set. 
 *
 * Important: Remember to deactivate and reactivate WP Rocket after adding this snippet so that WP Rocket can update it's config file. 
 *
 * @param array $cookies Array with mandatory cookies.
 * @return (array) Array of mandatory cookies with the Password Protected cookie appended
 */
function rocket_add_password_protected_cookie( $cookies ) {
	$cookies[] = 'bid_1_password_protected_auth';

	return $cookies;
}
add_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_password_protected_cookie' );

//Override DONOTCACHEPAGE behavior for WP Rocket.
add_filter( 'rocket_override_donotcachepage', '__return_true', PHP_INT_MAX );

// Remove WP Rocket rewrite rules from .htaccess file.
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false' );

Please try this out and let us know what you think.

Notes:

  • Password Protected also sets DONOTCACHEPAGE constant. This prevents caching.
  • Rewrite rules in Apache also needs to be removed for this to work I think. Which is why that filter is added in the snippet.

from wp-rocket.

arunbasillal avatar arunbasillal commented on May 29, 2024 1

Happy to hear that it is working! Thanks for the confirmation.

Preload will not be possible with password protection. With preload what WP Rocket does is send a visit to each of the pages. Since the pages are password protected, the pages won't be loaded and hence wont the preloaded. This will be a limitation when using this form of password protection.

Side note: Instead of using the Password Protection plugin, if you were using password protection using .htaccess, then it can be preloaded using this helper - https://github.com/wp-media/wp-rocket-helpers/tree/master/preload/wp-rocket-preload-htaccess-auth
You can google to figure out how to setup password protection using .htaccess.

from wp-rocket.

arunbasillal avatar arunbasillal commented on May 29, 2024

We have very few tickets related to this plugin and it doesn't make sense to have a custom compatibility for something with so few issues - https://secure.helpscout.net/search/?query=tag%3Apassword%20protected%20plugin

@GeekPress @webtrainingwheels What do you think?

from wp-rocket.

GeekPress avatar GeekPress commented on May 29, 2024

@arunbasillal Agree with you.

from wp-rocket.

metelidrissi avatar metelidrissi commented on May 29, 2024

Is there an alternative plugin to Password Protected compatible with WP Rocket?

Is there the possibility of simulating that WP Rocket has that cookie active so that it can cache the pages of a web where all the pages have access restricted under password?

Thanks

from wp-rocket.

metelidrissi avatar metelidrissi commented on May 29, 2024

Hello @arunbasillal thanks for that, i just tried following these steps:

  1. Adding the snippet on my functions.php
  2. Deactivate and reactivate WP Rocket
  3. Clear all cache on WP Rocket
  4. Click on preload caché

It works well, because when I'm accés to the website Password Protected asks for the password, and after I'm login for each click it creats a "cache" file as aI can see on the FTP.

But how to do for the automatic preload? I have to click manually for all of the items? Is there a way to run automatically?

Thanks again

from wp-rocket.

metelidrissi avatar metelidrissi commented on May 29, 2024

Hi @arunbasillal

We contemplate that option HTTP BASIC AUTH at the time but as the project requirement needs to perform a design on the "Login" first page the HTTP BASIC AUTH it's not an option for us for these two points:

  1. It cannot be designed us our requirements
  2. It demands a username and password (and we need only password)

What I'm trying now is that:

  1. With your snippet on the functions.php
  2. I deactivate the Password Protected Plugin to Preload all pages
  3. After all pages are preloaded i will activate again de Password Protected plugin

Maybe that it can help for someone else. For the moment that works for us, ee appreciate your snippet and the time you dedicate for the help thank you very much again.

Thanks!

from wp-rocket.

arunbasillal avatar arunbasillal commented on May 29, 2024

@metelidrissi Thanks for the update. That approach to preload works, but then the cache is cleared automatically every 8 hours (or what is set in the cache lifespan setting unless it's set to infinite). So it won't be a sustainable solution.

The loss in performance without preload is marginal since it affects only the first user. The first user will act as the preload in this case. When you have to enter a password, users typically are willing to wait a little more than usual. Just my two cents.

Thanks for the kind words and good luck!

from wp-rocket.

metelidrissi avatar metelidrissi commented on May 29, 2024

Hi @arunbasillal,

Yes, that works for the first run, but as you said it won't be a sustainable solution if we set to infinite as we have it now.

We don't know if these two situations are right, we are assuming is how it works:

  1. If some administrator updates a price of a product on woocommerce or any else element on any page, the cache for the specific page/product/post it's cleared forcing for the first user preload the page.
  2. If some administrator add new products, pages, or post, the pages where is the product/post (archives) it clears and it preload for the first user

Because at this cas the updates are very occasionally it can be ok if these 2 points are right.

Thanks again!

from wp-rocket.

arunbasillal avatar arunbasillal commented on May 29, 2024

@metelidrissi You are right on the second point. WooCommerce products are custom post types. Any update to it should clear the cache and preload it as long as the preload option is turned on. (doc)

from wp-rocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.