How can I run custom function when post status is changed?

See this Codex page. In general the hook is {old_status}_to_{new_status}. (Untested) but in your case, the hook would be pending_to_draft:

 add_action('pending_to_draft','wpse45803_pending_to_draft');
 function wpse45803_pending_to_draft($post){
  //Do something
 }

You might want to look up the wp_transition_post_status function. You could also use the hook: transition_post_status

 add_action('transition_post_status','wpse45803_transition_post_status',10,3);
 function wpse45803_transition_post_status($new_status,$old_status,$post){
  //Do something
 }

Leave a Comment