如何审核(手动批准)特定(注册)用户的评论

时间:2019-09-12 作者:3DHardware

我有一个WordPress博客,有很多评论。我有一个自由职业者,在博客上提供支持并回复这些评论。不过,在试用阶段,我希望该支持人员的评论由我手动批准。

如何做到这一点?是否在审核队列中保留特定用户的评论,直到获得批准?

1 个回复
SO网友:Mike Baxter

如果您熟悉编码,可以尝试基于WP\\u注释对象的自定义过滤器。可能是以下情况:

function wpse_wp_insert_comment($id, $comment) {    
        // Add your user_id, or use email address instead.
        if ( empty($comment->comment_author ) || $comment->user_id!== 1 )
            wp_set_comment_status( $comment, \'hold\' );
}
add_action(\'wp_insert_comment\', \'wpse_wp_insert_comment\', 10, 2);
-或。。。

// Same method, but using userdata to compare email address instead
function wpse_wp_insert_comment($id, $comment) {    
    $author = empty($comment->comment_author) ? NULL : get_userdata($comment->user_id);
    // Be sure to update this line with YOUR actual email address.
    if ( empty($comment->comment_author ) || $author->user_email!=="you@your-domain.com" )
        wp_set_comment_status( $comment, \'hold\' );
}
add_action(\'wp_insert_comment\', \'wpse_wp_insert_comment\', 10, 2);
根据Tom Mcfarlin的一篇文章推断”Programmatically Mark a Comment as Unapproved。请参阅他抛出的关于用户预期结果与此类函数导致的实际操作结果的“Gotcha”警告。