// 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,
is_countable( $comment_ids ) ?
count( $comment_ids ) : 0, '%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',
is_countable( $comment_ids ) ?
count( $comment_ids ) : 0
);
} if ( apply_filters( 'akismet_optimize_table',
( mt_rand(1, 5000
) == 11
),
$wpdb->comments
) ) // lucky number
$wpdb->
query("OPTIMIZE TABLE {
$wpdb->comments
}"
);
} public static function delete_old_comments_meta() { global $wpdb;
$interval =
apply_filters( 'akismet_delete_commentmeta_interval', 15
);