Support » Plugin: Akismet Anti-Spam » Change delete spam comments every 15 days to everyday?

Viewing 6 replies - 1 through 6 (of 6 total)
  • I have the same question. Also, can the time of day be changed? That is when is the content deleted? After 15 days exactly of the date that the spam was posted? at midnight on the 15th day, etc.??? Please let us know. Thanks.

    Plugin Contributor Greg Stewart

    (@jgs)

    Sure, it’s possible, but you’ll have to change some code in class.akismet.php. If you’re not comfortable with that, reach out to a developer or your web host for help.

    Depending on the version of the plugin you’re running, the line numbers may be different, but you’re basically looking for this SQL query:

    SELECT comment_id FROM {$wpdb->comments} WHERE DATE_SUB(NOW(), INTERVAL 15 DAY

    You can change the ‘INTERVAL 15’ to something lower, but keep in mind that there’s the possibility of breaking something and that this code may be replaced automatically when you update to newer versions so you’ll have to make that change with each update.

    Is there any chance of this being made configurable, even if it was only through a setting in wp-config.php – as you say, editing the plugin itself is hazardous.

    janesherratt

    (@janesherratt)

    hi, can I second that request from fsquared, would also like to auto-delete on a regular basis. Thanks

    Plugin Author Christopher Finke

    (@cfinke)

    Design Engineer at Automattic

    See this thread for instructions on changing how frequently comments are deleted from spam: https://wordpress.org/support/topic/how-do-you-use-the-new-filters-added-to-303?replies=2

    Just in case anyone is still reading this, it’s actually quite easy to do it. The function in Akismet is set up to apply a filter that contains the custom time period.

    All you have to do is make the function.

    Akismet has the line $delete_interval = apply_filters( 'akismet_delete_comment_interval', 15 ); – what that means is, it puts the results of a filter *if it exists*.

    So, you need to make the filter that it takes the number from 🙂

    Go to your theme’s folder and find the file functions.php – that’s where you put all your custom functions, so even if Akismet gets updated, your new bit of code won’t get deleted.

    At the end (before you see ?> if it’s there, otherwise just make sure it goes after the end of any previous bits of code), add something like this:

    add_filter( 'akismet_delete_comment_interval', 'custom_set_delete_interval' );
    
    function custom_set_delete_interval() {
    	return 2;
    }

    To walk you through it: It tells WordPress that a function named ‘custom_set_delete_interval’ will be run every time the filter ‘akismet_delete_comment_interval’ is applied. And Akismet *does* apply it right when you need it, as we saw above 🙂

    Then we make the function itself. All we want it to do is ‘return’ (fancy word for ‘send back’) the number we want to replace ’15’ with. So, when the filter is applied, the new number is passed back to it.

    Save the functions.php file and then check that it works – go to http://your-site.com/wp-admin/admin.php?page=akismet-key-config and scroll down to where you can set options. You’ll see it say “Note: Spam in the spam folder older than 2 days is deleted automatically. ” in the case I showed above.

    Hope this helps 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Change delete spam comments every 15 days to everyday?’ is closed to new replies.