0

I have successfully setup an action that executes when a custom post type is moved from "pending" to "publish" status. Everything works as expected when you change the post status individually (press the "Publish" button on the individual post edit page).

However, when using the Bulk Actions on the overview page for the custom post type, the items successfully move from pending to published, but the code below does not get executed.

How can a make sure this code is executed, even if the status is changed via a Bulk Update?

function bang30_publish_pending_response( $new_status, $old_status, $post )
{
  // Check if we are transitioning from pending to publish
  if ( $old_status == 'pending'  &&  $new_status == 'publish' ) {

    // thank you email to the user.
    $email = 'demo@example.com';
    $first_name = 'John';
    $last_name = 'Doe';
    $to = $first_name . ' ' . $last_name . '<' . $email . '>';
    $subject = 'Thanks for your submission to CanLand!';
    $message = 'Your submission to canland.org has been published.
    You can now view it online and share what you created with your friends:
    ' . get_permalink($post);

    wp_mail($to,$subject,$message);

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

EDIT:

nevermind - my issued turned out to be with how to use the $post object correctly.

Both transition_post_status and pending_to_publish are working for this curcumstance.

1

Change your action to pending_to_publish.

add_action(  'pending_to_publish', 'bang30_publish_pending_response', 10, 3 );
  • I tried that too - same result. – squarecandy Jul 27 '17 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.