Remove extra RSS feeds in WordPress

Here’s a WordPress snippet to remove RSS feeds for comments while keeping the main one available.

RSS Icon

RSS is super nifty. It’s a great way to keep on top of breaking news and articles from your favourite blogs and/or aggregators (I’ve got over 100 subscriptions in my feedly reader).

So it’s a wonder then that WordPress offers RSS feeds for comments on all your posts. I presume there’s a group of people who really like to track conversations, but in my experience, it’s the minority. This functionality should really be an additional (and not core) part of WordPress. If you want to prevent your site serving pointless additional RSS feeds, you’ll need to remove them from wp_head.

Removing them, however, is a two-step process. Add the following to your functions.php file:

And that’s it. The first two actions strip the RSS using remove_action with a high priority. The final add_action call tells WordPress to load our function when processing wp_head. This will go through and reinsert the main feed, leaving the comment feed out.

Congratulations! Your post conversations are now untrackable.

WordPress: Add page slug to body class (including parents!)

Are you using WordPress as a CMS? Do you want to style pages with CSS logically? You might want to try this.

By default, WordPress will inject the page and its ID into the body class. That’s great if you’re only running a single install, or if you really really don’t care what your CSS looks like.

Let’s face it – you care. Otherwise, you wouldn’t be here. Here’s a snippet that will inject the current page’s slug and all slugs of its parents into the body class of your HTML.

Add this to functions.php

And that’s it! You can then start chaining together page classes to target little overrides that your clients are probably hassling you about.

Help! register_activation_hook isn’t working!

If you’re developing a plugin, chances are you’ve been caught out by the WordPress activation/deactivation hooks.

I’ve been working on an Instagram plugin for WordPress, and in doing so have needed to use the functions register_activation_hook and register_deactivation_hook.

However, I – like many others, it seems – can’t get the hooked functions to execute. They simply don’t fire. To illustrate the problem, here’s an example from the code:

I would fully expect the system to execute the functions hooked within the constructor. Had that been the case, I wouldn’t have lost a day debugging a non-existant problem.

Finding a solution

Of course, everyone’s setup is different. There were many suggestions for fixing the problem. For the sake of usefulness, here’s the other major suggestion:

Your global variables aren’t global

If (like me), your plugin is a global, you actually need to explicitly define it as such with the global keyword. For example, the snippet

should instead by written this way:

Why? Well, for this, we need to consider how the plugin has its code loaded. After installation, your plugin has its code included “normally” with standard includes. This creates the global scope that you would expect. However, when you register a function with register_(de)activation_hook, it is called from within another function’s scope, effectively hiding your non-explicit globals.

Confused? Consider the plugin example from earlier. The variable $my_instagram is declared in the global scope, with global visibility. When your code executes, your plugin is included at the same scope, meaning you will have access to the variable (as they share the same suitably-high scope). Due to the way the hook/filter system in WordPress works, your activation/deactivation hooks are executed within a localised (not global) scope.

Screen beans - the only thing worse than scope.

Screen beans – the only thing worse than scope.

This scope-confusion applies to all functions created using create_function, or (in our specific example), functions called with call_user_func (and call_user_func_array). These functions have their own scope and are thus shielded from the cheap-and-nasty pile of implicit “globals” that haven’t been properly declared as such.

You can find a suitably more technical (and probably correct) write-up at the WordPress Codex page for register_activation_hook.

tl;dr: Explicitly declare your globals if you want them to work everywhere.

Ok, that’s great, but what’s the answer?

After having accidentally (and rather unwillingly) been given a very rough refresher on scope, I found that this was not my problem at all. Even running proxy functions (which eliminates scope issues) failed to call the functions specified in the hook.

After much trial and error (and I mean much), I found that the paths within register_(de)activation_hook were not matching the path found in plugin_dir_path. In fact, __FILE__ was returning a completely different path.

The problem? I had symlinked the theme directory in my install, meaning that __FILE__ returned a different path to plugin_dir_path. This is especially important, as the file path specified by the first parameter of register_(de)activation_hook is included before the function specified by the second parameter is called. So, if the path in the first parameter is wrong, you probably aren’t going to be executing many functions today.

The Fix

This is always my favourite part. To fix the symlinking problem, you just have to be very specific when you’re asking WordPress to execute a hook for you.

Fixing the first example, we get:

The most important changes occur on lines 1, 16, and 17. The first line fixes the definition by manually specifying the path using the base plugin directory (instead of an automagic WordPress search). Lines 16 and 17 specify the main plugin file itself as the path (instead of relying on __FILE__).

This allowed WordPress to find the plugin files without a hitch, which is especially important in the installation/uninstallation phases.

Moral of the story? Check your paths first.

Paths

LinkedIn – Lesson #1

My battle against recruiters continues with a strange and random request from LinkedIn.

I consider rejecting unsolicited LinkedIn mail my sisyphean punishment for some mysterious crime I did not commit. An ever-present tide of human ignorance washing against the grainy shore of my day, snuffing out what little hope I had left that the entire population was not – at some fundamental level – simply a dipshit.

It is no wonder, then, that I grew weary of replying to people who couldn’t do their job. The ever-persistent advance of this multi-headed hydra was eroding my enthusiasm for being a twat. Apathy was winning.

Another day, another email, and I replied with a terse “contact the manager”. A little while later, I was surprised to find the following response:

> Who is the GM?

Now, I’m no expert on LinkedIn (hell, I rarely venture from my own profile), but I certainly know how to click a link when I see one. Several, in fact. Sometimes in a row. So when the information you’re after is fewer clicks away than finding your inbox, you should probably just take the easier option. But if this is something you need to be told, I guess there is probably a greater concern here, right?

Instead of giving him a real answer, I decided to be a complete dick about it and go ahead and create this handy little video tutorial. Take note, LinkedIn trawlers.

I think my passion has returned.

 

Help! My photos are missing hover text!

If you’re an avid Tumblr blogger and have suddenly realised your hover text (tooltips) are missing from your photos, your day is about to get better.

Something brought to my attention recently is the lack of tooltips that appear for photos posted on Tumblr, even when a caption/description is provided using the editor.

Tumblr image uploader

The image thingamajigger from Tumblr

Code-Monkey explanation

What’s actually happening here is that Tumblr/Tiny MCE is incorrectly assigning the alt text of the image. The specification outlines the use of alt text as a replacement for the image in the case that it fails to load or if the client is, in-fact, using a screen-reader, not as a tooltip (hence “alternative text”). Browsers have been using alt text as a fallback for title text for years, and this incorrect implementation is finally catching up to developers.

The tooltip text should instead be assigned to the title attribute. This is the text that shows on mouse over.

Ok, can you fix it for me?

For the blog-(and not code-)savvy, you can add a tooltip by fixing your image tags, like so:

becomes:

I’ve noticed this behaviour most recently in Google Chrome, but I suspect other browsers will follow suit. It is in accordance with the spec, after all.

I hope this cleared things up for all you Chrome-wielding bloggers out there.

Bad Reviews: Going to Brown Town

I found a can at the back of the fridge with an expiry date of 26th of October, so I did what any reasonable person would do – I drank it.

I stumbled across this can of instant coffee while raiding a friend’s fridge. Although I’m no stranger to ready-made coffee, I was genuinely intrigued as to why someone felt the need to import a (canned) dairy product when we have so many cows right here in Australia more than willing to squirt out a few quarts of deliciousness.

Despite all recommendations to the contrary, I went ahead and decided to drink it.

The Packaging

Except maybe the words "trust me"

Nothing says ‘trust me’ like a full-faced beard. Nothing.

The can itself is what initially piqued my interest. The packaging features a stereotypically fat Mafioso winking suggestively out from the label, holding what is presumably a well-made espresso. Nothing says “quality coffee” quite like sticking it in an aluminium can and shipping it 7000 kilometres across the ocean.

Our protagonist (Mr Brown) is the visual amalgamation of several of the biggest Italian stereotypes of the last 100 years. I imagine a very jaded graphic designer typing “terrible Italian clichés” into Google images and shoehorning in as many results as possible.

The Opening

You be the judge!

Bad coffee or toilet water? You be the judge.

There’s always something very off-putting when you lift the tab and don’t hear that refreshing KSSHHH sound associated with (most) other canned drinks. Judging by how much the can expanded upon opening, there was a whole lot of trans-continental pressure inside. Were they keeping something out, or keeping something in.

A precautionary peek inside revealed the familiar brown hue of cheap coffee/watery diarrhoea. I gave it a tentative sniff and was relieved to find that it at least smelled (mostly) like coffee. I figured it was probably best in the long-term to pour this out into a glass. Should things turn bad, I’d at least be able to see why.

Mr Brown *was* one of the Reservoir Dogs

Seemingly innocuous so far. Laugh it up, Mr Brown.

The Tasting

Ignoring the floating white flecks of (probably) milk-powder on top, I took a mouthful of the very-watery coffee drink and committed it to my digestive system.

Past the lips, over the tongue, through the gag reflex, and down the gullet.

The drink tastes like it wants to taste like coffee. I was even taken aback a little by the apparent quality. Once it washed past my tongue, though, all semblance of arabica had vanished, leaving nothing but the stale taste of week-old soggy cigarette butts and dirty pipes. I repeated the feat to ensure that I was not mistaken. I was not.

I choked down the rest of this coffee/cigarette drink out of spite.

The Verdict

Honestly, given the wide array of instant coffee out there, I’m surprised that bad instant coffee drinks exist at all. Moreover, why are they being imported? We Australians are perfectly capable of churning out abysmal products without overseas help.

I did enjoy the experience of drinking what is normally a two-step breakfast for me – coffee and cigarettes. Mr Brown is probably working on his pitch to Sanitarium’s Up and Go team right now. A true meal replacement for champions.

Signor Marrone e inaffidabile

Italians – Made in Taiwan

 

It didn’t have to be like this

Welcome to Cancer Council Victoria’s latest campaign against cervical cancer.

Although I enjoyed the absurdity of the video, a few questions remain:

  1. What was the author trying to convey with their selection of background music? Romance? Sleaze? Seems too slow and deliberate for just a bit of the old in-out.
  2. Why did Joey McStudsalot go straight for the prize? Cool your jets, soldier, you’ve got all night. We’re listening to the same soundtrack, right? There’s nothing more embarassing than finishing before the album, let alone the first song.
  3. What the hell is powering her panties? I’m guessing some type of bio-fuel. I bet there are some sweet government subsidies on that. Probably renewable, too.
  4. Is Nanna Likestowatch dead? Alive? Part of an experimental ASIO project? Whichever it is, it seems like her granddaughter’s hamfisted attempt at getting laid has bothered her enough to pipe-up. I don’t know about you, but nothing makes me want to unhave sex more than my dead grandmother telling me about my potentially-festering loins.
  5. Is McStudsalot a robot? Or at least a futuristic fusion of man and machine? Then how the hell is he still raring to go after getting a lecture on his girlfriend’s nethers by a photo on a mantelpiece? I would’ve tipped off down the street, underwear in one hand and a phonecall to the Scooby Gang in the other.

Hopefully these are all answers we can get straight from the cutting room floor. I expect no fewer than two follow-up videos to this: one from the Erectile Dysfunction Centre, and the other as an episode of C.O.P.S.

Zoinks.

“EMPLOYMENT OPPORTUNITY”: Advice to recruiters everywhere

I get a lot of email from recruiters. Mostly because I hate recruiters and the fact they are a necessary evil, but also because they usually contact me by doing scummy, impolite/disrespectful things, like calling me at my workplace on my company phone, or emailing me when I’ve clearly stated not to.

Given the volume of mail I receive is not looking to wane any time soon, I’ve decided to start handing out unsolicited advice to any recruiters ignoring my previous (polite) requests.

You have been warned.

Hi Tim,

I came across your profile on LinkedIn and wanted to discuss a Senior Developer / Leader role I am recruiting for.

The client industry is education and is the largest provider of online distant education. They are looking for a Senior/Team Leader PHP Developer with strong Linux and ideally Drupal knowledge.
You will be leading the development of our next generation of desktop, mobile, social, and email-based online solutions.

Reporting to the Head of E-commerce, you will be working closely with our creative team of graphic designers, user experience architects and analysts to develop a state-of-the-art online student acquisition initiative.
The key deliverables/outcomes for the role is the following:

-       Leading a transition from a Microsoft.NET based environment to an open source environment, specifically Drupal on LAMP.
-       Delivering a Drupal site with approximately 500-1000 products (various types ofeducation courses), on around 20 themes, running on desktop and mobile.
-       Building and leading a highly scalable off-shore team.
The client is based in North Sydney and are looking to pay around the 120k mark.

Would you be interested in this position?
If you are not interested but know someone who would be ideal for this position then please forward on my details and should I place your referred candidate then I will give you $250 worth of vouchers (Terms Apply).

I will look forward to hearing from you.

Many Thanks

First up, this is not a personal email. I get literally dozens of these emails a week. Consider yourself more a sweepstake “winner”. Except that instead of a half-baked and probably flavourless meringue, you get my vitriol mixed in with unsolicited advice. Once again, not personal. I’m just honestly sick of being contact when I’ve explicitly told LinkedIn I’m not interested. Ever.

So, a couple of things:

1) I have my “contact if…” settings on LinkedIn set to everything but “send me a job”. I’m not sure why you don’t see this, but I suppose proper etiquette would suggest that you would check. If one didn’t realise that this setting existed, I think that one should probably play with LinkedIn a little more before using it as a significant workplace tool.

2) As this email is more than likely a blanket mail-merge/LinkedIn spam clusterfuck, I can probably ignore any semblance of sincerity or professionalism. Noone came across my profile. Well, I probably did a little after I finished writing it, but other than that, noone is manually reading this. I once had “Code Monkey” on my LinkedIn resume for 18 months and STILL got job offers. Any company willing to hire some dipshit who doesn’t take their own job seriously doesn’t deserve to be taken seriously themselves.

And now, the job:
1) “Largest provider of online distant education”? They aren’t in Sydney. If they are, they aren’t the largest provider of anything. Except probably bullshit. At least half a dozen international Universities do this (and better), not to mention the FREE SERVICES that are kicking around right now that are growing at mind-boggling rates with FREE CONTENT that doesn’t run on some rubbish platform. Speaking of which;

2) Drupal. I don’t really use it. Actually, most people don’t really use it. It’s kind of like WordPress. A handful of people are “good” at it. A significant number of people can tinker around and “get it to work”. Everyone else just copies and pastes bits and pieces of code until the damn thing stops reporting errors. If this site is the “largest provider of [whatever]“, they don’t need someone who ‘might’ know Drupal, they’re going to want the half a dozen people who know how the platform works so they don’t fuck up someone’s life with a shitty web service. Not to mention the volume of work that they think they can rollout.

3) You can’t be eCommerce and eLearning. Pick one or stop fucking over your userbase.

4) I don’t know what the hell “highly scalable off-shore team” means, but it certainly sounds like a whole bunch of industry wank for “cheapest chumps around”. Highly scalable? My database is highly scalable. My web site is highly scalable. My team is… people. We don’t scale. The point of the word is not just to indicate growth, but to indicate the flexibility of operating at any size. In this case, it sounds like the “highly scalable team” would have to also be happy with lining up for a dole cheque if the “team” can’t hit their presumably unreachable deadline.

Now that I’ve spent this time being a complete dickhead, here’s some advice so you don’t start Mondays with arseholes like me (and maybe actually get useful candidates):

1) Don’t use the mass-mailer. If you do, and LinkedIn is sending garbage to people like me, complain to LinkedIn. They make their money from you, not me. You will have the added bonus of being able to filter out shitty candidates, or people who ARE NOT candidates (i.e. me)

2) Don’t pretend to be contacting me directly if you aren’t. Specifically, don’t pretend to be /writing/ to me if you aren’t. I can tell that shit was copy/pasted from Word. Speaking from a programmer’s perspective, they want to be taken seriously. They also have a rainman-esque ability to notice things you probably ignore. Shitty, insincere emails is a double-whammy.

The job:
1) If you’re going to piss all over people’s bullshit-radars, at least give some indication as to who the company is. Noone cares about “largest manufacturer of devon” unless they can say “largest manufacturer of devon in Europe“. Also, the fact that this claim could be made with an apparent disregard for the market is a slap in the face to all the contributors to the free services currently out there. Poor (or lazy) research is not winning you candidates.

2) If a brief came in to me from some manager at LargestEducatorOnline that read “find me someone to code the largest Drupal site ever, but only give them 120k, plus highly scalable web 2.0 buzzword pancakes”, I would probably stop for a second. Mostly to laugh, but also to check why they think a senior manager running a massive “highly scalable offshore team” deserves only 120k. This screams all types of “I don’t know what the fuck I want”. Noone wants an unexpected surprise from their workplace, especially if it’s “yeah your ‘team’ is actually the array of bendy straws we have in the kitchen. Welcome aboard”. Find out what they want. Tell your candidates exactly that. Holy hot damn – results!

3, 4) I don’t care what type of world we live in. You can’t successfully merge eCommerce and eLearning. The best platforms for learning are currently FREE, and are built on the foundation that “knowledge is free”. Contributors love the idea of teaching, and students love the idea of learning. Trying to screw people out of a few bucks for the (dis)pleasure of a shitty online learning platform is not the way to make friends. My point here is pretty much the same as the above. Learn what your client wants and pass on as many un-wanked details as possible.

Basically, no, I’m not interested in this position. You’ve breached my trust from the outset using LinkedIn’s cruddy mass-mail tool (thus ignoring my messaging requests), not to mention the job description from the company you’re representing is terrible, either because the brief was heinously poor (their fault), or horribly misrepresented (your fault). Everything about this job screams ‘ridiculous’ at best, and ‘scam’ at worst.

Best regards and apologies,
neill

“That is not a meme” – A PSA

Being simultaneously a fan of Richard Dawkins and a fan of talking trash on the internet, it pains me to see people using the word “meme” as if it were the latest Web 2.0 technology.

Here’s a history lesson (from the Wikipedia article) if your only exposure to the word comes from the internet:

Memetics is a controversial theory of mental content based on an analogy with Darwinian evolution, originating from the popularization of Richard Dawkins’ 1976 book The Selfish Gene. It purports to be an approach to evolutionary models of cultural information transfer.

The meme, analogous to a gene, was conceived as a “unit of culture” (an idea, belief, pattern of behaviour, etc.) which is “hosted” in one or more individual minds, and which can reproduce itself, thereby jumping from mind to mind. Thus what would otherwise be regarded as one individual influencing another to adopt a belief is seen [...] as an idea-replicator reproducing itself in a new host. As with genetics, particularly under a Dawkinsian interpretation, a meme’s success may be due to its contribution to the effectiveness of its host.

Put more simply, an idea passes from person to person in a similar fashion to the way that genes (combinations within your DNA) pass from person to person.

Why does this bother me, then? Well, I think you’ve probably seen something like this:

This is a meme. Specifically, the use of Fry’s face with the text “Not sure if…” is the meme. What people normally call a meme is actually the image macro style. Annoyingly, this mistake is taking over (and, I guess, becoming a meme in and of itself. Meta.)

Here’s a list of things that are not memes:

  • Random, shitty photos with random, shitty captions
  • You

So remember, when you hear someone say “I made this cool meme”, you can be assured that they are almost certainly wrong.