WordPress.org

Ready to get started?Download WordPress

Forums

Akismet
Automatically empty my spam comments (9 posts)

  1. Jonathan
    Member
    Posted 1 year ago #

    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.

    http://wordpress.org/extend/plugins/akismet/

  2. Pothi
    Member
    Posted 1 year ago #

    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...

    #!/bin/bash
    
    # Author: Pothi Kalimuthu (@pothi)
    # please change path to wp-config.php file in WP_CONFIG_PATH accordingly without trailing slash
    
    WP_CONFIG_PATH="/home/username/public_html/wp"
    
    # 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.

  3. Jonathan
    Member
    Posted 1 year ago #

    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.

  4. Pothi
    Member
    Posted 1 year ago #

    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.

  5. J.D. Grimes
    Member
    Posted 11 months ago #

    Just add this to wp-config.php:

    define( 'EMPTY_TRASH_DAYS', 1 );

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

  6. Jonathan
    Member
    Posted 11 months ago #

    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/jonathanlindahl.dk/wp-config.php on line 88

    Is it something who works for you?

    Best regards,
    Jonathan

  7. J.D. Grimes
    Member
    Posted 11 months ago #

    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.

  8. Jonathan
    Member
    Posted 11 months ago #

    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
     * de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German
     * language support.
     */
    define ('WPLANG', 'da_DK');
  9. J.D. Grimes
    Member
    Posted 11 months ago #

    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 );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.