• Resolved wpforever18

    (@wpforever18)


    Hello! By default, the author can publish a comment on their own post without moderation. (Even with everything well configured on the panel so there is moderation). In other words: he is logged in and can post a new comment or respond to one without moderation.

    I understand that this is normal because the author is considered to have privileges to be trusted within the site, but is there any filter to force all comments (whether from authors or visitors) to be moderated by the administrator?

    Thank you very much!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    You can use the ‘pre_comment_approved’ filter. If a 0 is returned, the comment will be held for moderation. You should only do so when the currently passed value is 1 (approved without moderation). Other possible values are ‘spam’ and ‘trash’. Those should pass through unchanged.

    Your callback is passed $commentdata, from which you can discern if the comment author is the post’s author, or use any other criteria you care to use from the data that’s available to the callback. For example, you could simply force everyone except admins to be moderated regardless of other conditions.

    Thread Starter wpforever18

    (@wpforever18)

    Hello! Thank you very much for the tip!

    I used your filter suggestion and added a code that I found during research. The code found is for another purpose, but it ended up working for my purpose, as now the post author’s comment also goes to moderation.

    I’ll leave the code I used here for anyone who needs it too:

    add_filter( 'pre_comment_approved' , 'filter_handler' , '99', 2 );

    function filter_handler( $approved , $commentdata )
    {

    $args = array(
    'user_id' => $commentdata['user_ID'], //get user_ID of the commnet author
    'status' => 'approve', //approved comments only
    'count' => true //return only the count
    );
    $comments = get_comments( $args );
    $comments_num = 100000000000000; // number of comments to moderate

    if( $comments < $comments_num )
    $approved = 0; // set - comment is marked for moderation as "Pending" if less than 100000000000000 comments approved

    return $approved;
    }

    But if you can “clean up” this code, please let me know. Thanks!

    • This reply was modified 1 month ago by bcworkz. Reason: code format fixed
    Moderator bcworkz

    (@bcworkz)

    The only clean up pertains only to how it appeared here. The forum’s parser had corrupted your code, making it difficult for anyone else to use. I fixed it to be un-corrupted. Next time you post code here please use the code block so your code remains un-corrupted.

    I will note that specifying extremely large integers in PHP code can cause difficult to find bugs due to overflow conditions. To specify a very large integer that will not overflow on any system, use the constant PHP_INT_MAX instead of an explicit number like 100000000000000

    Thread Starter wpforever18

    (@wpforever18)

    I am very grateful for the great help and correction! It really helped me a lot. Success always!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.