Writing WP Super Cache Plugins

WP Super Cache is a full page caching plugin for WordPress. When a page is cached almost all of WordPress is skipped and the page is sent to the browser with the minimum amount of code executed. This makes the page load much faster.

Unfortunately if you want to run code on every page load you’re out of luck as regular WordPress plugins are not loaded or executed. You’ll need to write a WP Super Cache plugin. This short introduction will not teach you how to write plugins but the example plugins that ship with WP Super Cache will get you a long way towards understanding how they work.

Screen Shot 2017-10-25 at 16.49.10

WP Super Cache ships with some example plugins in wp-super-cache/plugins/. Some of them even do useful tasks like help with domain mapping and Jetpack integration. There’s one called “awaitingmoderation.php” which removes the text “Your comment is awaiting moderation.” when someone writes a moderated comment.
There’s also dynamic-cache-test.php which is a complicated beast but it’s heavily commented. It allows you to add template tags to your site that are replaced when the cached page is loaded.

Before you get started writing a plugin you should be aware that you should not use the wp-super-cache/plugins/ directory. Every time WP Super Cache is updated this directory is deleted. So, edit your wp-config.php and set $wp_cache_plugins_dir to another directory where you’ll put your plugin.

These plugins run before most of WordPress has loaded. That means you can’t rely on some of the nice features of WordPress such as filters and actions. However, WP Super Cache has it’s own action/filter system that is similar to actions and filters in WordPress:

  • add_cacheaction( $action, $func )
  • do_cacheaction( $action, $value = ” )

A cacheaction is also a filter. If you hook on to a cache action that has a parameter, you must return that parameter at the end of the function like you would with a WordPress filter.

Screen Shot 2017-10-25 at 16.52.59

If you need to hook into a WordPress filter use the imaginatively named cache action “add_cacheaction”. That runs on “init” so the function that is executed can use add_action() or add_filter(). You can see this in action in the plugins/dynamic-cache-test.php or plugins/awaitingmoderation.php scripts.

Two very useful filters are the WordPress filter, “wpsupercache_buffer” (in wp-cache-phase2.php) that is used to modify the page before it is cached and the cache action “wpsc_cachedata” (in wp-cache-phase1.php) is used to modify the cached page just before it’s served.

The Aftermath of Hurricane Ophelia

Hurricane Ophelia hit Ireland yesterday and while it was a baby compared to the monsters that ravaged the Caribbean and US it still did plenty of damage and left 3 people dead. Many areas were left without electricity or running water for most of the day. A day later and there are still areas without those basic amenities. Telecoms services were disrupted too as lines were cut and exchanges and mobile sites ran out of power. 30,000 people were without access to phone or Internet access. A red alert was declared nation-wide. Schools closed (for 2 days), public transport wasn’t running, shops and businesses didn’t open. There was a definite fear and expectation that this would be a big one. And it was. Gusts of 156kmh were recorded off Roches Point!

We were without power from just after 11am, then the mobile phone network, Eir, went down, except my wife’s phone was able to go online for minutes at a time throughout the day. Winds really picked up around 10am, and lasted until after 2pm with driving rain almost horizontal in the wind. Later in the day I walked around Blarney village and from the far corner of the square got a weak signal from a remote antenna and had just enough connectivity to get a few text messages.

Trees behind our home were knocked down by the wind, blocking most of the main Waterloo Road. Luckily the very tallest trees survived as they’re within reach of some of the houses!

Even this stop sign was twisted around by the wind, and mushrooms flattened too..

Two trees were knocked down in the village square, and someone had attempted to drive a car and caravan up that narrow road before getting stuck and abandoning their vehicle!

Power came back late yesterday evening, as did mobile data, but friends are still without power even now so it’s going to take some time before things are back to normal. Our satellite dish is broken, and it’ll be early November before someone can come out to replace it. Parts of my garden fence blew over too, but that was on it’s last legs anyway! A TV antenna ended up in our front garden, but I have no idea who owned it.

This morning there was a lovely sunrise, and the sky was a gorgeous mix of blue and soft orange. 🙂

Next weekend we can look forward to #StormBrian apparently. Hopefully it won’t be as bad as Ophelia.

This is odd… dot blog

dotblog-social

I’ve had some sort of online presence for twenty years, and that presence has been this blog for most of that time. When I started posting stuff online, PHP was still a toddler and I used a simple Perl script to merge html files with a content file before it was squirted up to an FTP server for publication. I’ve always put the newest news at the top, pushing older entries down, just like it is now. Ah, the glorious days of editing the file in Vim, copying and pasting posts from the “main” page to my “archive” page. I don’t miss it, WordPress makes that much easier now!

In those early days this site would have been called an “online diary” or journal. Apparently the term “weblog” was coined at the end of 1997 but I didn’t hear about that until a few years later. Blogs have been so very important to me in my personal and professional life so I’m really excited that this blog now lives on a .blog domain at odd.blog!

Automattic is rolling out the .blog domain, and as Matt says,

The namespace is wide open, and if you’re interested in reserving or bidding on your favorite name you can go to get.blog.

Stephanie Shirley: Software Pioneer

Stephanie Shirley: Software Pioneer

I’d never heard of Stephanie Shirley until I heard this BBC interview with her. As a five year old she escaped the Nazis in Germany, escaping to Britian in a Kindertransport. She founded a software company in 1962 that only hired women. It allowed employees to work from home, a practise that is much more common now than it was then. At the time women were not always welcome in the workplace, especially after they married or had kids, so this was an exceptional change. Ironically, equality legislation years later forced them to hire men!

In her personal life, her son Giles was autistic. Caring for him caused her to have a nervous breakdown as she tried to run her business too but she has poured huge sums of money into autism research and in her retirement has given away most of her £150m wealth.

To help Giles and others like him, she first established the Kingwood Trust to support young adults with autism, and more recently started the Prior’s Court School in Berkshire. “It is actually the biggest single project,” she says. “It took five years of my life. That’s the one I dreamed about.” It aims to help autistic children into mainstream education or some form of employment by using innovative techniques in art, music and sport.

The Shirley Foundation has spent or allocated around £50m in recent years – putting it among Britain’s top grant-giving foundations – with 70% going to autism-related work, from the first online conference on autism to yet another start-up, the Welsh support network Autism Cymru.

She also spoke at TED which she talked about her life.

If you want to hear about a remarkable woman, listen to this podcast and watch her on the TED stage.

Standing at my Varidesk

The last time I tried standing at my desk was a bit of a makeshift affair. I piled up books on either side of a plank of wood for my keyboard and mouse to rest on, with another pile of books for the monitor. It worked, but it wasn’t pretty, it was a bit unstable, and it wasn’t flexible. When I got tired later in the day or evening I couldn’t sit down and type without lugging around a bunch of graphic novels and copies of National Geographic.

So, last December I bought a Varidesk Pro Plus. There aren’t many sellers in Ireland but I bought mine here. Prices are expensive compared to the US but they’re imported from there I think so there’s VAT, import duty and all the associated costs of bringing things across the Atlantic.

Varidesk Pro Plus

The desk can be raised and lowered easily, that’s the best thing about it. It also rests on your existing desk so you don’t have to get rid of that. I can fit my office chair under the desk when I’m standing, which is great because my office is a tiny home-office. I was worried about the space for my keyboard and mouse because I use a split Microsoft keyboard but I shouldn’t have. It fits comfortably. The mouse has plenty of room too. The area for that is about 24x19cm, or large enough to rest a 9″ iPad. I’ve never had a problem with my mouse bumping against the keyboard for want of more space.

The only negative I can think of is that you need to take care of cables when lowering or raising the desk. Sometimes my monitor cable will get caught between the desk and a raised portion of my original desk at the back, and I have an old USB2 hub for my keyboard and mouse that occasionally gets caught under the desk. Those are very minor issues. I also use foldback clips to secure cables on to the desk which really helps too.

It does show the dust badly sometimes, especially when caught in sunlight like the photo above. In reality the dust is a lot easier to ignore, especially when you have a load of documents or stuff sitting on top of it. 🙂

There are a few video reviews of the desk out there, here’s a good one. It’s well worth buying if you’re sitting at a desk all day!

What colour do you see?

colour of the dress

It’s odd how this picture has gone viral. I saw it on Reddit, Twitter, Facebook, Google Plus and even on a blog, which just goes to show. Blogs are still hip.

Anyway, I see blue and black, but some people see white and gold. My son looked at the exact same screen I was looking at, but at an angle and said he saw brown and white. When he moved around he said he saw some blue but it was still mostly white. Odd.

Steven Novella has written a good post on this and explains why our brains see this difference. Wired have a good article too. It’s an optical illusion. Just like these:

dress_color

The two objects are the same colour. Cover the middle join with your finger.
The two objects are the same colour. Cover the middle join with your finger. (Thanks Davide!)

Are Squares A and B the same colour?
Are Squares A and B the same colour?

At least we can all agree on one thing: The people who see the dress as white are utterly, completely wrong.

Man on the Mun

man on the mun

Finally, a Kerbal stands on the Mun in Kerbal Space Program. Well done Corkin Kerman! Unfortunately the lights go out each night as the rechargeable battery runs out of power around 3am. That upsets poor Corkin as he’s engrossed in David Nicol’s new book, Lament for the Living. He printed out the Kindle version you see..

I would like to say I did it without any help but Mechjeb 2.0 played a part in getting Corkin there. The Smart A.S.S is invaluable for landing and a great help lining up for a manoeuvre node. Thanks TalenTaylor for your asparagus engine layout and moon lander tutorials. With 7 Jumbo fuel tanks I reached orbit with a tank that was almost 75% full! Good thing too as I burned that getting to the Mun and cirularizing my orbit. Efficiency? Bah, I laugh in the face of efficiency!

ksp minor glitch

It wasn’t all plain sailing. Once or twice the moon lander never even reached orbit. Ooops.

TCPEye: Windows network software to list Internet usage

If you use Windows and you’re curious about what’s using your Internet broadband then the free TCPEye tool will probably help you.

I used it a few weeks ago when something was sucking down gobs of data and making everything else slow. Turns out it was Windows Update, but not on my desktop machine, a laptop on my network was updating.

The odd thing with TCPEye is that CNET Downloads is in the number 1 place when searching for this tool. Reviews even link there instead of the author’s homepage!