Oldest son pads the resume: Babysitter

My twelve-year-old son recently took a local community education course that taught him the finer points of babysitting. The course was over six hours in length, probably got him out of his comfort zone in a non-sport environment and he now can administer some level of first aid.

Babysitter’s Training has been developed by the American Red Cross with input from youth just like you. The course is fun and fast-paced with hands-on activities, exciting video, role-plays and lively discussions. You’ll learn to be the best babysitter on the block. Plus, you’ll gain the confidence to make smart decisions and stay safe in any babysitting situation. Bring lunch and babydoll.

Sounds good to me.

Naturally, he came home eager to put his new found skills to use! My wife started networking on his behalf, letting a few families know that he recently completed a course and was available to entertain their kids. One family already took the bait and started doing their due diligence.

My son’s response to the “How much do you charge per hour?” question has caused my wife and I, albeit silently, to have a good laugh. He is thinking that five dollars/hour is a fair wage for being a babysitter. My wife and I have never had to pay a babysitter in the last twelve years. We have been very lucky to have my mom close and available, so we don’t actually know if five dollars/hour is the going rate but we can only guess that it’s not.

I think we’re going to let him learn on his own what his time is worth. He’s happy. So we’re happy.

WordPress function leads to endless fun

Came across a fun one today. A person in the WordPress.org Support Forums wanted a function that would set a post status to Private if the post was assigned to a certain category. My approach was to prevent future posts from not missing out on the opportunity to set the status and does not really address posts that are already in the database.

To start things off, I wandered over to the WordPress Codex for the wp_update_post function and adapted the example listed.

function post_saved_set_to_private ( $post_id ) {
if ( in_category( 'switcheroo' )) {
	// Update post with the following
	  $my_post = array( 'ID' => $post_id, 'post_status' => 'private' );

	// Update the post into the database
	  wp_update_post( $my_post );

	}
}
add_action('save_post', 'post_saved_set_to_private');

Talk about easy! I tossed this function into my theme’s functions.php file so I could try things out on my localhost installation. I was going to be the original poster’s savior.

I tried creating a regular post in a random category. Success! Now the real test — add a new post in the switcheroo category. Hit Publish. Why is it taking so long? What’s the deal? I’m dead in the water. Nothing is happening. This can’t be good. I opened up a new tab to my Dashboard and jumped into All Posts. 900+ new posts set to Private! Hey, that’s not right! So while I set to work on deleting those posts (200 at a time), I began to think about what had happened and I figured it must have something to do with post revisions.

Indeed. Now here’s the good part. If I had only scrolled down the wp_update_post Codex page just a little more, I would have avoided the problem I had created.

===Caution – Infinite loop===
When executed by an action hooked into save_post (e.g. a custom metabox), wp_update_post() has the potential to create an infinite loop. This happens because (1) wp_update_post() results in save_post being fired and (2) save_post is called twice when revisions are enabled (first when creating the revision, then when updating the original post—resulting in the creation of endless revisions).

If you must update a post from code called by save_post, make sure to verify the post_type is not set to 'revision' and that the $post object does indeed need to be updated.

function my_function( $post_id ) {
	if ( ! wp_is_post_revision( $post_id ) ) {
	
		// unhook this function so it doesn't loop infinitely
		remove_action('save_post', 'my_function');
	
		// update the post, which calls save_post again
		wp_update_post( $my_args );

		// re-hook this function
		add_action('save_post', 'my_function');
	}
}
add_action('save_post', 'my_function');

In the example above, you see a check to make sure that the post is not a revision. If that passes, the function then removes the action, does the update and then adds action back again. This is how you avoid an infinite loop and finding out you have 900+ posts that you didn’t want at all.

Armed with new information, I updated my original function to include the crucial part about avoiding an infinite loop and came up with the following function.

function post_saved_set_to_private ( $post_id ) {
	if ( ! wp_is_post_revision( $post_id ) ) {

		// unhook this function so it doesn't loop infinitely
		remove_action('save_post', 'post_saved_set_to_private');

		if ( in_category( 'switcheroo' )) {
			// Update post
		    $my_post = array( 'ID' => $post_id, 'post_status' => 'private' );

			// Update the post into the database
			wp_update_post( $my_post );
		}

		// re-hook this function
		add_action('save_post', 'post_saved_set_to_private');
	}
}
add_action('save_post', 'post_saved_set_to_private');

I believe I got the function working and learned a little something along the way.

Apple TV, AirPlay and the Harman Kardon Aura Wireless Speaker System

My family has been pretty happy with the addition of our Harman Kardon Aura Wireless Speaker. The setup was pretty easy and the HK Remote iOS app is fairly straight-forward to use.

The sound quality has been a huge improvement over the television or the iMac speakers. AirPlay compatibility was a huge selling point for us. We can send music from our iOS devices and other Apple computers quite easily.

Our only gripe is when the Apple TV occasionally loses its connection with the speaker and defaults back to the television. We have the television on mute and when it flips like that, we need to switch it back in the Apple TV’s AirPlay settings.

It could be more of an issue with my second generation Apple TV. When the fourth generation Apple TV comes out, hopefully in June at WWDC, I’ll get the new model and perhaps solve my issue of losing the speaker.

I’m not an audiophile but the sound coming from the speaker sounds great to me.

schulte.mn is back again, too.

There was a time where I was running a self-hosted blog on schulte.mn, but I found that I just didn’t write enough to continue to pay for hosting.

As I mentioned before, I used to have the schulte.mn domain running a WordPress installation. My hosting company, TextDrive, moved me over to Joyent and then back again to a TextDrive after some sort of rebirth. I admit that I didn’t keep up with all gory details regarding my hosting. I think the second incarnation of TextDrive slipped off quietly into the night and along with it, my old posts and site. I wasn’t super invested in my old content. C’est la vie! I had to look that up. I did try to jump back into the fray with Linode a few years later, but even then, it was more than I needed for a simple blog. I’m sure their services are great — it just wasn’t a good fit for me.

Eventually, I just started to redirect schulte.mn over to Twitter. Twitter is something I actually use and it seemed like a logical move on my part.

I got back in the blogging game on May 7th with WordPress.com and decided just the other day to reestablish schulte.mn again. WordPress.com makes it so simple to map a domain. Seriously. $13/year is all that it will cost me for the service. Very reasonable. Did I mention easy? It was!

The worst part of the whole process is waiting for the DNS propagation to complete. The changes eventually completed in less than 24 hours but it seemed like an eternity when everything else went so smoothly.

Not only can I say, I’m back, but schulte.mn is back, too.