Flarnie Marchán

Hello! I'm a software engineer with a passion for the web.

WordPress Post Transition Status Examples

Published Fri Nov 16 2012 00:00:00 GMT-0800 (PST)
If your WordPress plugin or theme has special functionality that is triggered by the "publishing" or other change to a page or post, then you will be using the transition_post_status hook. I had to experiment quite a bit with this hook to determine the keywords actually used for $new_status and $old_status, and now I'm sharing the complete list of my findings. Read on for a reference guide on what specific post transitions are called when any type of action is taken within the WordPress Admin. (Tested as of WordPress version 3.1) In most cases, two separate transitions were triggered by one action, and in that case the first and second status keywords are separated by a line ( | ). This pattern seems to hold for both 'pages' and 'posts', BUT custom post types don't get the 'new' and 'inherit' status emitted on each change like the others.
Action Taken Old Status New Status
Create new post new auto-draft
Wrote something in the new post auto-draft draft
Waited (autosave ran) draft draft
Saved draft new | draft inherit | draft
Saved and published for first time new | draft inherit | publish
Updated published post new | publish inherit | publish
Scheduled post for future publish new | draft inherit | future
Changed scheduled post to private new | future inherit | private
Set private future-post to new future-publish date new | private inherit | private
Sent regular, published post to trash new | publish inherit | trash
Permanently deleted post from trash (Nothing) (Nothing)
Sent privately scheduled post to trash new | private inherit | trash
Restored privately scheduled post from trash new | trash inherit | private
Restored regularly published post from trash new | trash inherit | publish
Made private scheduled post public new | private inherit | publish
Let the scheduled post reach it's publication time future publish
It seems like there should be an easier way to hook into specific types of post transitions. I wanted to trigger certain updates whenever a post was made public, and for that I need to separately hook into all of the following transitions: draft-to-publish, auto-draft-to-publish, private-to-publish, future-to-publish, trash-to-publish, etc. Anyway, I hope that this is helpful!