Last active
July 25, 2016 19:22
-
-
Save NateJLewis/acde91c95dee21861c9f7ca00943ed34 to your computer and use it in GitHub Desktop.
Send email notifications via wp_mail when a post is submitted (pending review) then notify the post author that the post has been 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 _pit_pending_post_status( $new_status, $old_status, $post ) { | |
$post_author_id = $post->post_author; | |
$post_author = get_the_author_meta( 'display_name', $post_author_id ); | |
$post_date = $post->post_date; | |
$post_title = $post->post_title; | |
if ( $new_status === 'pending' && $old_status !== 'pending' ) { | |
$headers[] = 'Content-Type: text/html; charset=UTF-8'; | |
$headers[] = 'From: PracticalIT <[email protected]>' . "\r\n"; | |
$admin_emails = array( | |
'[email protected]', | |
'[email protected]' | |
); | |
$subj = $post_title . ' is waiting review'; | |
$body = '<b>' . $post_title . '</b> post by <em>' . $post_author . '</em>, submitted on <b>' . $post_date .'</b> is waiting review.'; | |
wp_mail( $admin_emails, $subj, $body, $headers ); | |
} | |
} | |
add_action( 'transition_post_status', '_pit_pending_post_status', 10, 3 ); | |
function _pit_on_publish_pending_post( $post ) { | |
$headers[] = 'Content-Type: text/html; charset=UTF-8'; | |
$headers[] = 'From: PracticalIT <[email protected]>' . "\r\n"; | |
$post_date = $post->post_date; | |
$post_title = $post->post_title; | |
$post_author_id = $post->post_author; | |
$user_email = get_the_author_meta( 'user_email', $post_author_id ); | |
$subj = $post_title . 'has been approved'; | |
$body = 'Your post - <b>' . $post_title . '</b> submitted on <b>' . $post_date .'</b> has been approved.'; | |
wp_mail( $user_email, $subj, $body, $headers ); | |
} | |
add_action( 'pending_to_publish', '_pit_on_publish_pending_post', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment