Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#8792 closed enhancement (fixed)

Transitions should be called even if the status hasn't changed

Reported by: nbachiyski Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.7
Component: General Keywords: has-patch tested commit
Focuses: Cc:


I wanted to be able to differentiate newly published posts and published posts, which are re-saved. The current transitions hooks offer either:

  • publish_post hook, which is called for all saves of published posts


  • oldstatus_to_publish hook, which is called only if the status has changed.

Thus, there is no way to hook to the case, in which the status hasn't changed.

The logical solution for me is to make all the hooks in wp_transition_post_status() to be called even if the status hasn't changed. It shouldn't cause any compatibility problems, so here is a patch.

Attachments (1)

transitions-to-same-status.diff (1.6 KB) - added by nbachiyski 12 years ago.

Download all attachments as: .zip

Change History (8)

#1 @azaozz
12 years ago

  • Type changed from defect (bug) to enhancement

Wouldn't it be easier/safer to include the $old_status in the publish_post hook:

do_action("${new_status}_$post->post_type", $post->ID, $post, $old_status); 

There may be plugins that depend on the other actions being called only when a transitions occurs/post_status changes.

#2 follow-up: @jacobsantos
12 years ago

Yeah, you'll probably want to look at Subscribe2 plugin and test with that.

#3 in reply to: ↑ 2 @nbachiyski
12 years ago

Replying to jacobsantos:

Yeah, you'll probably want to look at Subscribe2 plugin and test with that.

It doesn't use transition_post_status, it lists all types in xxx_to_publish hooks.

The change isn't big and if we include in the plugin upgrade docs it won't cause any trouble. I like it a lot better than introducing a new hook or just adding the old status to the common hook, because it will be a lot more generic and more cases can be handled with less code.

#4 @Denis-de-Bernardy
12 years ago

imo, this is going to break a lot of plugins and introduce multitudes of workflow issues.

why not hook into save_post and check if status is published?

#5 @Denis-de-Bernardy
12 years ago

mm, nevermind that. patch does the right thing.

#6 @Denis-de-Bernardy
12 years ago

  • Keywords tested commit added

#7 @ryan
12 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [11197]) Always do post status transition actions. Props nbachiyski. fixes #8792

Note: See TracTickets for help on using tickets.