I ha开发者_JS百科ve a front end posting form where registered users can draft post. I have a meta field which contains email of the user who draft the content. Now when i publish the content from backend i want to send a email to user notifying that the post is published.
Any kinds of direction to the research will help.
Thanks!
add_action( 'publish_post', 'send_notification' );
function send_notification( $post_id ) {
$post = get_post($post_id);
$post_url = get_permalink( $post_id );
$post_title = get_the_title( $post_id );
$author = get_userdata($post->post_author);
$subject = 'Post publish notification';
$message = "Hello,";
$message .= "<a href='". $post_url. "'>'".$post_title."'</a>\n\n";
wp_mail($author->user_email, $subject, $message );
}
Here is free wordpress plugin for that http://wordpress.org/extend/plugins/publish-post-email-notification/
PHP's mail function should be a good starting point. Remember to make sure your php.ini is set up correctly to send mail.
Here's a tutorial on how to send new post notification to your WordPress users using MailOptin plugin.
The plugin work by hooking into publish_post hook and then using the standard wp_mail function to deliver the email.
You also have the option to send only to users belonging to a user role. This can come in handy if you wish to deliver the email to segment of your membership users.
You can get the MailOptin plugin for free in WordPress dashboard at https://wordpress.org/plugins/mailoptin/
精彩评论