Created
January 22, 2018 15:39
-
-
Save dibakarjana/31b778503a48c4d7c44c9f72328d22bf to your computer and use it in GitHub Desktop.
Wordpress: Send Email after any Post type status change
This file contains 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
//https://codex.wordpress.org/Post_Status_Transitions | |
//send email to admin after user create new deal from frontend form. | |
add_action('future_to_pending', 'send_emails_on_new_event'); | |
add_action('new_to_pending', 'send_emails_on_new_event'); | |
add_action('draft_to_pending', 'send_emails_on_new_event'); | |
add_action('auto-draft_to_pending', 'send_emails_on_new_event'); | |
add_action('pending_to_publish', 'send_emails_on_deal_publish'); | |
/** | |
* Send emails on event publication | |
* | |
* @param WP_Post $post | |
*/ | |
function send_emails_on_new_event($post) | |
{ | |
$emails = "[email protected]"; //If you want to send to site administrator, use $emails = get_option('admin_email'); | |
$title = wp_strip_all_tags(get_the_title($post->ID)); | |
$url = get_edit_post_link( $post->ID, $context ); | |
$message = "New Deal Created on Site Name!. Review and Publish. \n Link to post: \n{$url}"; | |
if(get_post_type($post->ID) === 'deal') //post, page, attachment or whatever other CPT you may have | |
{ | |
wp_mail($emails, "New Deal Created on Site Name: {$title}", $message); | |
} | |
} | |
function send_emails_on_deal_publish($post) | |
{ | |
$author_id=$post->post_author; | |
$emails = get_the_author_meta( 'user_email' , $author_id ); ; //If you want to send to site administrator, use $emails = get_option('admin_email'); | |
$title = wp_strip_all_tags(get_the_title($post->ID)); | |
$url = get_permalink( $post->ID ); | |
$message = "Your Deal is Live.\n Check Deal: \n{$url}"; | |
if(get_post_type($post->ID) === 'deal') //post, page, attachment or whatever other CPT you may have | |
{ | |
wp_mail($emails, "Your Deal on Site Name is Live: {$title}", $message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment