5

Guys, I need to know how to do the following:

When I receive a comment ... This comment must be approved by three moderators. To appear on the site.

Anyone know how to do it or some plugin?

1 Answer 1

8

you can use comment_unapproved_to_approved action hook to call your function which will use a commentmeta field to count how many times that comment has been approved or by how many users and if it's less then 3 then we updated the comment to not approved :

update

I'm posting an updated code in the form of a plugin which fixes a few typos:

<?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');


?>
28
  • thanks for the feedback We have three owners in the specific site The comment must be approved by each of them. Commented Apr 26, 2011 at 3:11
  • this code a moderator can approve more than once to comment? the idea is each of the three, only able to approve a time with 3, the commentary is released Commented Apr 26, 2011 at 16:57
  • Nope, a mod can only approve once each comments and its checked with /only allow each mod to approve once if (in_array($current_user->ID,$mods)){ return '';
    – Bainternet
    Commented Apr 26, 2011 at 17:01
  • ok i will test and tell you about it. Commented Apr 28, 2011 at 14:46
  • Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'check_add_approved_count' not found or invalid function name in /home/sitename/wp-includes/plugin.php on line 395 , i add your function in Theme Functions (functions.php) Commented Apr 28, 2011 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.