The publish_post hook

The publish_post hook is one I’ve seen a lot in tutorials and such. Even has its own page in the codex.

But surprise! That hook doesn’t actually exist, at least not if you search for do_action\(\s?.publish_post.

When I was learning to dig into core, this baffled me. What was this publish_post sorcery? Why wouldn’t it work on my custom post types???

Here’s a secret: The actual hook in core looks like this "{$new_status}_{$post->post_type}". It’s part of a small function in wp-includes/post.php (line 3321 at the time of writing), and there’s another equally useful variable hook right before it.

function wp_transition_post_status($new_status, $old_status, $post) {
	do_action('transition_post_status', $new_status, $old_status, $post);
	do_action("{$old_status}_to_{$new_status}", $post);
	do_action("{$new_status}_{$post->post_type}", $post->ID, $post);

There are quite a few of these variable hooks in core, I encourage you to go look at them, here’s a list I scraped together:


Stronger than dirt… I mean Ajax

I first learned about Ajax at a WordCamp (yay!), but I didn’t fully grasp how to implement it. There was a helper script provided, and I figured out how to make it work for my plugins, but all I really knew was copy & paste.

It was at least a good 6 months before I dug in and looked at the WordPress Ajax API. Getting a closer look helped me understand what I was writing, and how I could simplify and/or make improvements when necessary.

So let’s start.


Screencast: Coding a plugin, start to finish*

This screencast is an experiment I wanted to try and if well-received, I may do more in this style.

This recording is in realtime, not sped up (I may do a timelapsed version in the future), so you can see what I’m doing. I try to narrate it to make it easier to follow, but sometimes the cat in the background throws me off.

Unedited. Exporting and uploading took long enough as it is, as my first screencast of this type, consider it a rough draft.

The final result of this screencast can be found here:

However, the goal of this isn’t so much for the code at the end as the how I got there. Feedback and questions welcome.

Props to @dougal for the plugin idea. It might not be exactly what was had in mind, but that’s beside the point 🙂

* I know, plugins are never really finished

WordPress Talk Ideas

Supposing I were to take the time to write up a talk on some WordPress subject (probably development related), and then supposing I were to actually give this talk in front of a group of people, what do you think it should be about?

I’m considering being prepared with a talk proposal for an upcoming WordCamp – but I need help with brainstorming. Please, please, please offer a recommendation in the comments, or hit me up on Twitter.

I can’t promise that I’ll actually end up giving a presentation – whether out of failure to submit a proposal or out of failure to bribe someone to accept mine – but I will choose a topic and make every effort to prepare a talk/tutorial/presentation and share it here on

My Favorite WordPress Resources

Really. There are a lot of WordPress resources out there, with fancy tutorials and snippets and thingamajigs, but 99% of my questions are answered in one of the above 2 sites.

Once I’ve got  piece of code working the way I want, I save it so I can refer to it later. I’m working on consolidating all my working code snippets, but for now they can be found on this site, or in github gists (as well as in some of my plugins). Some are still in the mu-plugins folder of my local development site, I’m working on getting those cleaned up and online.

Confirm Email Address

If you’re running a WordPress network, and depending on how you’re using it, you may need to get users to confirm or update their email address.

In my situation, I build a lot of sites for clients, and during development I use an email address of my own so they don’t get bombarded with emails they don’t need. But I don’t always change it back when I’m done, or maybe there’s a typo. Or maybe it’s the client that has changed their email address.

Whatever the cause, sometimes these things just need to be double-checked and confirmed. So here’s a small plugin that can be dropped in your mu-plugins folder: