Post status ‘transition_post_status’ hook firing twice (status dropdown)
-
Hi there,
Thanks for releasing this plugin.
I’ve created a workflow that includes “Draft”, “Pending Review” and “Approved” in the Main Workflow, and “Needs Work” and “Rejected” in the Alternate Workflow.
When I create a new post and use the “Status” dropdown field in the right sidebar of the post edit screen, it seems that the
transition_post_status
fires as soon as the dropdown is updated, even though the post has not yet been saved/updated, which updates the post’s status to the one that has just been selected. The hook then fires again immediately after to update the status back to the post’s original status. This is causing notifications to fire when they shouldn’t be.I found the
notification_status_change
function and added error logs to allow me to see the hook firing twice.Example flow:
- As an Author, create a new post and using the Workflow submit for review. The post status is updated to
pending
. - As an Editor, “review” the post and use the right sidebar “Status” dropdown to select “Needs Work” status – note we haven’t saved the post yet, only selected the Needs Work status from the dropdown.
- The
transition_post_status
hook will have just fired twice:- Once to update the post status from
pending
toneeds-work
– this causes the notification to the Author to be sent informing them their post needs work. - The again immediately after the above to update the post status from
needs-work
back topending
– this causes the notification to the Editor to be sent informing them the post has been re-submitted for review, which is not yet true.
- Once to update the post status from
Hope this is helpful – thanks in advance.
Tom
- As an Author, create a new post and using the Workflow submit for review. The post status is updated to
- You must be logged in to reply to this topic.