
If you’re running a multi-authored blog, it can be very cool to let your contributors know when their post are online. Today’s recipe will show you how to do this automatically each time a post is published.

If you’re running a multi-authored blog, it can be very cool to let your contributors know when their post are online. Today’s recipe will show you how to do this automatically each time a post is published.
Nothing complicated with this recipe. Copy the code below and paste it on your functions.php file. Then save the file, and you're done!
function wpr_authorNotification($post_id) {
$post = get_post($post_id);
$author = get_userdata($post->post_author);
$message = "
Hi ".$author->display_name.",
Your post, ".$post->post_title." has just been published. Well done!
";
wp_mail($author->user_email, "Your article is online", $message);
}
add_action('publish_post', 'wpr_authorNotification');
Thanks to Daniel Pataki for the great piece of code!
7 Responses
Interesting
Can you trigger the function when a post i updated too?
I don’t think there is a need for the
global $wpdb;.Yeah, I think “global $wpdb” doesn’t need for this recipe
I was going to say the same thing about globalizing the db class. Also, the name of the function does not match the callback. (authorNotification != wpr_authorNotification)
Also, you are prefixing the function with wpr_ but you forgot to add that prefix in the action you’re adding to publish_post
ooops, thank you guys! Post have been updated.
Hmmm…
I think publish_post has deprecated for now
Trackbacks: