automatically delete spam comments in wordpress

WordPress Spam comments is big issue. I am getting daily 5k spam comments daily. we automated task of  deleting spam comments automatically. Daily going to comments dashboard and deleting spam comments is really boring task. WordPress Akismat wordpress plugin does good job of finding spam comments.

automatically delete spam comments in wordpress
automatically delete spam comments in wordpress

 

How to automatically delete spam comments in wordpress?

I am using Akismat wordpress plugin for my all wordpress blogs. It does good job of finding spam comments. Due to spam comments. comment-meta table becoming big and causing mysql resource issues. So cleaning comments table became necessary. so we used following hook in wordpress theme code.


function auto_delete_spam_comments() {
$in_progress = (bool) get_site_option( 'spamcomment_delete_in_progress' );
if ( ! $in_progress ) {
global $wpdb;
update_site_option( 'spamcomment_delete_in_progress', '1' );
// 4980
$next = (int) get_site_option( 'spamcomments_delete_next_blog' );
if ( empty( $next ) ) {
$next = 1;
}

if ( $next > 3000 ) {
return;
}
switch_to_blog( $next );

$spams = $wpdb->get_col( "SELECT comment_id FROM {$wpdb->comments} WHERE comment_approved = 'spam' LIMIT 10" );
if ( empty( $spams ) ) {
$next++;
update_site_option( 'spamcomments_delete_next_blog', $next );
} else {
foreach ( $spams as $spam ) {
wp_delete_comment( $spam, true );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->commentmeta} WHERE comment_id = %d", $spam ) );
}
}
// reclaim disk space
$wpdb->query( "OPTIMIZE TABLE {$wpdb->comments}" );
$wpdb->query( "OPTIMIZE TABLE {$wpdb->commentmeta}" );
restore_current_blog();
delete_site_option( 'spamcomment_delete_in_progress' );
}
}
register_shutdown_function( 'auto_delete_spam_comments' );

Notes:
The number of blogs is hardcoded (3000)
Add above code in functions.php file.

If you want WordPress to automatically empty my spam comments after 1 day. Just add this to wp-config.php. Following code will automatically Empty Your WordPress Trash

/**
 * Delete Spam Comments.
 */
define( 'EMPTY_TRASH_DAYS', 1 );

To disable trash set the number of days to zero. Note that WordPress will not ask for confirmation when someone clicks on “Delete Permanently”.

define( 'EMPTY_TRASH_DAYS', 0 ); // Zero days

If you want more information Automatically empty wordpress Trash comments and posts and How to make empty wordpress trash automatically

how do i find my akismet api key for wordpress

Some wordpress developer asked me, how do i find my akismet api key for wordpress, For protect your site from spam comments you need the askimet api key. which is common for jetpack and akismet plugin. WordPress api key is very important for using the wordpress jetpack plugin. For hosted wordpress sites wordpress api key is very important.

how do i find my akismet api key for wordpress

Here I will show you how to get the new wordpress api key.

  • sign in with your WordPress.com credentials (if you not have  wordpress.org account yet then sign up to worpdpress.org
  • Then go to your wordpress site and allow Akismet to connect to your WordPress account
  • click “sign up for a subscription”
  • choose your price plan. Get free plan.
  • be greeted by an “All Done” page and your big API key at the top of the page

Copy your api key and put in your wordpress site for jetpack plugin.

how do i find my akismet api key for wordpress
how do i find my akismet api key for wordpress

how to stop wordpress spam comments and increase SEO

WordPress tutorial, how to stop wordpress spam comments and increase SEO. Spam comments is really major issue. Spam comments will affect your site SEO.
You should delete the spam word comments from wordpress site.

how to stop wordpress spam comments and increase SEO

If you want to prevent spam comments wordpress.  You can check more points and wordpress plugins which will be helpful for wordpress websites.

If you have approved spam comments already than you can use following SQL query to change some spam comments status.

Using following sql query you can unapprove spam comments which are already approved.


Update wp_comments set comment_approved=0 WHERE CHAR_LENGTH(comment_author_url)>35;
Update wp_comments set comment_approved=0 WHERE CHAR_LENGTH(comment_author)>30;

 

After this, you can again recheck the comments which might be spam.

For SEO of your site deleting spam word comments is good.

Here are some steps for protecting your wordpress site.

You may copy and paste the following list to the Comment Moderation box in your wp-admin/options-discussions.php page:

  • -online
  • 4u
  • adipex
  • advicer
  • baccarrat
  • blackjack
  • bllogspot
  • booker
  • byob
  • car-rental-e-site
  • car-rentals-e-site
  • carisoprodol
  • casino
  • casinos
  • chatroom
  • cialis
  • coolcoolhu
  • coolhu
  • credit-card-debt
  • credit-report-4u
  • cwas
  • cyclen
  • cyclobenzaprine
  • dating-e-site
  • day-trading
  • debt-consolidation
  • debt-consolidation-consultant
  • discreetordering
  • duty-free
  • dutyfree
  • equityloans
  • fioricet
  • flowers-leading-site
  • freenet-shopping
  • freenet
  • gambling-
  • hair-loss
  • health-insurancedeals-4u
  • homeequityloans
  • homefinance
  • holdem
  • holdempoker
  • holdemsoftware
  • holdemtexasturbowilson
  • hotel-dealse-site
  • hotele-site
  • hotelse-site
  • incest
  • insurance-quotesdeals-4u
  • insurancedeals-4u
  • jrcreations
  • levitra
  • macinstruct
  • mortgage-4-u
  • mortgagequotes
  • online-gambling
  • onlinegambling-4u
  • ottawavalleyag
  • ownsthis
  • palm-texas-holdem-game
  • paxil
  • penis
  • pharmacy
  • phentermine
  • poker-chip
  • poze
  • pussy
  • rental-car-e-site
  • ringtones
  • roulette
  • shemale
  • shoes
  • slot-machine
  • texas-holdem
  • thorcarlson
  • top-site
  • top-e-site
  • tramadol
  • trim-spa
  • ultram
  • valeofglamorganconservatives
  • viagra
  • vioxx
  • xanax
  • zolus

There are some nice plugins also which is helpful for protecting your site from spam comments.
You should activate the Akismet wordpress plugin.
Akismet is quite possibly the best way in the world to protect your blog from comment and trackback spam. It keeps your site protected from spam even while you sleep.

You should check the following option from wordpress:

Before a comment appears: (Options)

  1. Before a comment appears An administrator must always approve the comment
  2. Comment author must have a previously approved comment

If you have many spam word comments in your site then you should use sql query for delete the spam comments.

DELETE FROM wp_comments WHERE comment_content LIKE '%<a%';
DELETE FROM wp_comments WHERE comment_author LIKE '%<a%';
DELETE FROM wp_comments WHERE comment_author_url LIKE '%health%';

You should replace the spam comments words in SQL query. Using above sql query you can delete the all spam word comments.

For SEO purpose following options are very important.

how to stop wordpress spam comments and increase SEO
how to stop wordpress spam comments and increase SEO

kill spam wordpress comments by changing comment file

In Article, we tell you about how to change the filename of wp-comments-post.php file another name. and kill spam wordpress comments by changing filename.

kill spam wordpress comments by changing filename wp-comments-post.php

With WordPress blogs and sites spam comments is very big issue. That waste our lot of time. There is very nice plugin called Akismet by wordpress. Which is helpful for catching the spam comments but that is not smart enough. Some spambots simply hit the wp-comments-post.php and wp-trackback.php files directly, without scanning your site to find the real names of these scripts. You can foil such bots by renaming these files. My site is also faced the spam comments and hack issues by spmmers. So following trick is very useful.

This files will not track which comment is spam. In this tutorial I will tell you about how to change the filename of wp-comments-post.php file another name. This way you can easily protect your blog against spammer comments.

You need to just follow the steps:

  1. Back up all your files.
  2. Replace all instances of wp-comments-post.php in your theme template files with wp-comments-kill-spam.php. In most themes, this will mean editing comments.php and comments-popup.php; it’s a good idea to double-check by searching through all files in your theme directory with the “find and replace” feature of your favorite editor.
  3. Upload your edited template files.
  4. Rename your wp-comments-post.php file to wp-comments-die-spam-die.php. Be sure that wp-comments-post.php is gone when you’re done, or spammers will still be able to use it!
  5. (Optional) Create a blank file and name it wp-comments-post.php. This will prevent spambots from getting a 404 error. If your 404 page is large, this will save you some bandwidth; it might also keep the spammers from catching on to your trick.
  6. Check that everything works by posting a test comment to your blog.

You will find following code in comments.php file.


<form action="<!--?php echo get_option('siteurl'); ?-->/wp-comments-post.php" method="post" id="commentform">

just replace to that as follows:


<form action="<!--?php echo get_option('siteurl'); ?-->/<tt>wp-comments-kill-spam.php</tt>" method="post" id="commentform">

This is simple way to protect your blog without any wordpress plugin. This tip is written by purabtech.in

If you are having any issue then please write to me support@purabtech.in.

kill spam wordpress comments by changing comment file
kill spam wordpress comments by changing comment file