当一篇新文章发表后,我想向我博客的所有编辑发送一封电子邮件。我找到了很多插件,但我想在没有插件的情况下解决这个问题。此外,我还找到了一个发送电子邮件的教程,但这只适用于博客管理员,不适用于编辑(Front-End Editor email notification issue). 如果你能给我小费或建议,我会很高兴的。非常感谢。
<?php
function notifyauthor( $post_id ) {
$post = get_post( $post_id );
$author = get_userdata( $post->post_author ); // How can I specify the role of the editors here?
$subject = "Post Published: " . $post->post_title;
$message = \' Hi \' . $author->display_name . \',
Your post, "\' . $post->post_title . \'" has just been published.
View post: \' . get_permalink( $post_id ) . \'Thanks\';
wp_mail( $role->user_email, $subject, $message );
}
add_action( \'publish_post\', \'notifyauthor\' );