-
-
Save nfsarmento/c629d3aea50adc028b2530b49b778288 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 product from frontend form. | |
* Send emails on products publication | |
* @param WP_Post $post | |
* | |
* | |
*/ | |
function ns_send_emails_on_new_event($post){ | |
$emails = "test@test.com"; | |
$title = wp_strip_all_tags(get_the_title($post->ID)); | |
$url = get_edit_post_link( $post->ID, $context ); | |
$message = "A new product has been created on in your site.\nProduct Title: \n{$title} \nProduct URL: \n{$url}"; | |
if(get_post_type($post->ID) === 'product') { | |
wp_mail($emails, "New product has been created", $message); | |
} | |
} | |
add_action('future_to_pending', 'ns_send_emails_on_new_event'); | |
add_action('new_to_pending', 'ns_send_emails_on_new_event'); | |
add_action('draft_to_pending', 'ns_send_emails_on_new_event'); | |
add_action('auto-draft_to_pending', 'ns_send_emails_on_new_event'); | |
add_action('pending_to_publish', 'ns_send_emails_on_deal_publish'); | |
function ns_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) === 'product') | |
{ | |
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