Send Email To Wordpress Author On Post Publish

Here is a great Wordpress snippet for multi author blogs. This will automatically send an email to the author of the post once it has been published. It uses the Wordpress action of publish_post which runs after the post has been published. All you have to do is add the following into your functions.php page.


function 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 at ".get_permalink( $post_id ).". Well done!
   ";
   wp_mail($author->user_email, "Your article is online", $message);
}
add_action('publish_post', 'authorNotification');

Source: WordPress Essentials: The Definitive Guide To WordPress Hooks

Written on

UpChecker

Reliable uptime monitoring and instant alerts for any website downtime.

  • Uptime Monitoring
  • Performance Monitoring
  • SSL Certificate Alerts
  • Domain Monitoring
  • DNS Checker
  • XML Sitemap Monitoring