Post Status Transitions

2007 September 5
by Ryan

WordPress 2.3 introduces some new actions that plugins can use to hook into status transitions and workflow. Before, WP had a ‘private_to_published’ action that announced that a post moved from private to published, and that’s about it. Now WP has actions for every possible transition. These actions are of the form ’status_to_status’ where status is one of:

  • publish
  • draft
  • private
  • future
  • pending

When a ‘pending’ post is published, the action ‘pending_to_publish’ is triggered. The action is accompanied by the post object that is changing status.

A generic ‘transition_post_status’ action is also emitted for every status change. It is accompanied by the new status, the old status, and the post object. Plugins can use this action to attach a function that intercepts all status changes.

The final action triggered during a status change is of the form ’status_object’, where status is from the status list above and object is either ‘page’ or ‘post’. For example, when a post is published, a ‘publish_post’ action is triggered. The action is accompanied by the post ID and post object.

See the function wp_transition_post_status() for how these actions are formed. Use add_action() to attach functions to these actions.

10 Responses
  1. 2007 September 5

    I’m growing more and more scared of having to upgrade WordPress to 2.3.x now because I have so many dependents on how the database structure is currently setup.

    will legacy code be supported at all for the old database structure?

  2. 2007 September 5

    If you do direct SQL queries that involve the categories, post2cat, or link2cat tables, things will break. If you use API you are safe.

  3. 2007 September 5

    Hmm alright. I do a few direct queries, I’ll just need to review them before I make any upgrades to my sites. Thanks Ryan.

  4. 2007 September 5

    My concern is that additions to the database schema mean more queries, which in turn, will mean worse performance for those on shared mysql hosting environments. A few thousand entries, and database actions are already very sluggish when compared to a fresh blog on the same machine.

  5. 2007 September 9

    I share the same concern with Flexo. My seo site is running on a shared hosting environment and even on WP 2.2, I am almost using the maximum cpu usage (4%).

Trackbacks & Pingbacks

  1. WordPress Wednesday News: International WordCamps, WordPress 2.3, Theme Viewer Working, WordPress.com Banned, and More News : The Blog Herald
  2. Every Flavour Beans » What is New in Wordpress 2.3 (Beta 1)?
  3. WordPress 2.3 Beta And Why You Shouldn’t Use It …. Yet | Web 2.0 How-To Spot-er
  4. Mr. Awesome » Blog Archive » Beware the next WordPress version 2.3 release… | My Life, My Code, My Awesomeness
  5. Vindictive Bastard » Beware the next WordPress version 2.3 release… | Welcome to the land of shut the fuck up and just listen!

Comments are closed for this entry.