您可以使用comment_unapproved_to_approved
动作挂钩调用您的函数,该函数将使用commentmeta字段计算该评论被批准的次数或被多少用户批准,如果少于3,则我们将该评论更新为未批准:
更新
我正在以插件的形式发布更新的代码,该插件修复了一些拼写错误:
<?php
/*
Plugin Name: 3-comment-mod
Plugin URI: http://en.bainternet.info
Description: Answer to http://wordpress.stackexchange.com/questions/15574/3-moderators-to-approve-comment/15595#15595
Version: 1.0
Author: Bainternet
Author URI: http://en.bainternet.info
*/
if(!function_exists(\'check_add_approved_count\')) {
function check_add_approved_count($comment){
global $current_user;
get_currentuserinfo();
//respect the admin comments approved by one approval
if (current_user_can(\'manage_options\')){
return \'\';
}
$mods = get_comment_meta($comment->comment_ID,\'approved_by\',true);
if(!empty($mods) && is_array($mods)){
//only allow each mod to approve once
if (in_array($current_user->ID,$mods)){
return \'\';
}else{
//here we check the count
if (count($mods) < 3){
//if less then 3 then
//we add the current mod to the approving list
$mods[] = $current_user->ID;
update_comment_meta($comment->comment_ID,\'approved_by\',$mods);
//and revert back the comment to not approved
$commentarr = get_comment($comment->comment_ID, ARRAY_A);
$commentarr[\'comment_approved\'] = 0;
wp_update_comment($commentarr);
}
}
}
//if we got here it means that this is the first approval
//so we just add the user to the list and revert back the comment to not approved
$mods[] = $current_user->ID;
update_comment_meta($comment->comment_ID,\'approved_by\',$mods);
//and revert back the comment to not approved
$commentarr = get_comment($comment->comment_ID, ARRAY_A);
$commentarr[\'comment_approved\'] = 0;
wp_update_comment($commentarr);
}
}
add_action(\'comment_unapproved_to_approved\',\'check_add_approved_count\');
?>