Comments (10)
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.
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.
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.
@arunbasillal Agree with you.
from wp-rocket.
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.
Hello @arunbasillal thanks for that, i just tried following these steps:
- Adding the snippet on my functions.php
- Deactivate and reactivate WP Rocket
- Clear all cache on WP Rocket
- 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.
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:
- It cannot be designed us our requirements
- It demands a username and password (and we need only password)
What I'm trying now is that:
- With your snippet on the functions.php
- I deactivate the Password Protected Plugin to Preload all pages
- 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.
@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.
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:
- 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.
- 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.
@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)
- Age Verification Screen for WooCommerce cookie gets stripped in Never Cache Cookies HOT 1
- Imagify update broke third compatibility HOT 3
- 3.16 - Send links fetched on homepage to the SaaS to trigger a visit so that LCP/ATF optimization has a warm-up HOT 8
- 3.16 - Specify the optimization_list parameter in requests to the SaaS to clearly state what the request is about HOT 10
- Wrong CSS generated when "lazyload background images" feature is enabled and stylesheet has `#` as `href` attribute
- Preload batch size is artificially reduced as we count in-progress rows with a pending AS action twice
- Update maintenance for LCP/ATF data storage HOT 1
- Detect imagify while avif is enabled
- 3.16 Add inline JS data for current URL and device HOT 1
- 3.16 - R&D - Beacon script compatibility with LazyLoad HOT 2
- Replace Vimeo iframe with preview image
- 123
- Images inside CSS file names that contain space or special char will not be lazyloaded
- test defect
- Failed test: Should exclude file name containing space from LL BG image
- TEST MLT - Failed test: Should exclude file name containing space from LL BG image
- Failed test: Demo test case MLT
- Elementor Builder - LL BG images added on ulterior edits will be visible only after a clear cache
- Old/Failed rows are not deleted due to incorrect table name
- Generatepress Elements and Remove Unused CSS HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wp-rocket.