admin管理员组文章数量:1203823
I'd like to have an email automatically sent out to my website's subscribers when I publish a post for a specific custom post type. I've found a few plugins that will do this but only for regular posts (or for any post type that gets published, not allowing you to specify a particular post type). Any suggestions would be greatly appreciated! Thanks.
I'd like to have an email automatically sent out to my website's subscribers when I publish a post for a specific custom post type. I've found a few plugins that will do this but only for regular posts (or for any post type that gets published, not allowing you to specify a particular post type). Any suggestions would be greatly appreciated! Thanks.
Share Improve this question asked May 24, 2013 at 17:15 furiofurio 731 gold badge2 silver badges4 bronze badges1 Answer
Reset to default 16Hook into transition_post_status
, fetch the users and send an email to all users.
Sample code, not tested:
add_action( 'transition_post_status', 'send_mails_on_publish', 10, 3 );
function send_mails_on_publish( $new_status, $old_status, $post )
{
if ( 'publish' !== $new_status or 'publish' === $old_status
or 'my_custom_type' !== get_post_type( $post ) )
return;
$subscribers = get_users( array ( 'role' => 'subscriber' ) );
$emails = array ();
foreach ( $subscribers as $subscriber )
$emails[] = $subscriber->user_email;
$body = sprintf( 'Hey there is a new entry!
See <%s>',
get_permalink( $post )
);
wp_mail( $emails, 'New entry!', $body );
}
You should probably use the Bcc
field.
本文标签: How to auto send email when publishing a custom post type
版权声明:本文标题:How to auto send email when publishing a custom post type? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738676681a2106304.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论