Lessons Learned

I learned a few things this week.

1. I learned that php 7 allows type hinting for basic variable types, and for return type hinting.

“So, what’s type hinting?” you ask. “And why is this a big deal?”

Type Hinting is being able to tell what kind of variable you expect when you activate (call) a bit of code. Variables come in lots of types: there are numbers, strings of letters and other characters, yes/no bits (called boolians, arrays, and on it goes.

A common kind of error happens when your code is expecting one kind of data (maybe you need a number, because you want to know how many units you’ve sold), but the wrong kind of data gets passed in (maybe the word “units”). Everything breaks down, because you can’t multiply the word “units” by a price to get a total. Type hinting allows you to say right off the bat if you’ve got the kind of information you need to do what you need to do. If you specify you need a number and you don’t get a number, you know right away, rather than when something unexpected happens down the line.

Up to now (well, a year ago when php7 was released) you could only specify complex data types, but you couldn’t say for numbers and strings. And, type hinting the returned output allows you to know right away if you didn’t get back the kind of data you expected, too.

So , yeah, this is a big geek deal.

2. I learned a few new things about php strings. String padding.

I guess I just never had any reason to go there before. Maybe I did, I don’t know.

String padding is handy when you need to have a string of characters that is exactly so many characters long. Say you need an invoice number and it always has to have 12 characters in it. So your first few invoices are a few characters short of 12. Say it’s invoice ARZ–13579. That’s 9 characters. So you can pad that out with spaces in the front by just specifying you need it to be 12 characters and add spaces to the left. All fixed!

3. I learned some JavaScript that allows storing data in the browser.

Yeah, again pretty basic for JavaScript junkies. But very cool. Store stuff in the browser, then have it handy to use on another page later on.

I probably learned a few other things this week, too. But those are the ones that stand out. Now you know a little bit about them too. Congratulations!

iCaspar Analytics Plugin, Version 1.0.1

Google Analytics Tracking ID in General Settings

The thing with writing plugins, or any software, is that once you’ve got the project started things take on a life of their own.

So after yesterday’s little plugin write-up I got to thinking. Having a spot to enter an analytics tracking ID in the customizer is fine. But, really, the customizer is for theme and presentation stuff. What if out there in the world somewhere a theme re-arranges the customizer. That panel might not be available.

The other place to put a setting is on a page in the WordPress admin area. Lots of plugins do this, adding their own settings page. But there’s no use creating a whole new page for one setting. So, I thought, let’s just add it to the general settings page that’s already there?

It didn’t take too much to plop the field in there. So a day later, version 1.0.1. Does the same thing, but now you can add or update the site tracking ID from either place.

Download from Github.

A Minimalist Google Analytics WordPress Plugin

Google Analytics Tracking ID

When I turned off Jetpack, one of the bits I lost was website statistics.

Not a problem. Google Analytics is a great web statistics solution. And it’s free. I’ve had a Google Analytics account all along. I’ve just been too lazy to bother with it.

In the spirit of keeping things lean and clean, I sat down to write my own quick WordPress plugin to pop the analytics tracking script onto my sites.

The result is a new field in the WordPress customizer’s default Site Identity panel where I can enter the site’s tracking ID. Just enter, save, and voila! Site stats!

Interested? Feel free to grab the code.

Turning Off Jetpack

So, yeah. Up until a couple weeks ago, I used a WordPress plugin called Jetpack on this and several other sites.

Jetpack is a popular plugin, a whole suite of plugins, really. Everything from a markdown editor, to backups, to added gallery sliders, to infinite scrolling, to site statistics. It’s popular because it’s useful in so many ways. And it’s built and maintained by Automattic, one of the biggest players in the WordPress world. So it’s solid.

Over the past couple years, though, it’s come to the point where it’s just grown too big. I just don’t need most of the things. Besides the statistics (which I can get from Google Analytics) and the markdown editor (which I can get by without easily enough) I just wasn’t using very much of it. The social sharing buttons were also handy, but I have a calendar plugin that takes care of that now, too. The minimalist in me started agitating for trimming down.

Mostly, I don’t miss it at all. And, truth be told, the couple of things I do miss, will likely goad me toward writing my own plugins to do those few things, and maybe some others besides.

I’m not saying anyone should turn off Jetpack. If you’re a Jetpack user and its working for you, by all means carry on. But every once in a while, it’s worth taking a hard look at what you’re really using, and whether it comes with a lot of extra baggage. So it goes for websites and a lot of other things in life, too.

Bells and whistles are nice. Lean and clean are better.


Star Wars Battlefront cover art

I made a deal with my kid the other day.

He wanted to get the Star Wars BattleFront game for the PS4. I wanted him to do something other than play games every waking moment.

The deal was he had to come up with a video that shared something he knew that would be helpful to someone else. It could be any topic he wanted, but it had to be informational and useful in some way. He had to come up with the topic, decide how to present it and record it.

He has a YouTube channel with over 500 subscribers. When the video was made and uploaded, he could download the game.

And, he gets 1 hour of game time per day. If he wants screens, he can produce more videos.

It took him one day to do the video. It was a 15 minute how-to for recording a gameplay video with a picture-in-picture effect. It gets more hits than this blog.

Pretty good deal, I think.