Support » Plugin: Akismet » Automatically empty my spam comments

  • Jonathan


    Hello 🙂

    I want WordPress to automatically empty my spam comments after 1 day. I can see that Akismet can automatically do it after 30 days – but I will like to have that converted to 1 day.

    I have found this piece of code:

    if ( $post->post_type == ‘post’ && $diff > 30 && get_option( ‘akismet_discard_month’ ) == ‘true’ && empty($comment[‘user_ID’]) ) {

    Should I just change 30 to 1?

    Thanks in advance.

Viewing 8 replies - 1 through 8 (of 8 total)
  • I don’t recommend changing the plugin code that may be overwritten, when it is updated. I use a script to do nightly or weekly purging of spam comments. Here’s the script…

    # Author: Pothi Kalimuthu (@pothi)
    # please change path to wp-config.php file in WP_CONFIG_PATH accordingly without trailing slash
    # Find the credentials to use later
    WPPASS=<code>/bin/sed &quot;s/[()',;]/ /g&quot; ${WP_CONFIG_PATH}/wp-config.php | /bin/grep DB_PASSWORD | /bin/awk '{print $3}'</code>
    WPUSER=<code>/bin/sed &quot;s/[()',;]/ /g&quot; ${WP_CONFIG_PATH}/wp-config.php | /bin/grep DB_USER | /bin/awk '{print $3}'</code>
    WPDB=<code>/bin/sed &quot;s/[()',;]/ /g&quot; ${WP_CONFIG_PATH}/wp-config.php | /bin/grep DB_NAME | /bin/awk '{print $3}'</code>
    # Find the table prefix
    WPPREFIX=<code>/bin/sed -n &quot;/table_prefix/ s/'\(.*\)';/\1/p&quot; ${WP_CONFIG_PATH}/wp-config.php | /usr/bin/awk '{print $3}'</code>
    $(which mysql) -u${WPUSER} -p${WPPASS} ${WPDB} -e "DELETE FROM ${WPPREFIX}comments WHERE ${WPPREFIX}comments.comment_approved = 'spam';"
    exit 0

    Please never never never trust any code that you don’t understand. Please test it in a development environment.



    Hi Pothi,

    Thank you for your answer.

    Think it looks quite advanced.
    Hypothetically speaking – know you do not recommend that – but will I solve the problem by switching 30 out of 1 here:

    if ($ post-> post_type == ‘post’ && $ diff> 30 && get_option (‘akismet_discard_month’) == ‘true’ && empty ($ comment [‘user_id’])) {

    I am willing to update at each update.

    I just checked the code. You are right. I do think that you found the right code to change the automatic interval for purging older spam comments.

    Just add this to wp-config.php:

    define( 'EMPTY_TRASH_DAYS', 1 );

    I think that should work. Though it will also empty the trash.



    Hi J.D. Grimes

    Thanks for your advice.

    I have tried to add to my wp-config.php, but I get this error message:

    Fatal error: Can’t use function return value in write context in /home/findkoll/public_html/ on line 88

    Is it something who works for you?

    Best regards,

    I really don’t see how that error could be related. Are you sure that the code on line 88 is what you added to empty the spam? If you could post what is on that line it would be helpful.



    Sorry, it’s me who wrote the code incorrectly. The error is no longer there.

    But it does not delete all spam comments immediately. You can see here how I inserted it.

     * WordPress Database Table prefix.
     * You can have multiple installations in one database if you give each a unique
     * prefix. Only numbers, letters, and underscores please!
    $table_prefix  = 'wp_';
     * Delete Spam Comments.
    define( 'EMPTY_TRASH_DAYS', 1 );
     * WordPress Localized Language, defaults to English.
     * Change this to localize WordPress.  A corresponding MO file for the chosen
     * language must be installed to wp-content/languages. For example, install
     * to wp-content/languages and set WPLANG to 'de_DE' to enable German
     * language support.
    define ('WPLANG', 'da_DK');

    It doesn’t delete them immediately, but after one day. I don’t know if it will delete them faster if you set replace the 1 with 0. Maybe try that if you want it to delete them faster.

    define( 'EMPTY_TRASH_DAYS', 0 );

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Automatically empty my spam comments’ is closed to new replies.