Akismet Anti-Spam - Version 4.2.2

Version Description

Release Date - 24 January 2022

  • Improved compatibility with Formidable Forms
  • Fixed a bug that could cause issues when multiple contact forms appear on one page.
  • Updated delete_comment and deleted_comment actions to pass two arguments to match WordPress core since 4.9.0.
  • Add a filter that allows comment types to be excluded when counting users' approved comments.
Download this release

Release Info

Developer cfinke
Plugin Icon 128x128 Akismet Anti-Spam
Version 4.2.2
Comparing to
See all releases

Code changes from version 4.2.1 to 4.2.2

Files changed (3) hide show
  1. akismet.php +3 -3
  2. class.akismet.php +53 -11
  3. readme.txt +10 -2
akismet.php CHANGED
@@ -6,7 +6,7 @@
6
  Plugin Name: Akismet Anti-Spam
7
  Plugin URI: https://akismet.com/
8
  Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. It keeps your site protected even while you sleep. To get started: activate the Akismet plugin and then go to your Akismet Settings page to set up your API key.
9
- Version: 4.2.1
10
  Author: Automattic
11
  Author URI: https://automattic.com/wordpress-plugins/
12
  License: GPLv2 or later
@@ -37,10 +37,10 @@ if ( !function_exists( 'add_action' ) ) {
37
  exit;
38
  }
39
 
40
- define( 'AKISMET_VERSION', '4.2.1' );
41
  define( 'AKISMET__MINIMUM_WP_VERSION', '5.0' );
42
  define( 'AKISMET__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
43
- define( 'AKISMET_DELETE_LIMIT', 100000 );
44
 
45
  register_activation_hook( __FILE__, array( 'Akismet', 'plugin_activation' ) );
46
  register_deactivation_hook( __FILE__, array( 'Akismet', 'plugin_deactivation' ) );
6
  Plugin Name: Akismet Anti-Spam
7
  Plugin URI: https://akismet.com/
8
  Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. It keeps your site protected even while you sleep. To get started: activate the Akismet plugin and then go to your Akismet Settings page to set up your API key.
9
+ Version: 4.2.2
10
  Author: Automattic
11
  Author URI: https://automattic.com/wordpress-plugins/
12
  License: GPLv2 or later
37
  exit;
38
  }
39
 
40
+ define( 'AKISMET_VERSION', '4.2.2' );
41
  define( 'AKISMET__MINIMUM_WP_VERSION', '5.0' );
42
  define( 'AKISMET__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
43
+ define( 'AKISMET_DELETE_LIMIT', 10000 );
44
 
45
  register_activation_hook( __FILE__, array( 'Akismet', 'plugin_activation' ) );
46
  register_deactivation_hook( __FILE__, array( 'Akismet', 'plugin_deactivation' ) );
class.akismet.php CHANGED
@@ -64,6 +64,10 @@ class Akismet {
64
  add_filter( 'wpcf7_form_elements', array( 'Akismet', 'append_custom_form_fields' ) );
65
  add_filter( 'wpcf7_akismet_parameters', array( 'Akismet', 'prepare_custom_form_values' ) );
66
 
 
 
 
 
67
  add_action( 'update_option_wordpress_api_key', array( 'Akismet', 'updated_option' ), 10, 2 );
68
  add_action( 'add_option_wordpress_api_key', array( 'Akismet', 'added_option' ), 10, 2 );
69
 
@@ -410,8 +414,12 @@ class Akismet {
410
 
411
  $wpdb->queries = array();
412
 
 
 
413
  foreach ( $comment_ids as $comment_id ) {
414
- do_action( 'delete_comment', $comment_id );
 
 
415
  do_action( 'akismet_batch_delete_count', __FUNCTION__ );
416
  }
417
 
@@ -421,12 +429,13 @@ class Akismet {
421
  $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->comments} WHERE comment_id IN ( " . $format_string . " )", $comment_ids ) );
422
  $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->commentmeta} WHERE comment_id IN ( " . $format_string . " )", $comment_ids ) );
423
 
424
- clean_comment_cache( $comment_ids );
425
- do_action( 'akismet_delete_comment_batch', count( $comment_ids ) );
426
-
427
  foreach ( $comment_ids as $comment_id ) {
428
- do_action( 'deleted_comment', $comment_id );
 
429
  }
 
 
 
430
  }
431
 
432
  if ( apply_filters( 'akismet_optimize_table', ( mt_rand(1, 5000) == 11), $wpdb->comments ) ) // lucky number
@@ -504,11 +513,38 @@ class Akismet {
504
  public static function get_user_comments_approved( $user_id, $comment_author_email, $comment_author, $comment_author_url ) {
505
  global $wpdb;
506
 
507
- if ( !empty( $user_id ) )
508
- return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->comments} WHERE user_id = %d AND comment_approved = 1", $user_id ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
 
510
- if ( !empty( $comment_author_email ) )
511
- return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_author_email = %s AND comment_author = %s AND comment_author_url = %s AND comment_approved = 1", $comment_author_email, $comment_author, $comment_author_url ) );
 
512
 
513
  return 0;
514
  }
@@ -1327,8 +1363,14 @@ class Akismet {
1327
  $fields .= '<label>&#916;<textarea name="' . $prefix . 'hp_textarea" cols="45" rows="8" maxlength="100"></textarea></label>';
1328
 
1329
  if ( ! function_exists( 'amp_is_request' ) || ! amp_is_request() ) {
1330
- $fields .= '<input type="hidden" id="ak_js" name="' . $prefix . 'js" value="' . mt_rand( 0, 250 ) . '"/>';
1331
- $fields .= '<script>document.getElementById( "ak_js" ).setAttribute( "value", ( new Date() ).getTime() );</script>';
 
 
 
 
 
 
1332
  }
1333
 
1334
  $fields .= '</p>';
64
  add_filter( 'wpcf7_form_elements', array( 'Akismet', 'append_custom_form_fields' ) );
65
  add_filter( 'wpcf7_akismet_parameters', array( 'Akismet', 'prepare_custom_form_values' ) );
66
 
67
+ // Formidable Forms
68
+ add_filter( 'frm_filter_final_form', array( 'Akismet', 'inject_custom_form_fields' ) );
69
+ add_filter( 'frm_akismet_values', array( 'Akismet', 'prepare_custom_form_values' ) );
70
+
71
  add_action( 'update_option_wordpress_api_key', array( 'Akismet', 'updated_option' ), 10, 2 );
72
  add_action( 'add_option_wordpress_api_key', array( 'Akismet', 'added_option' ), 10, 2 );
73
 
414
 
415
  $wpdb->queries = array();
416
 
417
+ $comments = array();
418
+
419
  foreach ( $comment_ids as $comment_id ) {
420
+ $comments[ $comment_id ] = get_comment( $comment_id );
421
+
422
+ do_action( 'delete_comment', $comment_id, $comments[ $comment_id ] );
423
  do_action( 'akismet_batch_delete_count', __FUNCTION__ );
424
  }
425
 
429
  $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->comments} WHERE comment_id IN ( " . $format_string . " )", $comment_ids ) );
430
  $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->commentmeta} WHERE comment_id IN ( " . $format_string . " )", $comment_ids ) );
431
 
 
 
 
432
  foreach ( $comment_ids as $comment_id ) {
433
+ do_action( 'deleted_comment', $comment_id, $comments[ $comment_id ] );
434
+ unset( $comments[ $comment_id ] );
435
  }
436
+
437
+ clean_comment_cache( $comment_ids );
438
+ do_action( 'akismet_delete_comment_batch', count( $comment_ids ) );
439
  }
440
 
441
  if ( apply_filters( 'akismet_optimize_table', ( mt_rand(1, 5000) == 11), $wpdb->comments ) ) // lucky number
513
  public static function get_user_comments_approved( $user_id, $comment_author_email, $comment_author, $comment_author_url ) {
514
  global $wpdb;
515
 
516
+ /**
517
+ * Which comment types should be ignored when counting a user's approved comments?
518
+ *
519
+ * Some plugins add entries to the comments table that are not actual
520
+ * comments that could have been checked by Akismet. Allow these comments
521
+ * to be excluded from the "approved comment count" query in order to
522
+ * avoid artificially inflating the approved comment count.
523
+ *
524
+ * @param array $comment_types An array of comment types that won't be considered
525
+ * when counting a user's approved comments.
526
+ *
527
+ * @since 4.2.2
528
+ */
529
+ $excluded_comment_types = apply_filters( 'akismet_excluded_comment_types', array() );
530
+
531
+ $comment_type_where = '';
532
+
533
+ if ( is_array( $excluded_comment_types ) && ! empty( $excluded_comment_types ) ) {
534
+ $excluded_comment_types = array_unique( $excluded_comment_types );
535
+
536
+ foreach ( $excluded_comment_types as $excluded_comment_type ) {
537
+ $comment_type_where .= $wpdb->prepare( ' AND comment_type <> %s ', $excluded_comment_type );
538
+ }
539
+ }
540
+
541
+ if ( ! empty( $user_id ) ) {
542
+ return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->comments} WHERE user_id = %d AND comment_approved = 1" . $comment_type_where, $user_id ) );
543
+ }
544
 
545
+ if ( ! empty( $comment_author_email ) ) {
546
+ return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_author_email = %s AND comment_author = %s AND comment_author_url = %s AND comment_approved = 1" . $comment_type_where, $comment_author_email, $comment_author, $comment_author_url ) );
547
+ }
548
 
549
  return 0;
550
  }
1363
  $fields .= '<label>&#916;<textarea name="' . $prefix . 'hp_textarea" cols="45" rows="8" maxlength="100"></textarea></label>';
1364
 
1365
  if ( ! function_exists( 'amp_is_request' ) || ! amp_is_request() ) {
1366
+ // Keep track of how many ak_js fields are in this page so that we don't re-use
1367
+ // the same ID.
1368
+ static $field_count = 0;
1369
+
1370
+ $field_count++;
1371
+
1372
+ $fields .= '<input type="hidden" id="ak_js_' . $field_count . '" name="' . $prefix . 'js" value="' . mt_rand( 0, 250 ) . '"/>';
1373
+ $fields .= '<script>document.getElementById( "ak_js_' . $field_count . '" ).setAttribute( "value", ( new Date() ).getTime() );</script>';
1374
  }
1375
 
1376
  $fields .= '</p>';
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: matt, ryan, andy, mdawaffe, tellyworth, josephscott, lessbloat, eoigal, cfinke, automattic, jgs, procifer, stephdau
3
  Tags: comments, spam, antispam, anti-spam, contact form, anti spam, comment moderation, comment spam, contact form spam, spam comments
4
  Requires at least: 5.0
5
- Tested up to: 5.8
6
- Stable tag: 4.2.1
7
  License: GPLv2 or later
8
 
9
  The best anti-spam protection to block spam comments and spam in a contact form. The most trusted antispam solution for WordPress and WooCommerce.
@@ -30,6 +30,14 @@ Upload the Akismet plugin to your blog, activate it, and then enter your Akismet
30
 
31
  == Changelog ==
32
 
 
 
 
 
 
 
 
 
33
  = 4.2.1 =
34
  *Release Date - 1 October 2021*
35
 
2
  Contributors: matt, ryan, andy, mdawaffe, tellyworth, josephscott, lessbloat, eoigal, cfinke, automattic, jgs, procifer, stephdau
3
  Tags: comments, spam, antispam, anti-spam, contact form, anti spam, comment moderation, comment spam, contact form spam, spam comments
4
  Requires at least: 5.0
5
+ Tested up to: 5.9
6
+ Stable tag: 4.2.2
7
  License: GPLv2 or later
8
 
9
  The best anti-spam protection to block spam comments and spam in a contact form. The most trusted antispam solution for WordPress and WooCommerce.
30
 
31
  == Changelog ==
32
 
33
+ = 4.2.2 =
34
+ *Release Date - 24 January 2022*
35
+
36
+ * Improved compatibility with Formidable Forms
37
+ * Fixed a bug that could cause issues when multiple contact forms appear on one page.
38
+ * Updated delete_comment and deleted_comment actions to pass two arguments to match WordPress core since 4.9.0.
39
+ * Add a filter that allows comment types to be excluded when counting users' approved comments.
40
+
41
  = 4.2.1 =
42
  *Release Date - 1 October 2021*
43