Akismet Anti-Spam - Version 2.5.6

Version Description

  • Prevent retry scheduling problems on sites where wp_cron is misbehaving
  • Preload mshot previews
  • Modernize the widget code
  • Fix a bug where comments were not held for moderation during an error condition
  • Improve the UX and display when comments are temporarily held due to an error
  • Make the Check For Spam button force a retry when comments are held due to an error
  • Handle errors caused by an invalid key
  • Don't retry comments that are too old
  • Improve error messages when verifying an API key
Download this release

Release Info

Developer tellyworth
Plugin Icon 128x128 Akismet Anti-Spam
Version 2.5.6
Comparing to
See all releases

Code changes from version 2.5.5 to 2.5.6

Files changed (5) hide show
  1. admin.php +56 -18
  2. akismet.js +6 -0
  3. akismet.php +61 -8
  4. readme.txt +13 -2
  5. widget.php +87 -69
admin.php CHANGED
@@ -125,8 +125,7 @@ function akismet_conf() {
125
  if ( $key_status == 'valid' ) {
126
  $ms[] = 'key_valid';
127
  } else if ( $key_status == 'invalid' ) {
128
- delete_option('wordpress_api_key');
129
- $ms[] = 'key_empty';
130
  } else if ( !empty($key) && $key_status == 'failed' ) {
131
  $ms[] = 'key_failed';
132
  }
@@ -140,6 +139,7 @@ function akismet_conf() {
140
  'no_connection' => array('color' => '888', 'text' => __('There was a problem connecting to the Akismet server. Please check your server configuration.')),
141
  'key_empty' => array('color' => 'aa0', 'text' => sprintf(__('Please enter an API key. (<a href="%s" style="color:#fff">Get your key.</a>)'), 'http://akismet.com/get/?return=true')),
142
  'key_valid' => array('color' => '4AB915', 'text' => __('This key is valid.')),
 
143
  'key_failed' => array('color' => 'aa0', 'text' => __('The key below was previously validated but a connection to akismet.com can not be established at this time. Please check your server configuration.')),
144
  'bad_home_url' => array('color' => '888', 'text' => sprintf( __('Your WordPress home URL %s is invalid. Please fix the <a href="%s">home option</a>.'), esc_html( get_bloginfo('url') ), admin_url('options.php#home') ) ),
145
  );
@@ -291,7 +291,32 @@ function akismet_stats() {
291
  add_action('activity_box_end', 'akismet_stats');
292
 
293
  function akismet_admin_warnings() {
294
- global $wpcom_api_key;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  if ( !get_option('wordpress_api_key') && !$wpcom_api_key && !isset($_POST['submit']) ) {
296
  function akismet_warning() {
297
  echo "
@@ -303,11 +328,12 @@ function akismet_admin_warnings() {
303
  } elseif ( ( empty($_SERVER['SCRIPT_FILENAME']) || basename($_SERVER['SCRIPT_FILENAME']) == 'edit-comments.php' ) && wp_next_scheduled('akismet_schedule_cron_recheck') ) {
304
  function akismet_warning() {
305
  global $wpdb;
 
306
  $waiting = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" ) );
307
- $next_check = human_time_diff( wp_next_scheduled('akismet_schedule_cron_recheck') );
308
- if ( $waiting > 0 )
309
  echo "
310
- <div id='akismet-warning' class='updated fade'><p><strong>".__('Akismet has detected a problem.')."</strong> ".sprintf(_n('A server or network problem prevented Akismet from checking %d comment. It has been temporarily held for moderation and will be automatically re-checked in %s.', 'A server or network problem prevented Akismet from checking %d comments. They have been temporarily held for moderation and will be automatically re-checked in %s.', $waiting), number_format_i18n( $waiting ), $next_check)."</p></div>
311
  ";
312
  }
313
  add_action('admin_notices', 'akismet_warning');
@@ -324,10 +350,13 @@ function akismet_comment_row_action( $a, $comment ) {
324
  return $a;
325
 
326
  $akismet_result = get_comment_meta( $comment->comment_ID, 'akismet_result', true );
 
327
  $user_result = get_comment_meta( $comment->comment_ID, 'akismet_user_result', true);
328
  $comment_status = wp_get_comment_status( $comment->comment_ID );
329
  $desc = null;
330
- if ( !$user_result || $user_result == $akismet_result ) {
 
 
331
  // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same
332
  if ( $akismet_result == 'true' && $comment_status != 'spam' && $comment_status != 'trash' )
333
  $desc = __( 'Flagged as spam by Akismet' );
@@ -346,8 +375,12 @@ function akismet_comment_row_action( $a, $comment ) {
346
  $b = array();
347
  foreach ( $a as $k => $item ) {
348
  $b[ $k ] = $item;
349
- if ( $k == 'edit' )
 
 
 
350
  $b['history'] = '<a href="comment.php?action=editcomment&amp;c='.$comment->comment_ID.'#akismet-status" title="'. esc_attr__( 'View comment history' ) . '"> '. __('History') . '</a>';
 
351
  }
352
 
353
  $a = $b;
@@ -436,11 +469,6 @@ add_filter('comment_text', 'akismet_text_add_link_class');
436
  function akismet_rightnow() {
437
  global $submenu, $wp_db_version;
438
 
439
- // clean_url was deprecated in WP 3.0
440
- $esc_url = 'clean_url';
441
- if ( function_exists( 'esc_url' ) )
442
- $esc_url = 'esc_url';
443
-
444
  if ( 8645 < $wp_db_version ) // 2.7
445
  $link = 'edit-comments.php?comment_status=spam';
446
  elseif ( isset( $submenu['edit-comments.php'] ) )
@@ -458,14 +486,15 @@ function akismet_rightnow() {
458
  $intro = sprintf( __('<a href="%1$s">Akismet</a> blocks spam from getting to your blog. '), 'http://akismet.com/?return=true' );
459
  }
460
 
 
461
  if ( $queue_count = akismet_spam_count() ) {
462
  $queue_text = sprintf( _n(
463
  'There\'s <a href="%2$s">%1$s comment</a> in your spam queue right now.',
464
  'There are <a href="%2$s">%1$s comments</a> in your spam queue right now.',
465
  $queue_count
466
- ), number_format_i18n( $queue_count ), $esc_url($link) );
467
  } else {
468
- $queue_text = sprintf( __( "There's nothing in your <a href='%1\$s'>spam queue</a> at the moment." ), $esc_url($link) );
469
  }
470
 
471
  $text = $intro . '<br />' . $queue_text;
@@ -605,6 +634,10 @@ function akismet_transition_comment_status( $new_status, $old_status, $comment )
605
 
606
  if ( defined('WP_IMPORTING') && WP_IMPORTING == true )
607
  return;
 
 
 
 
608
 
609
  global $current_user;
610
  $reporter = '';
@@ -625,8 +658,7 @@ function akismet_transition_comment_status( $new_status, $old_status, $comment )
625
  }
626
  }
627
 
628
- if ( !get_comment_meta( $comment->comment_ID, 'akismet_rechecking' ) )
629
- akismet_update_comment_history( $comment->comment_ID, sprintf( __('%s changed the comment status to %s'), $reporter, $new_status ), 'status-' . $new_status );
630
  }
631
 
632
  add_action( 'transition_comment_status', 'akismet_transition_comment_status', 10, 3 );
@@ -661,6 +693,8 @@ function akismet_spam_count( $type = false ) {
661
  function akismet_recheck_queue() {
662
  global $wpdb, $akismet_api_host, $akismet_api_port;
663
 
 
 
664
  if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) )
665
  return;
666
 
@@ -687,21 +721,25 @@ function akismet_recheck_queue() {
687
  foreach ( $c as $key => $data )
688
  $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
689
 
 
690
  $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
691
  if ( 'true' == $response[1] ) {
692
  wp_set_comment_status($c['comment_ID'], 'spam');
693
  update_comment_meta( $c['comment_ID'], 'akismet_result', 'true' );
 
694
  akismet_update_comment_history( $c['comment_ID'], __('Akismet re-checked and caught this comment as spam'), 'check-spam' );
695
 
696
  } elseif ( 'false' == $response[1] ) {
697
  update_comment_meta( $c['comment_ID'], 'akismet_result', 'false' );
 
698
  akismet_update_comment_history( $c['comment_ID'], __('Akismet re-checked and cleared this comment'), 'check-ham' );
699
  // abnormal result: error
700
  } else {
701
  update_comment_meta( $c['comment_ID'], 'akismet_result', 'error' );
702
- akismet_update_comment_history( $c['comment_ID'], sprintf( __('Akismet was unable to re-check this comment (response: %s)'), $response[1]), 'check-error' );
703
  }
704
 
 
705
  }
706
  wp_safe_redirect( $_SERVER['HTTP_REFERER'] );
707
  exit;
125
  if ( $key_status == 'valid' ) {
126
  $ms[] = 'key_valid';
127
  } else if ( $key_status == 'invalid' ) {
128
+ $ms[] = 'key_invalid';
 
129
  } else if ( !empty($key) && $key_status == 'failed' ) {
130
  $ms[] = 'key_failed';
131
  }
139
  'no_connection' => array('color' => '888', 'text' => __('There was a problem connecting to the Akismet server. Please check your server configuration.')),
140
  'key_empty' => array('color' => 'aa0', 'text' => sprintf(__('Please enter an API key. (<a href="%s" style="color:#fff">Get your key.</a>)'), 'http://akismet.com/get/?return=true')),
141
  'key_valid' => array('color' => '4AB915', 'text' => __('This key is valid.')),
142
+ 'key_invalid' => array('color' => '888', 'text' => __('This key is invalid.')),
143
  'key_failed' => array('color' => 'aa0', 'text' => __('The key below was previously validated but a connection to akismet.com can not be established at this time. Please check your server configuration.')),
144
  'bad_home_url' => array('color' => '888', 'text' => sprintf( __('Your WordPress home URL %s is invalid. Please fix the <a href="%s">home option</a>.'), esc_html( get_bloginfo('url') ), admin_url('options.php#home') ) ),
145
  );
291
  add_action('activity_box_end', 'akismet_stats');
292
 
293
  function akismet_admin_warnings() {
294
+ global $wpcom_api_key, $pagenow;
295
+
296
+ if (
297
+ $pagenow == 'edit-comments.php'
298
+ || ( !empty( $_GET['page'] ) && $_GET['page'] == 'akismet-key-config' )
299
+ || ( !empty( $_GET['page'] ) && $_GET['page'] == 'akismet-stats-display' )
300
+ ) {
301
+ if ( get_option( 'akismet_alert_code' ) ) {
302
+ function akismet_alert() {
303
+ $alert = array(
304
+ 'code' => (int) get_option( 'akismet_alert_code' ),
305
+ 'msg' => get_option( 'akismet_alert_msg' )
306
+ );
307
+ ?>
308
+ <div class='error'>
309
+ <p><strong>Akismet Error Code: <?php echo $alert['code']; ?></strong></p>
310
+ <p><?php esc_html_e( $alert['msg'] ); ?></p>
311
+ <p>More information is available at <a href="https://akismet.com/errors/<?php echo $alert['code']; ?>">https://akismet.com/errors/<?php echo $alert['code']; ?></a></p>
312
+ </div>
313
+ <?php
314
+ }
315
+
316
+ add_action( 'admin_notices', 'akismet_alert' );
317
+ }
318
+ }
319
+
320
  if ( !get_option('wordpress_api_key') && !$wpcom_api_key && !isset($_POST['submit']) ) {
321
  function akismet_warning() {
322
  echo "
328
  } elseif ( ( empty($_SERVER['SCRIPT_FILENAME']) || basename($_SERVER['SCRIPT_FILENAME']) == 'edit-comments.php' ) && wp_next_scheduled('akismet_schedule_cron_recheck') ) {
329
  function akismet_warning() {
330
  global $wpdb;
331
+ akismet_fix_scheduled_recheck();
332
  $waiting = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" ) );
333
+ $next_check = wp_next_scheduled('akismet_schedule_cron_recheck');
334
+ if ( $waiting > 0 && $next_check > time() )
335
  echo "
336
+ <div id='akismet-warning' class='updated fade'><p><strong>".__('Akismet has detected a problem.')."</strong> ".sprintf(__('Some comments have not yet been checked for spam by Akismet. They have been temporarily held for moderation. Please check your <a href="%s">Akismet configuration</a> and contact your web host if problems persist.'), 'admin.php?page=akismet-key-config')."</p></div>
337
  ";
338
  }
339
  add_action('admin_notices', 'akismet_warning');
350
  return $a;
351
 
352
  $akismet_result = get_comment_meta( $comment->comment_ID, 'akismet_result', true );
353
+ $akismet_error = get_comment_meta( $comment->comment_ID, 'akismet_error', true );
354
  $user_result = get_comment_meta( $comment->comment_ID, 'akismet_user_result', true);
355
  $comment_status = wp_get_comment_status( $comment->comment_ID );
356
  $desc = null;
357
+ if ( $akismet_error ) {
358
+ $desc = __( 'Awaiting spam check' );
359
+ } elseif ( !$user_result || $user_result == $akismet_result ) {
360
  // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same
361
  if ( $akismet_result == 'true' && $comment_status != 'spam' && $comment_status != 'trash' )
362
  $desc = __( 'Flagged as spam by Akismet' );
375
  $b = array();
376
  foreach ( $a as $k => $item ) {
377
  $b[ $k ] = $item;
378
+ if (
379
+ $k == 'edit'
380
+ || ( $k == 'unspam' && $GLOBALS['wp_version'] >= 3.4 )
381
+ ) {
382
  $b['history'] = '<a href="comment.php?action=editcomment&amp;c='.$comment->comment_ID.'#akismet-status" title="'. esc_attr__( 'View comment history' ) . '"> '. __('History') . '</a>';
383
+ }
384
  }
385
 
386
  $a = $b;
469
  function akismet_rightnow() {
470
  global $submenu, $wp_db_version;
471
 
 
 
 
 
 
472
  if ( 8645 < $wp_db_version ) // 2.7
473
  $link = 'edit-comments.php?comment_status=spam';
474
  elseif ( isset( $submenu['edit-comments.php'] ) )
486
  $intro = sprintf( __('<a href="%1$s">Akismet</a> blocks spam from getting to your blog. '), 'http://akismet.com/?return=true' );
487
  }
488
 
489
+ $link = function_exists( 'esc_url' ) ? esc_url( $link ) : clean_url( $link );
490
  if ( $queue_count = akismet_spam_count() ) {
491
  $queue_text = sprintf( _n(
492
  'There\'s <a href="%2$s">%1$s comment</a> in your spam queue right now.',
493
  'There are <a href="%2$s">%1$s comments</a> in your spam queue right now.',
494
  $queue_count
495
+ ), number_format_i18n( $queue_count ), $link );
496
  } else {
497
+ $queue_text = sprintf( __( "There's nothing in your <a href='%1\$s'>spam queue</a> at the moment." ), $link );
498
  }
499
 
500
  $text = $intro . '<br />' . $queue_text;
634
 
635
  if ( defined('WP_IMPORTING') && WP_IMPORTING == true )
636
  return;
637
+
638
+ // if this is present, it means the status has been changed by a re-check, not an explicit user action
639
+ if ( get_comment_meta( $comment->comment_ID, 'akismet_rechecking' ) )
640
+ return;
641
 
642
  global $current_user;
643
  $reporter = '';
658
  }
659
  }
660
 
661
+ akismet_update_comment_history( $comment->comment_ID, sprintf( __('%s changed the comment status to %s'), $reporter, $new_status ), 'status-' . $new_status );
 
662
  }
663
 
664
  add_action( 'transition_comment_status', 'akismet_transition_comment_status', 10, 3 );
693
  function akismet_recheck_queue() {
694
  global $wpdb, $akismet_api_host, $akismet_api_port;
695
 
696
+ akismet_fix_scheduled_recheck();
697
+
698
  if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) )
699
  return;
700
 
721
  foreach ( $c as $key => $data )
722
  $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
723
 
724
+ add_comment_meta( $c['comment_ID'], 'akismet_rechecking', true );
725
  $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
726
  if ( 'true' == $response[1] ) {
727
  wp_set_comment_status($c['comment_ID'], 'spam');
728
  update_comment_meta( $c['comment_ID'], 'akismet_result', 'true' );
729
+ delete_comment_meta( $c['comment_ID'], 'akismet_error' );
730
  akismet_update_comment_history( $c['comment_ID'], __('Akismet re-checked and caught this comment as spam'), 'check-spam' );
731
 
732
  } elseif ( 'false' == $response[1] ) {
733
  update_comment_meta( $c['comment_ID'], 'akismet_result', 'false' );
734
+ delete_comment_meta( $c['comment_ID'], 'akismet_error' );
735
  akismet_update_comment_history( $c['comment_ID'], __('Akismet re-checked and cleared this comment'), 'check-ham' );
736
  // abnormal result: error
737
  } else {
738
  update_comment_meta( $c['comment_ID'], 'akismet_result', 'error' );
739
+ akismet_update_comment_history( $c['comment_ID'], sprintf( __('Akismet was unable to re-check this comment (response: %s)'), substr($response[1], 0, 50)), 'check-error' );
740
  }
741
 
742
+ delete_comment_meta( $c['comment_ID'], 'akismet_rechecking' );
743
  }
744
  wp_safe_redirect( $_SERVER['HTTP_REFERER'] );
745
  exit;
akismet.js CHANGED
@@ -104,3 +104,9 @@ jQuery.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a
104
  }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
105
  o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;}
106
  });
 
 
 
 
 
 
104
  }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
105
  o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;}
106
  });
107
+ // Preload mshot images after everything else has loaded
108
+ jQuery(window).load(function() {
109
+ jQuery('a[id^="author_comment_url"]').each(function () {
110
+ jQuery.get('http://s.wordpress.com/mshots/v1/'+jQuery.URLEncode(jQuery(this).attr('href'))+'?w=450');
111
+ });
112
+ });
akismet.php CHANGED
@@ -6,7 +6,7 @@
6
  Plugin Name: Akismet
7
  Plugin URI: http://akismet.com/?return=true
8
  Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from comment and trackback spam</strong>. It keeps your site protected from spam even while you sleep. To get started: 1) Click the "Activate" link to the left of this description, 2) <a href="http://akismet.com/get/?return=true">Sign up for an Akismet API key</a>, and 3) Go to your <a href="admin.php?page=akismet-key-config">Akismet configuration</a> page, and save your API key.
9
- Version: 2.5.5
10
  Author: Automattic
11
  Author URI: http://automattic.com/wordpress-plugins/
12
  License: GPLv2 or later
@@ -28,7 +28,7 @@ along with this program; if not, write to the Free Software
28
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29
  */
30
 
31
- define('AKISMET_VERSION', '2.5.5');
32
  define('AKISMET_PLUGIN_URL', plugin_dir_url( __FILE__ ));
33
 
34
  /** If you hardcode a WP.com API key here, all key config screens will be hidden */
@@ -70,12 +70,33 @@ function akismet_get_key() {
70
  return get_option('wordpress_api_key');
71
  }
72
 
73
- function akismet_verify_key( $key, $ip = null ) {
74
  global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
75
  $blog = urlencode( get_option('home') );
76
  if ( $wpcom_api_key )
77
  $key = $wpcom_api_key;
78
  $response = akismet_http_post("key=$key&blog=$blog", 'rest.akismet.com', '/1.1/verify-key', $akismet_api_port, $ip);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  if ( !is_array($response) || !isset($response[1]) || $response[1] != 'valid' && $response[1] != 'invalid' )
80
  return 'failed';
81
  return $response[1];
@@ -280,7 +301,7 @@ function akismet_auto_check_update_meta( $id, $comment ) {
280
  // abnormal result: error
281
  } else {
282
  update_comment_meta( $comment->comment_ID, 'akismet_error', time() );
283
- akismet_update_comment_history( $comment->comment_ID, sprintf( __('Akismet was unable to check this comment (response: %s), will automatically retry again later.'), $akismet_last_comment['akismet_result']), 'check-error' );
284
  }
285
 
286
  // record the complete original data as submitted for checking
@@ -349,6 +370,7 @@ function akismet_auto_check_comment( $commentdata ) {
349
  $commentdata['comment_as_submitted'] = $comment;
350
 
351
  $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
 
352
  $commentdata['akismet_result'] = $response[1];
353
  if ( 'true' == $response[1] ) {
354
  // akismet_spam_count will be incremented later by akismet_result_spam()
@@ -371,10 +393,12 @@ function akismet_auto_check_comment( $commentdata ) {
371
 
372
  // if the response is neither true nor false, hold the comment for moderation and schedule a recheck
373
  if ( 'true' != $response[1] && 'false' != $response[1] ) {
374
- if ( !wp_get_current_user() ) {
375
  add_filter('pre_comment_approved', 'akismet_result_hold');
376
  }
377
- wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
 
 
378
  }
379
 
380
  if ( function_exists('wp_next_scheduled') && function_exists('wp_schedule_event') ) {
@@ -386,6 +410,8 @@ function akismet_auto_check_comment( $commentdata ) {
386
  akismet_delete_old();
387
  }
388
  $akismet_last_comment = $commentdata;
 
 
389
  return $commentdata;
390
  }
391
 
@@ -478,6 +504,13 @@ function akismet_check_db_comment( $id, $recheck_reason = 'recheck_queue' ) {
478
  function akismet_cron_recheck() {
479
  global $wpdb;
480
 
 
 
 
 
 
 
 
481
  delete_option('akismet_available_servers');
482
 
483
  $comment_errors = $wpdb->get_col( "
@@ -488,8 +521,9 @@ function akismet_cron_recheck() {
488
  " );
489
 
490
  foreach ( (array) $comment_errors as $comment_id ) {
491
- // if the comment no longer exists, remove the meta entry from the queue to avoid getting stuck
492
- if ( !get_comment( $comment_id ) ) {
 
493
  delete_comment_meta( $comment_id, 'akismet_error' );
494
  continue;
495
  }
@@ -528,6 +562,7 @@ function akismet_cron_recheck() {
528
  wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
529
  return;
530
  }
 
531
  }
532
 
533
  $remaining = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" ) );
@@ -548,8 +583,26 @@ $akismet_comment_nonce_option = apply_filters( 'akismet_comment_nonce', get_opti
548
  if ( $akismet_comment_nonce_option == 'true' || $akismet_comment_nonce_option == '' )
549
  add_action( 'comment_form', 'akismet_add_comment_nonce' );
550
 
 
551
  if ( '3.0.5' == $wp_version ) {
552
  remove_filter( 'comment_text', 'wp_kses_data' );
553
  if ( is_admin() )
554
  add_filter( 'comment_text', 'wp_kses_post' );
555
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  Plugin Name: Akismet
7
  Plugin URI: http://akismet.com/?return=true
8
  Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from comment and trackback spam</strong>. It keeps your site protected from spam even while you sleep. To get started: 1) Click the "Activate" link to the left of this description, 2) <a href="http://akismet.com/get/?return=true">Sign up for an Akismet API key</a>, and 3) Go to your <a href="admin.php?page=akismet-key-config">Akismet configuration</a> page, and save your API key.
9
+ Version: 2.5.6
10
  Author: Automattic
11
  Author URI: http://automattic.com/wordpress-plugins/
12
  License: GPLv2 or later
28
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29
  */
30
 
31
+ define('AKISMET_VERSION', '2.5.6');
32
  define('AKISMET_PLUGIN_URL', plugin_dir_url( __FILE__ ));
33
 
34
  /** If you hardcode a WP.com API key here, all key config screens will be hidden */
70
  return get_option('wordpress_api_key');
71
  }
72
 
73
+ function akismet_check_key_status( $key, $ip = null ) {
74
  global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
75
  $blog = urlencode( get_option('home') );
76
  if ( $wpcom_api_key )
77
  $key = $wpcom_api_key;
78
  $response = akismet_http_post("key=$key&blog=$blog", 'rest.akismet.com', '/1.1/verify-key', $akismet_api_port, $ip);
79
+ return $response;
80
+ }
81
+
82
+ // given a response from an API call like akismet_check_key_status(), update the alert code options if an alert is present.
83
+ function akismet_update_alert( $response ) {
84
+ $code = $msg = null;
85
+ if ( isset($response[0]['x-akismet-alert-code']) ) {
86
+ $code = $response[0]['x-akismet-alert-code'];
87
+ $msg = $response[0]['x-akismet-alert-msg'];
88
+ }
89
+
90
+ // only call update_option() if the value has changed
91
+ if ( $code != get_option( 'akismet_alert_code' ) ) {
92
+ update_option( 'akismet_alert_code', $code );
93
+ update_option( 'akismet_alert_msg', $msg );
94
+ }
95
+ }
96
+
97
+ function akismet_verify_key( $key, $ip = null ) {
98
+ $response = akismet_check_key_status( $key, $ip );
99
+ akismet_update_alert( $response );
100
  if ( !is_array($response) || !isset($response[1]) || $response[1] != 'valid' && $response[1] != 'invalid' )
101
  return 'failed';
102
  return $response[1];
301
  // abnormal result: error
302
  } else {
303
  update_comment_meta( $comment->comment_ID, 'akismet_error', time() );
304
+ akismet_update_comment_history( $comment->comment_ID, sprintf( __('Akismet was unable to check this comment (response: %s), will automatically retry again later.'), substr($akismet_last_comment['akismet_result'], 0, 50)), 'check-error' );
305
  }
306
 
307
  // record the complete original data as submitted for checking
370
  $commentdata['comment_as_submitted'] = $comment;
371
 
372
  $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
373
+ akismet_update_alert( $response );
374
  $commentdata['akismet_result'] = $response[1];
375
  if ( 'true' == $response[1] ) {
376
  // akismet_spam_count will be incremented later by akismet_result_spam()
393
 
394
  // if the response is neither true nor false, hold the comment for moderation and schedule a recheck
395
  if ( 'true' != $response[1] && 'false' != $response[1] ) {
396
+ if ( !current_user_can('moderate_comments') ) {
397
  add_filter('pre_comment_approved', 'akismet_result_hold');
398
  }
399
+ if ( !wp_next_scheduled( 'akismet_schedule_cron_recheck' ) ) {
400
+ wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
401
+ }
402
  }
403
 
404
  if ( function_exists('wp_next_scheduled') && function_exists('wp_schedule_event') ) {
410
  akismet_delete_old();
411
  }
412
  $akismet_last_comment = $commentdata;
413
+
414
+ akismet_fix_scheduled_recheck();
415
  return $commentdata;
416
  }
417
 
504
  function akismet_cron_recheck() {
505
  global $wpdb;
506
 
507
+ $status = akismet_verify_key( akismet_get_key() );
508
+ if ( get_option( 'akismet_alert_code' ) || $status == 'invalid' ) {
509
+ // since there is currently a problem with the key, reschedule a check for 6 hours hence
510
+ wp_schedule_single_event( time() + 21600, 'akismet_schedule_cron_recheck' );
511
+ return false;
512
+ }
513
+
514
  delete_option('akismet_available_servers');
515
 
516
  $comment_errors = $wpdb->get_col( "
521
  " );
522
 
523
  foreach ( (array) $comment_errors as $comment_id ) {
524
+ // if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck
525
+ $comment = get_comment( $comment_id );
526
+ if ( !$comment || strtotime( $comment->comment_date_gmt ) < strtotime( "-15 days" ) ) {
527
  delete_comment_meta( $comment_id, 'akismet_error' );
528
  continue;
529
  }
562
  wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
563
  return;
564
  }
565
+ delete_comment_meta( $comment_id, 'akismet_rechecking' );
566
  }
567
 
568
  $remaining = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" ) );
583
  if ( $akismet_comment_nonce_option == 'true' || $akismet_comment_nonce_option == '' )
584
  add_action( 'comment_form', 'akismet_add_comment_nonce' );
585
 
586
+ global $wp_version;
587
  if ( '3.0.5' == $wp_version ) {
588
  remove_filter( 'comment_text', 'wp_kses_data' );
589
  if ( is_admin() )
590
  add_filter( 'comment_text', 'wp_kses_post' );
591
  }
592
+
593
+ function akismet_fix_scheduled_recheck() {
594
+ $future_check = wp_next_scheduled( 'akismet_schedule_cron_recheck' );
595
+ if ( !$future_check ) {
596
+ return;
597
+ }
598
+
599
+ if ( get_option( 'akismet_alert_code' ) > 0 ) {
600
+ return;
601
+ }
602
+
603
+ $check_range = time() + 1200;
604
+ if ( $future_check > $check_range ) {
605
+ wp_clear_scheduled_hook( 'akismet_schedule_cron_recheck' );
606
+ wp_schedule_single_event( time() + 300, 'akismet_schedule_cron_recheck' );
607
+ }
608
+ }
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: matt, ryan, andy, mdawaffe, tellyworth, josephscott, lessbloat, automattic
3
  Tags: akismet, comments, spam
4
  Requires at least: 3.0
5
- Tested up to: 3.3.1
6
- Stable tag: 2.5.5
7
  License: GPLv2 or later
8
 
9
  Akismet checks your comments against the Akismet web service to see if they look like spam or not.
@@ -31,6 +31,17 @@ Upload the Akismet plugin to your blog, Activate it, then enter your [Akismet.co
31
 
32
  == Changelog ==
33
 
 
 
 
 
 
 
 
 
 
 
 
34
  = 2.5.5 =
35
  * Add nonce check for comment author URL remove action
36
  * Fix the settings link
2
  Contributors: matt, ryan, andy, mdawaffe, tellyworth, josephscott, lessbloat, automattic
3
  Tags: akismet, comments, spam
4
  Requires at least: 3.0
5
+ Tested up to: 3.4
6
+ Stable tag: 2.5.6
7
  License: GPLv2 or later
8
 
9
  Akismet checks your comments against the Akismet web service to see if they look like spam or not.
31
 
32
  == Changelog ==
33
 
34
+ = 2.5.6 =
35
+ * Prevent retry scheduling problems on sites where wp_cron is misbehaving
36
+ * Preload mshot previews
37
+ * Modernize the widget code
38
+ * Fix a bug where comments were not held for moderation during an error condition
39
+ * Improve the UX and display when comments are temporarily held due to an error
40
+ * Make the Check For Spam button force a retry when comments are held due to an error
41
+ * Handle errors caused by an invalid key
42
+ * Don't retry comments that are too old
43
+ * Improve error messages when verifying an API key
44
+
45
  = 2.5.5 =
46
  * Add nonce check for comment author URL remove action
47
  * Fix the settings link
widget.php CHANGED
@@ -2,89 +2,107 @@
2
  /**
3
  * @package Akismet
4
  */
5
- // Widget stuff
6
- function widget_akismet_register() {
7
- if ( function_exists('register_sidebar_widget') ) :
8
- function widget_akismet($args) {
9
- extract($args);
10
- $options = get_option('widget_akismet');
11
- $count = get_option('akismet_spam_count');
12
- ?>
13
- <?php echo $before_widget; ?>
14
- <?php echo $before_title . $options['title'] . $after_title; ?>
15
- <div id="akismetwrap"><div id="akismetstats"><a id="aka" href="http://akismet.com" title=""><?php printf( _n( '%1$s%2$s%3$s %4$sspam comment%5$s %6$sblocked by%7$s<br />%8$sAkismet%9$s', '%1$s%2$s%3$s %4$sspam comments%5$s %6$sblocked by%7$s<br />%8$sAkismet%9$s', $count ), '<span id="akismet1"><span id="akismetcount">', number_format_i18n( $count ), '</span>', '<span id="akismetsc">', '</span></span>', '<span id="akismet2"><span id="akismetbb">', '</span>', '<span id="akismeta">', '</span></span>' ); ?></a></div></div>
16
- <?php echo $after_widget; ?>
17
- <?php
18
  }
19
 
20
- function widget_akismet_style() {
21
- $plugin_dir = '/wp-content/plugins';
22
- if ( defined( 'PLUGINDIR' ) )
23
- $plugin_dir = '/' . PLUGINDIR;
24
 
25
- ?>
26
  <style type="text/css">
27
- #aka,#aka:link,#aka:hover,#aka:visited,#aka:active{color:#fff;text-decoration:none}
28
- #aka:hover{border:none;text-decoration:none}
29
- #aka:hover #akismet1{display:none}
30
- #aka:hover #akismet2,#akismet1{display:block}
31
- #akismet2{display:none;padding-top:2px}
32
- #akismeta{font-size:16px;font-weight:bold;line-height:18px;text-decoration:none}
33
- #akismetcount{display:block;font:15px Verdana,Arial,Sans-Serif;font-weight:bold;text-decoration:none}
34
- #akismetwrap #akismetstats{background:url(<?php echo get_option('siteurl'), $plugin_dir; ?>/akismet/akismet.gif) no-repeat top left;border:none;color:#fff;font:11px 'Trebuchet MS','Myriad Pro',sans-serif;height:40px;line-height:100%;overflow:hidden;padding:8px 0 0;text-align:center;width:120px}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  </style>
36
- <?php
 
37
  }
38
 
39
- function widget_akismet_control() {
40
- $options = $newoptions = get_option('widget_akismet');
41
- if ( isset( $_POST['akismet-submit'] ) && $_POST["akismet-submit"] ) {
42
- $newoptions['title'] = strip_tags(stripslashes($_POST["akismet-title"]));
43
- if ( empty($newoptions['title']) ) $newoptions['title'] = __('Spam Blocked');
44
  }
45
- if ( $options != $newoptions ) {
46
- $options = $newoptions;
47
- update_option('widget_akismet', $options);
48
  }
49
- $title = htmlspecialchars($options['title'], ENT_QUOTES);
50
- ?>
51
- <p><label for="akismet-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="akismet-title" name="akismet-title" type="text" value="<?php echo $title; ?>" /></label></p>
52
- <input type="hidden" id="akismet-submit" name="akismet-submit" value="1" />
53
- <?php
54
- }
55
 
56
- if ( function_exists( 'wp_register_sidebar_widget' ) ) {
57
- wp_register_sidebar_widget( 'akismet', 'Akismet', 'widget_akismet', null, 'akismet');
58
- wp_register_widget_control( 'akismet', 'Akismet', 'widget_akismet_control', null, 75, 'akismet');
59
- } else {
60
- register_sidebar_widget('Akismet', 'widget_akismet', null, 'akismet');
61
- register_widget_control('Akismet', 'widget_akismet_control', null, 75, 'akismet');
62
  }
63
- if ( is_active_widget('widget_akismet') )
64
- add_action('wp_head', 'widget_akismet_style');
65
- endif;
66
- }
67
 
68
- add_action('init', 'widget_akismet_register');
 
 
 
69
 
70
- // Counter for non-widget users
71
- function akismet_counter() {
72
- $plugin_dir = '/wp-content/plugins';
73
- if ( defined( 'PLUGINDIR' ) )
74
- $plugin_dir = '/' . PLUGINDIR;
75
 
 
 
 
 
 
 
76
  ?>
77
- <style type="text/css">
78
- #akismetwrap #aka,#aka:link,#aka:hover,#aka:visited,#aka:active{color:#fff;text-decoration:none}
79
- #aka:hover{border:none;text-decoration:none}
80
- #aka:hover #akismet1{display:none}
81
- #aka:hover #akismet2,#akismet1{display:block}
82
- #akismet2{display:none;padding-top:2px}
83
- #akismeta{font-size:16px;font-weight:bold;line-height:18px;text-decoration:none}
84
- #akismetcount{display:block;font:15px Verdana,Arial,Sans-Serif;font-weight:bold;text-decoration:none}
85
- #akismetwrap #akismetstats{background:url(<?php echo get_option('siteurl'), $plugin_dir; ?>/akismet/akismet.gif) no-repeat top left;border:none;color:#fff;font:11px 'Trebuchet MS','Myriad Pro',sans-serif;height:40px;line-height:100%;overflow:hidden;padding:8px 0 0;text-align:center;width:120px}
86
- </style>
87
  <?php
88
- $count = get_option('akismet_spam_count');
89
- printf( _n( '<div id="akismetwrap"><div id="akismetstats"><a id="aka" href="http://akismet.com" title=""><div id="akismet1"><span id="akismetcount">%1$s</span> <span id="akismetsc">spam comment</span></div> <div id="akismet2"><span id="akismetbb">blocked by</span><br /><span id="akismeta">Akismet</span></div></a></div></div>', '<div id="akismetwrap"><div id="akismetstats"><a id="aka" href="http://akismet.com" title=""><div id="akismet1"><span id="akismetcount">%1$s</span> <span id="akismetsc">spam comments</span></div> <div id="akismet2"><span id="akismetbb">blocked by</span><br /><span id="akismeta">Akismet</span></div></a></div></div>', $count ), number_format_i18n( $count ) );
90
  }
 
 
 
 
 
 
2
  /**
3
  * @package Akismet
4
  */
5
+ class Akismet_Widget extends WP_Widget {
6
+
7
+ function __construct() {
8
+ parent::__construct(
9
+ 'akismet_widget',
10
+ __( 'Akismet Widget' ),
11
+ array( 'description' => __( 'Display the number of spam comments Akismet has caught' ) )
12
+ );
13
+
14
+ if ( is_active_widget( false, false, $this->id_base ) ) {
15
+ add_action( 'wp_head', array( $this, 'css' ) );
16
+ }
 
17
  }
18
 
19
+ function css() {
20
+ ?>
 
 
21
 
 
22
  <style type="text/css">
23
+ .a-stats {
24
+ width: auto;
25
+ }
26
+ .a-stats a {
27
+ background: #7CA821;
28
+ background-image:-moz-linear-gradient(0% 100% 90deg,#5F8E14,#7CA821);
29
+ background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#7CA821),to(#5F8E14));
30
+ border: 1px solid #5F8E14;
31
+ border-radius:3px;
32
+ color: #CFEA93;
33
+ cursor: pointer;
34
+ display: block;
35
+ font-weight: normal;
36
+ height: 100%;
37
+ -moz-border-radius:3px;
38
+ padding: 7px 0 8px;
39
+ text-align: center;
40
+ text-decoration: none;
41
+ -webkit-border-radius:3px;
42
+ width: 100%;
43
+ }
44
+ .a-stats a:hover {
45
+ text-decoration: none;
46
+ background-image:-moz-linear-gradient(0% 100% 90deg,#6F9C1B,#659417);
47
+ background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#659417),to(#6F9C1B));
48
+ }
49
+ .a-stats .count {
50
+ color: #FFF;
51
+ display: block;
52
+ font-size: 15px;
53
+ line-height: 16px;
54
+ padding: 0 13px;
55
+ white-space: nowrap;
56
+ }
57
  </style>
58
+
59
+ <?php
60
  }
61
 
62
+ function form( $instance ) {
63
+ if ( $instance ) {
64
+ $title = esc_attr( $instance['title'] );
 
 
65
  }
66
+ else {
67
+ $title = __( 'Spam Blocked' );
 
68
  }
69
+ ?>
 
 
 
 
 
70
 
71
+ <p>
72
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
73
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
74
+ </p>
75
+
76
+ <?php
77
  }
 
 
 
 
78
 
79
+ function update( $new_instance, $old_instance ) {
80
+ $instance['title'] = strip_tags( $new_instance['title'] );
81
+ return $instance;
82
+ }
83
 
84
+ function widget( $args, $instance ) {
85
+ $count = get_option( 'akismet_spam_count' );
 
 
 
86
 
87
+ echo $args['before_widget'];
88
+ if ( ! empty( $instance['title'] ) ) {
89
+ echo $args['before_title'];
90
+ echo esc_html( $instance['title'] );
91
+ echo $args['after_title'];
92
+ }
93
  ?>
94
+
95
+ <div class="a-stats">
96
+ <a href="http://akismet.com" target="_blank" title=""><?php printf( _n( '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>', '<strong class="count">%1$s spam</strong> blocked by <strong>Akismet</strong>', $count ), number_format_i18n( $count ) ); ?></a>
97
+ </div>
98
+
 
 
 
 
 
99
  <?php
100
+ echo $args['after_widget'];
101
+ }
102
  }
103
+
104
+ function akismet_register_widgets() {
105
+ register_widget( 'Akismet_Widget' );
106
+ }
107
+
108
+ add_action( 'widgets_init', 'akismet_register_widgets' );