I am using a custom function with ‘publish_post’ hook for a notification to the author when the post has been published but the issue I am facing right now is that the notification is being sent out twice and as well when the post is updated. Here is how my function looks.
function authorNotification($post_id) {
$post = get_post($post_id);
$author = get_userdata($post->post_author);
$message = "
Hi ".$author->display_name.",
New post, ".$post->post_title." has just been published at ".get_permalink( $post_id ).".
";
wp_mail($author->user_email, "New Post Published", $message);
}
add_action('publish_post', 'authorNotification');
am I missing something here?
You need to write your hook for
transition_post_status
action: