• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress a2z

WordPress a2z

WordPress Dynamic API Reference

  • Home
  • Plugins
  • Themes
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Akismet::delete_old_comments() –

You appear to be a bot. Output may be restricted

Description

Usage

Akismet::delete_old_comments();

Parameters

Returns

void

Source

File name: akismet/class.akismet.php
Lines:

1 to 52 of 52
  public static function delete_old_comments() {
    global $wpdb;

    
/**
 * Determines how many comments will be deleted in each batch.
 *
 * @param int The default, as defined by AKISMET_DELETE_LIMIT.
 */
    $delete_limit = apply_filters( 'akismet_delete_comment_limit', defined( 'AKISMET_DELETE_LIMIT' ) ? AKISMET_DELETE_LIMIT : 10000 );
    $delete_limit = max( 1, intval( $delete_limit ) );

    
/**
 * Determines how many days a comment will be left in the Spam queue before being deleted.
 *
 * @param int The default number of days.
 */
    $delete_interval = apply_filters( 'akismet_delete_comment_interval', 15 );
    $delete_interval = max( 1, intval( $delete_interval ) );

    while ( $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_id FROM {$wpdb->comments} WHERE DATE_SUB(NOW(), INTERVAL %d DAY) > comment_date_gmt AND comment_approved = 'spam' LIMIT %d", $delete_interval, $delete_limit ) ) ) {
      if ( empty( $comment_ids ) )
        return;

      $wpdb->queries = array();

      $comments = array();

      foreach ( $comment_ids as $comment_id ) {
        $comments[ $comment_id ] = get_comment( $comment_id );

        do_action( 'delete_comment', $comment_id, $comments[ $comment_id ] );
        do_action( 'akismet_batch_delete_count', __FUNCTION__ );
      }

      // Prepared as strings since comment_id is an unsigned BIGINT, and using %d will constrain the value to the maximum signed BIGINT.
      $format_string = implode( ", ", array_fill( 0, count( $comment_ids ), '%s' ) );

      $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->comments} WHERE comment_id IN ( " . $format_string . " )", $comment_ids ) );
      $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->commentmeta} WHERE comment_id IN ( " . $format_string . " )", $comment_ids ) );

      foreach ( $comment_ids as $comment_id ) {
        do_action( 'deleted_comment', $comment_id, $comments[ $comment_id ] );
        unset( $comments[ $comment_id ] );
      }

      clean_comment_cache( $comment_ids );
      do_action( 'akismet_delete_comment_batch', count( $comment_ids ) );
    }

    if ( apply_filters( 'akismet_optimize_table', ( mt_rand(1, 5000) == 11), $wpdb->comments ) ) // lucky number
      $wpdb->query("OPTIMIZE TABLE {$wpdb->comments}");
  }
 

 View on GitHub View on Trac

Published: 19th December 2019 | Last updated: 25th January 2022

Primary Sidebar

Information

Function name: Akismet::delete_old_comments
Class ref: Akismet
Plugin ref: Akismet
Version: 5.0.1
Sourcefile: class.akismet.php
File ref: class.akismet.php
Deprecated?: No
API Letters: A,C,D,O

Footer

WordPress a2z
WordPress a2z
WordPress Dynamic API Reference
WordPress 6.1.1. PHP: 8.0.28
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  wp-a2z.org
© Copyright WordPress a2z 2014-2023. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites