在我的网站上,用户可以通过普通形式提交帖子。
我保存的PHP变量是:
$usersarray = store the mail of the user
$postId = store the ID of the submitted post提交的帖子在“草稿”中自动输入。
我想自动发邮件时,他的帖子变成“出版”,我怎么做呢?
当然,这必须与不同的用户和不同的帖子提交,而不仅仅是最后一个。(每个用户都提交了自己的帖子)
谢谢你的建议。
发布于 2018-12-20 13:32:55
使用publish_post钩子,它是每当更新post时触发的动作,它的新状态是“发布”。
在文章发表时,通过wp_mail()向文章作者发送电子邮件。
function post_published_notification( $ID, $post ) {
$author = $post->post_author; /* Post author ID. */
$name = get_the_author_meta( 'display_name', $author );
$email = get_the_author_meta( 'user_email', $author );
$title = $post->post_title;
$permalink = get_permalink( $ID );
$edit = get_edit_post_link( $ID, '' );
$to[] = sprintf( '%s <%s>', $name, $email );
$subject = sprintf( 'Published: %s', $title );
$message = sprintf ('Congratulations, %s! Your article “%s” has been published.' . "\n\n", $name, $title );
$message .= sprintf( 'View: %s', $permalink );
$headers[] = '';
wp_mail( $to, $subject, $message, $headers );
}
add_action( 'publish_post', 'post_published_notification', 10, 2 );编辑:
正如@Stender在下面的评论中所建议的那样。
你也可以用
draft_to_publish钩子,这将工作完美地满足您的需要。
https://stackoverflow.com/questions/53869559
复制相似问题