2

Curiously, Akismet is deleting old spam comments after a period of time (I'm guessing within a week).

This box is NOT checked:

Auto-delete spam submitted on posts more than a month old.

I've sent a message to Akismet support more than a week ago but I've not yet received a reply.

I do not want Akismet to delete anything. I do not check often enough to verify false positives so I want all comments saved indefinitely, even the spam.

Does anyone know why it's deleting spam comments even though it's set not to? Does anyone know of a workaround?

2 Answers 2

3

I would generally not recommend modifying files for Plugins that you do not control. Better would be to write your own site/custom Plugin, to control this hook:

add_action('akismet_scheduled_delete', 'akismet_delete_old');

First, to stop the deletion altogether, simply call:

remove_action('akismet_scheduled_delete', 'akismet_delete_old');

Then, you can set up a cron job (or similar), to fire the akismet_delete_old() function on whatever frequency you prefer.

Edit

To be more clear: I'm referring to a site/custom Plugin, that interacts with Akismet - not a fork/replacement of Akismet. Since Akismet adds the comment-deletion functionality as a callback to an action hook specific to the Plugin, you can override that added action from outside the Plugin.

The remove_action() call above will simply stop the comment-deletion code from running at all. If you want to enable less-frequent comment deletion, you could use several methods:

  1. Rewrite the akismet_delete_old() callback (as you have done in your own answer), and then hook it into akismet_scheduled_delete
  2. Write your own cron job to run on your desired frequency
  3. Etc.

Note: there is a companion callback, akismet_delete_old_meta(), that you may need to modify/remove from the akismet_scheduled_delete action, also.

7
  • 1
    I think you're misunderstanding what I'm saying. I'm not saying that you need to rewrite Akismet itself, but rather to modify its output via custom Plugin. Actually, this method is simpler, because it doesn't require you to modify the Akismet Plugin proper every time it updates. With this method, you write your own plugin that simply removes the action that executes the function that deletes old comment spam, using the indicated code. Commented Apr 30, 2012 at 19:38
  • I did misunderstand. I'll look into your suggestion.
    – Sparky
    Commented Apr 30, 2012 at 19:44
  • Does remove_action('akismet_scheduled_delete', 'akismet_delete_old'); have to be run via cron or just one time? I never wrote a WP plugin before.
    – Sparky
    Commented Apr 30, 2012 at 20:11
  • It runs every time WordPress is executed, just like the corresponding add_action() call runs every time. WordPress collects all of the add_action() and remove_action() calls, queues them by priority, and then fires them at the specified action hook. A remove_action() added to the same priority for the same callback will simply remove the specified callback from the queue for the specified action. By adding your remove_action() call, you basically tell WordPress, "no, don't execute that callback at the akismet_scheduled_delete action." Commented Apr 30, 2012 at 20:14
  • So basically, it's a file in the plugin directory using a format similar to the other plugins, except it only contains the one line above? Then I just "activate" it in the Admin panel?
    – Sparky
    Commented Apr 30, 2012 at 20:17
0

Firstly, there is no setting for not deleting spam comments. My confusion was caused by ambiguous wording on the Akismet configuration page...

Auto-delete spam submitted on posts more than a month old.

"more than a month old" is referring to "posts" that are more than a month old, not "spam submitted on posts" that are more than a month old.

As far as the original question about how to stop the comments from being deleted...

They are automatically deleted after 15 days, no matter what. Akismet thinks they know best! They assume you want the spam deleted after 2 weeks because they also assume that 15 days is more than enough time for you to verify that the comment was flagged correctly.

I asked them why they couldn't simply give the user an option and I got some excuse about how thousands of spam comments can shut down a server. Fine, that's true. But the same thing could happen if the Akismet plugin wasn't installed in the first place. Give the admin a little credit for being able to make his own decision regarding his installation. But that's not going to happen.


I realize editing core files is frowned upon, but here's how I decided to handle it for my own site.

This line in the wp-content/plugins/akismet/akismet.php file...

$comment_ids = $wpdb->get_col("SELECT comment_id FROM $wpdb->comments WHERE
DATE_SUB('$now_gmt', INTERVAL 15 DAY) > comment_date_gmt AND
comment_approved = 'spam'");

I edited INTERVAL 15 DAY to 180 days, giving me more than enough time to review comments before deletion.

EDIT:

Every time the plugin is updated, such a modification would have to be re-applied.


EDIT 2:

As per helpful suggestion by @ChipBennett, I created a plugin which does nothing but deactivate the comment deletion by Akismet plugin. This simple thing avoids the whole issue of having to modify the Akismet plugin.

I simply created the following php file and put it in the plugins directory (wp-content/plugins/)

<?php
/**
 * @package Akismet_keep_comment
 * @version 1.0
 */
/*
Plugin Name: Akismet Keep Comment
Plugin URI: 
Description: This plugin removes the comment deletion ability of the Akismet plugin
Author: Me
Version: 1.0
Author URI: http://www.mysite.com
*/

remove_action('akismet_scheduled_delete', 'akismet_delete_old');

?>

Then I "activated" it via the plugin page of the Dashboard.

12
  • If it takes you longer than 2 weeks to cull your spam queue, you have other issues going on than auto-deletion. For that matter, if you're reviewing every comment in your spam queue, why even use Akismet in the first place?
    – EAMann
    Commented Apr 30, 2012 at 18:48
  • @EAMann, I only get a few dozen spam comments a month... sometimes more in waves. Since Akismet is not perfect and occasionally has false positives, I'd like to not give the plugin total autonomy to just delete comments. You may not have been aware but Akismet will delete anything in the spam queue even if it was put there long before the plugin was installed.
    – Sparky
    Commented Apr 30, 2012 at 19:21
  • If anything is in the spam queue long before Akismet is installed, you likely put it there yourself because it was spam - meaning it should be deleted.
    – EAMann
    Commented Apr 30, 2012 at 19:27
  • 1
    Downvote for modifying an uncontrolled PHP file. This method will require modifying Akismet PHP files every time it is updated. Commented Apr 30, 2012 at 19:39
  • 1
    @Sparky672 and that's all well and good, if this solution works for you specifically. :) In fact, that's what your "accepted answer" checkmark indicates. But up/down votes are for community vetting of answers to determine which answers are the most universally correct/useful. This answer will not be appropriate for most people, because of the need to edit Plugin files directly. (The WPSE community generally discourages editing core files - or other files outside the user's direct control - for all the obvious reasons.) Commented Apr 30, 2012 at 19:50

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.