WordPress.org

Ready to get started?Download WordPress

Forums

How can I remove thousands of Spam comments? (2 posts)

  1. mikewelsh
    Member
    Posted 1 year ago #

    Hi

    My host, Siteground, has shut down my site until I clear all of the Spam comments out.

    I have stopped new registrations. I have installed a disable comments plugin. How do I get rid of thousands of spam comments from 300+ multisites from network admin? None of them will have been approved. If necessary I am happy to delete all comments.

    Is there a way to do it without having to login to each individual site or find each individual comments table in myPHPadmin?

    Many thanks, Mike.

    [Please stop posting the same question in multiple, pre-existing, topics.]

  2. David Sader
    Member
    Posted 1 year ago #

    I use this mu-plugin snippet on an install with a couple hundred blogs. I've seen it clear out towsands of spam comments and empty trashes. It may time out if a site has gadzillions of spam, I don't know. I can't test that.

    Plunk this snippet into a php file in your "mu-plugins" folder. It'll run when you click the "Update Network" button.

    <?php
    function my_spam_be_gone( $blog_id ) {
    	global $wpdb;
    	$blog_prefix = $wpdb->get_blog_prefix( $blog_id );
    			$wpdb->query( "DELETE FROM {$blog_prefix}comments WHERE comment_approved = 'spam' OR comment_approved = 'trash'" );
    }
    add_action( 'wpmu_upgrade_site', 'my_spam_be_gone' );
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic