Created
August 6, 2013 18:38
-
-
Save castroalves/6167297 to your computer and use it in GitHub Desktop.
WordPress Hook to Notify Users When New Post Was 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
/** | |
* Send E-mails When a New Post is Published | |
*/ | |
function email_notify( $new_status, $old_status, $post ) { | |
// Avoids re-sending e-mails on update | |
if( $new_status == 'publish' && $new_status != $old_status ) { | |
$message = 'The post ' . $post->post_title . ' was published at ' . get_bloginfo('name'); | |
add_filter( 'wp_mail_content_type', 'set_html_content_type' ); | |
wp_mail( '[email protected]', 'New Post Published At ' . get_bloginfo('name'), $message ); | |
// Reset content-type to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578 | |
remove_filter( 'wp_mail_content_type', 'set_html_content_type' ); | |
return $post->ID; | |
} | |
} | |
add_action( 'transition_post_status', 'email_notify', 10, 3 ); | |
function set_html_content_type() { | |
return 'text/html'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment