Advertisement
Aurangajeb

Notify post author once a new post is published

Jun 28th, 2020
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.55 KB | None | 0 0
  1. /** Notify post author once a new post is published **/
  2.  
  3. function notify_author($post_id) {
  4.  
  5. $post = get_post($post_id);
  6. $author = get_userdata($post->post_author);
  7. $subject = "A new Post Published: ".$post->post_title."";
  8.  
  9. $message = "
  10.      Hi ".$author->display_name.",
  11.      
  12.      Your post, \"".$post->post_title."\" has just been published.
  13.      
  14.      View post: ".get_permalink( $post_id )."
  15.      
  16.      Thanks"
  17.       ;
  18.        
  19.    wp_mail($author->user_email, $subject, $message);
  20. }
  21. add_action('publish_post', 'notify_author');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement