我想那个钩子pre_comment_approved
在这种情况下应该是完美的。
像这样的东西应该可以完成这项工作:
function my_pre_comment_approved($approved, $commentdata) {
// you can return 0, 1 or \'spam\'
if ( $commentdata[\'user_ID\'] ) {
$args = array(
\'user_id\' => $commentdata[\'user_ID\'],
\'post_id\' => $commentdata[\'comment_post_ID\']
);
$usercomment = get_comments( $args );
if ( 1 <= count( $usercomment ) )
return 0;
}
return $approved;
}
add_filter(\'pre_comment_approved\', \'my_pre_comment_approved\', 99, 2);
过滤器应返回:
0
(即“假”),如果评论不被批准1
(即“true”),如果评论应获得批准\'spam\'
如果评论应标记为垃圾邮件