[wp-trac] [WordPress Trac] #53418: Post Status Transition missing Hook

WordPress Trac noreply at wordpress.org
Tue Jun 15 23:42:17 UTC 2021


#53418: Post Status Transition missing Hook
-------------------------+-------------------------------------------------
 Reporter:  brettrans    |      Owner:  (none)
     Type:  defect       |     Status:  new
  (bug)                  |
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Posts, Post  |    Version:  5.7.2
  Types                  |   Keywords:  needs-patch needs-testing has-dev-
 Severity:  blocker      |  note dev-feedback
  Focuses:               |
-------------------------+-------------------------------------------------
 REF: https://codex.wordpress.org/Post_Status_Transitions

 So I have been testing this and found there is an issue creating the post
 type **new to pending**:

 {{{#!php
 <?php
 // Sends a notification when a new Event type post is created from New to
 Pending.
 function on_new_pending_post( $post ) {
         // A function to perform when a pending post is published.
         // Send an email:
 }
 add_action(  'new_to_pending',  'on_new_pending_post', 10, 1 );
 }}}


 This code above will run on both status changes from **new to draft** and
 **new to pending**

 we have a form in which people submit new posts, these posts can be saved
 as a draft before being saved to pending status. We need to send an email
 when a status is changed from **new to pending** and **draft to pending**
 however we don't want an email to send from **new to draft** but using the
 above code hook will still send an email

 We have attempted to use

 {{{#!php
 <?php
 function post_new_pending( $new_status, $old_status, $post ) {
     if ( $old_status == 'new'  &&  $new_status != 'pending' ) {
         // A function to perform actions when a post status changes from
 publish to any non-public status.
 // send email
                 }
     }
 }
 add_action( 'transition_post_status', 'post_new_pending', 10, 3 );
 }}}


 have tried with the $old_status set to empty or set to 'new' but this
 doesn't fire our code off.

 we can simulate the status change from draft to pending correctly using

 {{{#!php
 <?php
 function post_draft_pending( $new_status, $old_status, $post ) {
     if ( $old_status == 'draft'  &&  $new_status != 'pending' ) {
         // A function to perform actions when a post status changes from
 publish to any non-public status.

                 }
     }
 }
 add_action( 'transition_post_status', 'post_draft_pending', 10, 3 );
 }}}


 There doesn't seem to be a way to using **new to pending** even when using
 the hook new_to_pending it will also effect new to draft status changes.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53418>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list