wp-supercache handling proposal
-
GDPR Cookie compliance plugin use supercache handle wpsc_add_cookie to register cookies and make cache to differentiate cache files on cookie value. However, this approach has a weakness: on presence of cookie_notice_accepted cookie wp-supercache plugin does not store generated page as a static file (index.html, index-https.html, …-mobile.html, etc.) but generates a php file with pseudo-random name (containing encoded cookie value) and meta file for each cookie value. This prevents serving static files in expert cache mode because only supercache php script can calculate a valid name, read and serve cache file.
However, in the simpliest case we have only one cookie with one value: cookie_notice_accepted: true. So, instead of creating random files, it would be far better to instruct wp-supercache to create another variant of a static html file for a page with this cookie name and value. I know the plugin premium version uses another cookie hu-consent, but in that case probably there are only a few more values and the solution would be slightly more complicated.
My proposal consists of a few lines of code, first to deregister cookie registered by GDPR plugin, next to instruct supercache to use another variant of a static file for a page with the cookie:;1. deregister cookie name from supercache function wpsc_delete_cookie_notice_check() { do_action( 'wpsc_delete_cookie', 'cookie_notice_accepted' ); } add_action( 'init', 'wpsc_delete_cookie_notice_check', 20 ); ;2. Set the name variant function wp_super_cache_cookie_notice_check( $extra_str ) { if ( isset( $_COOKIE['cookie_notice_accepted'] ) && 'true' === $_COOKIE['cookie_notice_accepted'] ) $extra_str .= '-cookied'; return $extra_str; } add_action( 'supercache_filename_str', 'wp_super_cache_cookie_notice_check' );
Now, in my situation wp-supercache creates 2 variants of a static page file: index-https.html for users without a cookie and index-https-cookied.html for these with the cookie.
This works both in a simple cache mode and in an expert mode with rewrite rules for direct serving pages without php.Should this method be incorporated into plugin code, the first part is unnecessary, together with current init action in plugin code (do_action( ‘wpsc_add_cookie’, ‘cookie_notice_accepted’ )), what need to be removed. The whole code is smaller and we can use expert cache mode.
- The topic ‘wp-supercache handling proposal’ is closed to new replies.