WP Super Cache and Cookie Banners

EDIT: Updated for WP Super Cache 1.6.3 and newer.

More sites use cookie banners now that the GDPR is active but some are finding that their banners are misbehaving once they enable caching.

This is a similar issue to the one that happened to some page counter plugins in the past. The page counter wouldn’t increment.

When a cookie banner is clicked a cookie is set in the browser so the website knows this visitor has agreed to accept cookies. If the cookie is set then the cookie banner html is not sent to the browser.

I suspect the main issue is that the code that sets and checks if the cookie is set is PHP. Unfortunately because the page is cached then no PHP code is executed, and the cookie banner is displayed because it was originally cached that way.

Since WP Super Cache only knows about certain WordPress cookies it assumes everyone who doesn’t have those cookies is a first time “anonymous” visitor. It doesn’t know about your cookie banner cookie.

You have two options:

  1. Rewrite your cookie banner so it’s completely in Javascript. Do the cookie detection in Javascript and also set the cookie in Javascript. If the cookie banner has been clicked then you need to trigger an action, and other Javascript that is hooked on to that trigger will run and load the tracking cookies.
  2. Modify WP Super Cache so it knows about the cookie your cookie banner uses. Caching won’t work quite as well as before as it’ll be split between visitors who have clicked the cookie banner and those that haven’t. One cached file will display the cookie banner, and the other will not but it will have ad tracking Javascript.

Using Javascript completely is a better solution because it runs in the browser on every page load but that might not be possible every time.

Otherwise, use PHP to get WP Super Cache to play nicely with your existing code. You basically need to run do_action( 'wpsc_add_cookie', 'cookie_name' ); after init so WP Super Cache adds the cookie name to its cookie list. This only needs to be done once, but you can leave it run all the time because it will only ever add the cookie name once. This also ensures the name is added again if the WP Super Cache configuration file is ever reset or deleted.

  1. Create a PHP script in wp-content/mu-plugins/ (or in to your own plugin).
  2. Add the cookie by using the wpsc_add_cookie action in a function that loads on “init”.
  3. Reload any uncached page and the cookie name will be added to the cookie list.
  4. Caching can only be performed by simple caching now, unless you’re willing to edit mod_rewrite rules in your .htaccess file.
/*
 * Tell WP Super Cache to cache requests with the cookie "eucookie" separately
 * from other visitors.
 */
function add_wpsc_cookie_banner() {
    do_action( 'wpsc_add_cookie', 'eucookie' );
}
add_action( 'init', 'add_wpsc_cookie_banner' );

Substitute the name of the cookie (eucookie) for your cookie name.

When your plugin is uninstalled it should remove your cookie with the following:

do_action( 'wpsc_delete_cookie', 'eucookie' );

For future reference, since cookie banners will hopefully not be around forever, here’s what they looked like in the deep, distant past of 2018. 🙂

The LA Times just gave up and don’t show anything to EU visitors.

The Supernova in the East

The latest episode of Hardcore History is another amazing audio tour through history, even if Dan Carlin himself says he is unqualified and it might not be completely accurate. He’s a great story teller. This one covers the rise of Japan in the early twentieth century and beyond.

Dan’s coverage of the Manchurian Incident reminded me I have to re-read the Tintin story, “The Blue Lotus“. Hergé definitely applied his imagination when recounting how the train track was blown up but I’d never have known about that period of time if I had never read that book.

And similarly, I wouldn’t have known the railway track was barely damaged if I hadn’t listened to Hardcore History!

Why is our car all dusty?

I have no idea. It’s only parked outside our home, where it’s always been.

Yeah, that’s where it comes from. When you live across the road from a building site. Where trucks queue on the road. Where they blast their horns on the main road to alert the crew on the site of their imminent arrival. Where I felt the air in my kitchen vibrate and resonate with the sound of the jack hammers and trucks passing. We fought it, we should have won, but we lost.

I had a really bad headache today.

My S7Edge gets the April Update

My Samsung Galaxy S7 Edge is now installing the April 1st update. It got Oreo a few months back and a few updates since. Going by Samsung’s track record I expect those updates to dry up any time soon but it’s good to see them still handing out any sort of updates.

In case you’re wondering, this is the unlocked international variant.

Version installed: G935FXXU2EREM/G935FOXA2EREM/G935FXXU2ERD6

Unmount USB drives from a script in macOS

I have a number of external drives hanging off my laptop, but sometimes I want to disconnect them. I used to go into Finder and click the eject button but I have five drives now so that’s getting unwieldy.

There are a few different ways of doing this. I wrote a small BASH script based on information here.

I created a shell script on my Desktop, added the following, changing DRIVE to the volume path for each of my external drives:

osascript -e ‘do shell script “diskutil unmountDisk /Volumes/DRIVE”‘

After creating that script I made it executable with chmod +x and as I use iTerm2 as a terminal I associated .sh files with that (Finder, right click on script, Get Info->Open With).
Every time I double click the script a new tab opens in iTerm2 and I see the progress of the unmount commands!

CervicalCheck Protest in Cork

More than 800 people marched through Cork on Saturday to protest the CervicalCheck scandal where 209 smear tests were misread and 18 women have died already.

Terminally ill Emma Mhic Mhathúna appeared at a protest today in Kerry.

In a poignant protest in Tralee town centre on Monday evening, the very day that she was told that her cancer has spread even further to her vertebra, Emma, in a moving and emotional speech, said that she would continue to fight for reform of the health service. 
“I am sick of being treated like nothing. Our health is the last thing that these people care about. The Dáil needs to realise that if they are going to take responsibility for our lives they better do it well or they need to be fired,” she told the crowd. 
“I promise my death won’t go unnoticed. I will make sure that they pay for what they have done to every single family in Ireland, whether you are on a waiting list too long or whether you are not being treated fair. Tell them you’re my friend and I’ll come and sort them out.”
“I can’t save my life but at least I can save yours and your children’s lives.” 

https://www.independent.ie/regionals/kerryman/news/kerry-stands-together-in-solidarity-as-emma-faces-death-sentence-36910803.html

Bohemian Rhapsody Overload

Hyped for this. Don’t be bad. Don’t be bad. Don’t mess it up.

It’s kinda odd to think of Elliot from Mr. Robot as Freddie Mercury but this trailer is promising, unless you’re going to pick holes in every little bit of it.

I enjoyed this interview with Rami Malek on The Late Show, and here’s a video produced by the band Bulsara and His Queenies called ‘A Sheer Homage’. Wow.

If you still haven’t had enough of Queen, (and who can?) the official Queen Youtube Channel has a number of 1 hour long compilations.

Finally, and this is the coolest thing ever, User cmi on the QueenZone forum has made an expanded collection of Queen albums. You’ll probably find bits and pieces there that you’ve never heard.

Maze of the Mummy & Freeze64!

Maze of the Mummy, rare “purple” Freeze64 and my regular Freeze64

Look what the postman delivered last week! I entered a competition held by Freeze64 author/publisher Vinny for C64 game Maze of the Mummy and a rare misprint of the Freeze64 fanzine and I won! You should watch the live video of Vinny picking the winner, if only to wonder at everything he has plugged into his C64 and a preview of issue 18 of Freeze64. He pronounced my name wrong too, but that’s to be expected. 🙂

I have yet to play Maze of the Mummy as it’s been a hectic few days here but I’m going to get my 1541-II down out of the attic and make a backup d64 image to play in Vice this week.

I think the last boxed C64 game I ever bought was Creatures 2 which was a long time ago so handling a physical copy of a new game sets off a mix of nostalgia for the old and eagerness to try something new. I’m looking forward to trying this game!


Bye Bye Google Backup & Sync

I’m a huge fan of Google Photos. It’s an amazing service that lets me quickly share photos with particular people, creates interesting images from my photos and it’s a convenient way to bring my photo archive with me on my phone.

Evening in Cork City

However, the new “Backup & Sync” app from Google that replaced the old uploader is problematic.

As well as uploading my photos to Google Photos it would backup to Google Drive. I don’t care about this feature because I use Backblaze for backups. I didn’t really realise what this meant when I first installed the app.

Slieve Liag

I told it to sync my “2018” folder and it dutifully started backing up to Google Photos but I soon noticed that the storage used in my Google account was decreasing. Eventually I found the computers section of Google Drive. All my files were backed up there.

It appears that “Don’t sync to this computer” doesn’t mean “don’t sync this computer to Google Drive”. However it does mean that any files deleted in the synced “Computers” section of Google Drive will be deleted locally. I found this out when I tried to save some storage space by deleting files off Google Drive. Later that day I fired up Lightroom and it reported that a large number of files were unavailable. I opened the folder in Finder only to see the images magically disappear before my eyes.

It was “Backup & Sync” deleting my local files. It was syncing deletes “to this computer”. Thankfully the files were still in the Trash so I could restore them quickly.

Cork City Hall in the fog

So, instead of wasting my storage I need to upload things manually. I see two options:

  • Drag and drop files on to a Google Photos browser window.
  • Sync one temporary folder where I copy duplicates of my photos. I need to periodically delete those files off Google Drive which won’t matter locally because they’ll be duplicates that are deleted immediately after upload.
Grand Parade under construction in 2007

It’s disappointing that Google merged the backup and sync functionality. Google Photos is not a backup service unless you pay for storage and upload full size images. For that reason I can see why they did it.

Thalamus The Hits

Thalamus was a game developer based in the UK in the mid 80s to early 90s. They had a reputation for flashy games and and pounding soundtracks. Most of their games were highly rated and their first compilation, The Hits, had some amazing games.

Sanxion and Armalyte were among my favourite shoot ’em ups while Hawkeye had great looking parallax scrolling. I thought the Delta theme music was great but the game didn’t grab me like Armalyte did. I’m going to get that game out again later..

Still have the receipt from Turbosoft in the box too!

Thanks Commodore Format for reminding me I bought this!