Ticket #8792 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

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

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

Description

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

or

  • 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

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

Change History

  • 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.

comment:2 follow-up: ↓ 3   jacobsantos3 years ago

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

comment:3 in reply to: ↑ 2   nbachiyski3 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.

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?

mm, nevermind that. patch does the right thing.

  • Keywords tested commit added

comment:7   ryan3 years ago

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

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

Note: See TracTickets for help on using tickets.