wordpress收费下载资源主题
wordpress付费下载资源插件

WordPress hook钩子comment_moderation_recipients的用法详解

WordPress的comment_moderation_recipients钩子是一个用于修改评论审核收件人的钩子。该钩子允许开发者在评论被提交后,根据特定条件动态地更改收件人。

使用该钩子,需要在主题的functions.php文件或者自定义插件中添加以下代码:

function custom_comment_moderation_recipients( $emails, $comment_id ) {
// 获取评论信息
$comment = get_comment( $comment_id );

// 添加自定义逻辑,根据评论内容或其他条件来动态修改收件人
if ( // 根据条件判断是否需要修改收件人
$comment->comment_author_email == 'admin@example.com' ||
$comment->comment_author_email == 'moderator@example.com'
) {
// 修改收件人
$emails = 'custom-recipient@example.com';
}

return $emails;
}
add_filter( 'comment_moderation_recipients', 'custom_comment_moderation_recipients', 10, 2 );

在上述示例代码中,我们首先定义了一个名为`custom_comment_moderation_recipients`的自定义函数。该函数接受两个参数:$emails用于接收原始收件人列表,$comment_id用于获取评论信息。

在函数体内,我们获取了评论信息并根据条件判断是否需要修改收件人。如果条件成立,则将$emails变量修改为我们所需的自定义收件人。

最后,我们使用add_filter函数将自定义函数`custom_comment_moderation_recipients`添加为comment_moderation_recipients钩子的过滤器。

通过这样的方式,我们可以根据自己的需求来动态地修改评论审核的收件人。

0 个评论

定制开发
本站承接WordPress等系统建站仿站、二次开发、主题插件定制等开发服务
在线咨询
  • 请直接说明需求,勿问在否
    QQ:1-247-246-247

  • QQ一群:104228692(满)
  • QQ二群:64786792
在线咨询
本站承接WordPress建站仿站、二次开发、主题插件定制等PHP开发服务!

了解详情