我正在使用此功能在用户的帖子发布时通知用户。然而,更新帖子时会重复发送电子邮件。我只想在第一次发布帖子时发送一封电子邮件,如果帖子随后更新,我不会再发送更多电子邮件。
function notifyauthor($post_id) {
$post = get_post($post_id);
$author = get_userdata($post->post_author);
$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 )."
"
;
wp_mail($author->user_email, $subject, $message);
}
add_action(\'publish_post\', \'notifyauthor\');