我有一个自定义的帖子类型“月报”,需要在发布新公告时向订阅者发送一封盲邮件。
下面的代码可以发送给订阅者,但所有人都可以看到电子邮件。
如何将代码修改为密件抄送订户?
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 \'monthlybulletin\' !== 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 );
}
谢谢大家!