CSS text-transform can’t do “sentence case” but there’s a really simple alternative

Need to capitalize just the first letter of a text string? CSS text-transform has capitalize but that capitalizes every word.

Fortunately, you can use the ::first-letter pseudo element! In my case, I wanted all of the links in my navigation to definitely start with a capital letter, so I went with this:

#primary_navigation a::first-letter {
  text-transform: uppercase;
}

Slick!

Get rid of that annoying “WebSocket connection to ‘…’ failed” error on WordPress sites running Jetpack

If you run a self-hosted WordPress site with Jetpack, installed, you may have noticed a frequent error message showing up in your browser console.

In Chrome it looks like this:

WebSocket connection to ‘wss://public-api.wordpress.com/pinghub/wpcom/me/newest-note-data’ failed: Error during WebSocket handshake: Unexpected response code: 403

In Safari it’s slightly less specific, but the issue is the same:

WebSocket connection to ‘wss://public-api.wordpress.com/pinghub/wpcom/me/newest-note-data’ failed: Unexpected response code: 403

This issue has been reported various places online but nowhere do I find a true fix.

As indicated in some of those support threads I linked to above, it’s due to an issue with the Notifications module in Jetpack. What? It’s something I was not even really aware of and that can be extremely easy to ignore, especially if your site is not blog-focused or does not have active commenting. Turns out Jetpack has this little “Notifications” icon up in the admin bar next to your Gravatar, where you can get the latest updates on what’s happening on your blog.

If you’re like me, you don’t need or want the Notifications tool. And if getting rid of it gets rid of that stupid error that’s constantly popping up in the console, all the better.

Side note: Did you know there’s a hidden page where you can access the settings for a ton of Jetpack modules? (Neither did I.) Just go to /wp-admin/admin.php?page=jetpack_modules in your WP admin and there it is! If you’re just dealing with this issue on one particular site, and don’t want to write any code, simply deactivate the Notifications module here and you’re done. If this is something you are dealing with on many sites though and you want an automatic, code-based solution to stick into your base theme, read on…

I tried using Jetpack’s instructions for disabling a module via code. (Fun fact, the name for this module in the code is not 'notifications' as you might expect; it’s 'notes'.) Frustratingly, neither the 'option_jetpack_active_modules' filter nor the 'jetpack_get_available_modules' filter worked. I even scoured the Jetpack source code for other filters I might need to use, and none of them made a difference.

Oh, I was able to get 'notes' not to appear in the array those filters returns, and I was even able to use that to get “Notifications” to always appear as “inactive” on that hidden settings page.

But the error kept showing up in the console, and the little Notifications icon was still in the admin bar. The module was not inactive.

Finally, through further source code poking, I discovered there’s a static public method called Jetpack::deactivate_module(). I tried running it in those aforementioned filters but it resulted in an HTTP 500 error. (Strangely, it was an out-of-memory error. Shrug.)

So I decided to try the method in different actions. After some trial and error, it seems the 'init' action works. But that’s a bit of overkill, running this code on every front end page load, especially since once the module is deactivated, it should stay deactivated, so my solution is to run it on the 'admin_init' action instead. Especially since this issue only happens for logged-in users anyway, it should be adequate.

Here’s a bit of code you can stick into your theme’s functions.php file or wherever you like to put things like this:

add_action('admin_init', 'rm34_jetpack_deactivate_modules');
function rm34_jetpack_deactivate_modules() {
    if (class_exists('Jetpack') && Jetpack::is_module_active('notes')) {
        Jetpack::deactivate_module('notes');
    }
}

A justification for Barack Obama’s “infomercial” airing tonight

Tonight a 30-minute paid program, i.e. infomercial, will air on 3 major networks plus some Spanish-language networks and cable channels, paid for by the Obama campaign. I don’t know the content of the program yet, but I assume I’ll be watching it.

I’ve been reading some comments on news stories anticipating the “television event.” Many supporters rooting him on, the usual right-wing tirades, and a few legitimate arguments from McCain supporters challenging the idea that this was a prudent use of money as we’re plunging into a global economic crisis.

Legitimate, but misguided, I think. Sure, it would be great if the $5-7 million (my estimate) he’s spending on this could be used for more urgent matters, but it’s wrong to criticize Obama for using this money in this manner at this time. It’s campaign money, donated by supporters, with the objective and expressed intent that the money be used in the campaign to get Obama elected president. In other words, he has to spend this money, and he has to spend it on his presidential bid. It’s not like he can just say, “OK, we’ve been given more money than we need. Let’s just put the surplus into paying down the national debt” or something similar (and equally futile). The money was not given to him for that purpose, and aside from disappointing and/or angering the donors, I’m pretty sure any other use of the money would be illegal. I don’t really know what happens after an election if a campaign has a surplus of funds, but it would be foolish for a campaign not to spend money it has during the campaign season, if it finds a suitable use for the money.

Which brings me back to the matter of wasting campaign money. Sure, the mailers and robocalls and emails SLP and I received over the last month from the McCain campaign were a drop in the bucket compared to 30 minutes of national prime-time airtime, but the latter is also a drop in the bucket compared to the $700 billion bank bailout, or the $10 trillion (or whatever incomprehensible number it is now) national debt. My point is, Obama’s money isn’t being wasted on a nationally televised program that gives the country a chance to see who he is and why they should (or should not, but really they should) vote for him. The money the McCain campaign spent trying to woo members of my household was absolutely wasted and even the most minimal amount of research could have verified for the campaign that our address had no business appearing on their mailing list.

As far as tonight’s programming goes, I don’t know if it’s ultimately a plus for the Obama campaign or not. It could backfire. But I don’t think it will. Any naysayer who isn’t just vehemently, fundamentally opposed to Barack Obama could be persuaded, I think, if they just give him a chance and listen to what he has to say.

If you happen to be online during the telecast, be sure to check out the live blog on SIDEDOWN.