WordPress 用户评论审核通过,发个通知给用户

追格官方小助手/ 2022年12月15日/ WordPress/ 浏览 959

根据最新的规定,评论信息都要先审核再发布。审核通过后,如果能给用户发个通知就比较好了。


使用 WordPress 系统,如何实现这个需求呢?


没错,还是钩子!钩子在 WordPress 中无处不在,也无所不能!


对于评论状态变化的监控,WordPress提供了两批钩子:comment_{$old_status}_to_{$new_status} 和 comment_{$new_status}_{$comment->comment_type}


类似于前篇介绍的:《WordPress如何监控文章状态变化》


comment_{$old_status}_to_{$new_status} 包含了以下钩子:


comment_unapproved_to_approved、comment_spam_to_approved、comment_approved_to_unapproved、comment_spam_to_unapproved、comment_unapproved_to_spam、comment_approved_to_spam……


comment_{$old_status}_to_{$new_status} 包含了以下钩子:


comment_unapproved_to_approved、comment_spam_to_approved、comment_approved_to_unapproved、comment_spam_to_unapproved、comment_unapproved_to_spam、comment_approved_to_spam……


有这些钩子就覆盖所有评论状态变化的监控了。和文章状态变化钩子一样,也有一个全面监控评论状态变化的钩子:transition_comment_status


do_action( 'transition_comment_status', int|string $new_status, int|string $old_status, WP_Comment $comment )


发表评论

暂无评论,抢个沙发...

客服 工单