WordPress.org

Ready to get started?Download WordPress

Forums

Post Status Transitions and wp_mail (2 posts)

  1. Jacorre
    Member
    Posted 2 years ago #

    I wrote a small bit of code to send an email to the admin when a pending custom post type is submitted for review (pending status). It works fine.

    But when I try to notify the user that their post has been published (when the status changes from pending to publish) the email isn't generated for them? Is there anything wrong with the following:

    function notify_submitter() {
     global $post;
     $custom = get_post($post->ID);
     $author = get_userdata($custom->post_author);
     $author_email = $author->user_email;
     $message = "message here...";
     $headers = 'From: me <me@mydomain.com>' . "\r\n";
       wp_mail($author_email, "subject here...", $message, $headers);
    }
    add_action('pending_to_publish_[custom_post_type]', 'notify_submitter');
  2. Jacorre
    Member
    Posted 2 years ago #

    I did further testing with this and found that I believe it's an issue with post transitions with custom post types. If I use publish_[custom_post_type] it works fine, but I don't want follow up emails if I update the custom post type.

    So I want to use pending_to_publish_[custom_post_type] so that it only applies when the status transitions that one time. But unfortunately it's not working with the post transition. I also tried new_to_publish_[custom_post_type] and still doesn't work.

Topic Closed

This topic has been closed to new replies.

About this Topic