bulk actions in wordpress comment moderation

I’ve been getting a steady stream of comment spam for the past few days, and WordPress’ built in moderation is doing a superb job. Very few of them have gotten through so far, while normal people are still able to leave comments without me having to moderate them.

My only complaint is that after a comment goes into moderation, I have to click the delete radio button for each one and if I get hit by 20-30 at a time, it’s more time than I want to spend cleaning up comment spam.

To save myself time, I wrote a Javascript function and added it to wp-admin/moderation.php to allow me to select the approve, delete or do nothing radio button for all moderated comments. In case anyone else wants to use it, I’ve included the code below. Simply add the block right above the following text (line number 143 in my installation):

<?php _e(‘<p>The following comments are in the moderation queue:</p>’) ?>

Here is the code to add.

<script type="text/javascript">
function bulkSelect( action )
    form = document.approval;
    for ( i = 0; i < form.elements.length; i++ )
        if ( form.elements[ i ].type == "radio" &&
            form.elements[ i ].value == action )
            form.elements[ i ].checked = true;

    <a href="javascript:bulkSelect('approve')">approve</a> |
    <a href="javascript:bulkSelect('delete')">delete</a> |
    <a href="javascript:bulkSelect('later')">do nothing</a> on all comments


 (Post a comment) | Comments RSS feed
  1. Thank you, thank you, thank you.
    I am having such a problem with comment spam and this has just saved me some time! A BIG help. Thank you!

    Comment by beth on November 2, 2004 @ 5:39 pm
  2. I would also like to thank you. I have put a post on my website linking to your code. Again, I thank you for your code.

    Comment by John Hays on January 3, 2005 @ 4:06 am
  3. Thank you for this code. I added it as you instructed and it is working fine. However, before I used your code I got this error message, “Warning: Invalid argument supplied for foreach() in /home2/maria/public_html/memoir/wp-admin/moderation.php on line 26

    Warning: Cannot modify header information – headers already sent by (output started at /home2/maria/public_html/memoir/wp-admin/moderation.php:26) in /home2/maria/public_html/memoir/wp-admin/moderation.php on line 71”

    If you know anything about this please let me know. Thanks!

    Comment by Bink on July 28, 2006 @ 1:31 pm
  4. Blink: I haven’t seen that error, but WordPress just released 2.0.4, so you may want to upgrade to that and see if you still get the error.

    Comment by dan on July 29, 2006 @ 5:50 am

Comments are closed