首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用户在wordpress中提交他的文章后发送邮件

问用户在wordpress中提交他的文章后发送邮件
EN

Stack Overflow用户
提问于 2018-12-20 13:19:22
回答 1查看 443关注 0票数 0

在我的网站上,用户可以通过普通形式提交帖子。

我保存的PHP变量是:

代码语言:javascript
复制
$usersarray = store the mail of the user
$postId = store the ID of the submitted post

提交的帖子在“草稿”中自动输入。

我想自动发邮件时,他的帖子变成“出版”,我怎么做呢?

当然,这必须与不同的用户和不同的帖子提交,而不仅仅是最后一个。(每个用户都提交了自己的帖子)

谢谢你的建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-20 13:32:55

使用publish_post钩子,它是每当更新post时触发的动作,它的新状态是“发布”。

在文章发表时,通过wp_mail()向文章作者发送电子邮件。

代码语言:javascript
复制
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钩子,这将工作完美地满足您的需要。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53869559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档