Last active
July 5, 2018 04:43
-
-
Save dasbairagya/47f6f534469425bbd7dcf3bb73384950 to your computer and use it in GitHub Desktop.
SENDING OUT AN EMAIL WHEN A POST IS PUBLISHED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function post_published_notification( $ID, $post ) { | |
| $author = $post->post_author; /* Post author ID. */ | |
| $name = get_the_author_meta( 'display_name', $author ); | |
| $email = get_the_author_meta( 'user_email', $author ); | |
| $title = $post->post_title; | |
| $permalink = get_permalink( $ID ); | |
| $edit = get_edit_post_link( $ID, '' ); | |
| $to[] = sprintf( '%s <%s>', $name, $email ); | |
| /*$to = 'youremail@gmail.com';*/ | |
| $subject = sprintf( 'Published: %s', $title ); | |
| $message = sprintf ('Congratulations, %s! Your article “%s” has been published.' . "\n\n", $name, $title ); | |
| $message .= sprintf( 'View: %s', $permalink ); | |
| $headers[] = ''; | |
| wp_mail( $to, $subject, $message, $headers ); | |
| } | |
| add_action( 'publish_your-cpt', 'post_published_notification', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment