Created
September 1, 2014 18:41
-
-
Save fjarrett/e8cb7ee8a7012ec2ae7e to your computer and use it in GitHub Desktop.
Alert original post author
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
<?php | |
function ataylorme_alert_original_author( $post_id ) { | |
// Skip post revisions | |
if ( wp_is_post_revision( $post_id ) ) { | |
return; | |
} | |
// Get post data | |
$post = get_post( $post_id ); | |
$post_type_obj = get_post_type_object( $post->post_type ); | |
$post_type_label = isset( $post_type_obj->labels->singular_name ) ? $post_type_obj->labels->singular_name : $post_type_obj->name; | |
$post_author = get_userdata( $post->post_author ); | |
// Get last modified by | |
$last_author_id = get_post_meta( $post_id, '_edit_last', true ); | |
$last_author = get_userdata( $last_author_id ); | |
// Set email subject | |
$subject = 'Your post has been updated'; | |
// Set email message | |
$message = sprintf( | |
"%s updated your %s %s at %s\n\n%s", | |
esc_html( $last_author->display_name ), | |
esc_html( strtolower( $post_type_label ) ), | |
esc_html( $post->post_title ), | |
esc_html( $post->post_modified ), | |
get_permalink( $post_id ) | |
); | |
// Send email | |
wp_mail( $post_author->user_email, $subject, $message ); | |
} | |
add_action( 'save_post', 'ataylorme_alert_original_author' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment