wp_new_comment_notify_moderator()
云策文档标注
概述
wp_new_comment_notify_moderator() 函数用于向站点管理员发送待审核评论的通知邮件。它检查评论状态,并通过过滤器 allow_moderator 控制是否发送通知。
关键要点
- 函数参数:$comment_id(整数,必需),表示评论的 ID。
- 返回值:成功时返回 true,失败时返回 false。
- 仅对状态为待审核(comment_approved 为 '0')的评论发送通知。
- 使用 notify_moderator 过滤器允许开发者覆盖默认通知行为。
- 内部调用 wp_notify_moderator() 函数来实际发送邮件通知。
代码示例
function wp_new_comment_notify_moderator( $comment_id ) {
$comment = get_comment( $comment_id );
// Only send notifications for pending comments.
$maybe_notify = ( '0' === $comment->comment_approved );
/** This filter is documented in wp-includes/pluggable.php */
$maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id );
if ( ! $maybe_notify ) {
return false;
}
return wp_notify_moderator( $comment_id );
}注意事项
- 函数自 WordPress 4.4.0 版本引入。
- 相关函数包括 wp_notify_moderator()、apply_filters() 和 get_comment()。
- notify_moderator 过滤器可以用于自定义通知逻辑,例如基于特定条件阻止或允许发送。
原文内容
Sends a comment moderation notification to the comment moderator.
Parameters
$comment_idintrequired-
ID of the comment.
Source
function wp_new_comment_notify_moderator( $comment_id ) {
$comment = get_comment( $comment_id );
// Only send notifications for pending comments.
$maybe_notify = ( '0' === $comment->comment_approved );
/** This filter is documented in wp-includes/pluggable.php */
$maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id );
if ( ! $maybe_notify ) {
return false;
}
return wp_notify_moderator( $comment_id );
}
Hooks
- apply_filters( ‘notify_moderator’, bool $maybe_notify, int $comment_id )
-
Filters whether to send the site moderator email notifications, overriding the site setting.
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |