Plugin Directory

Changeset 883488

Timestamp:
03/28/2014 11:05:12 AM (10 years ago)
Author:
eoigal
Message:
  • Ignore discard header in ajax requests and where the user is logged in.
  • Drop the use of static variables to ensure comment only increments counter once, compare comment to last comment instead
File:
1 edited

Legend:

Unmodified
Added
Removed
  • akismet/trunk/class.akismet.php

    r882552 r883488  
    123123        if ( 'true' == $response[1] ) {
    124124            // akismet_spam_count will be incremented later by comment_is_spam()
    125             add_filter('pre_comment_approved', array( 'Akismet',  'comment_is_spam' ) );
    126 
    127             $discard = ( isset( $commentdata['akismet_pro_tip'] ) && $commentdata['akismet_pro_tip'] === 'discard' && get_option( 'akismet_strictness' ) === '1' );
     125            add_filter('pre_comment_approved', array( 'Akismet',  'comment_is_spam' ) );
     126
     127            $discard = ( isset( $commentdata['akismet_pro_tip'] ) && $commentdata['akismet_pro_tip'] === 'discard' && );
    128128
    129129            do_action( 'akismet_spam_caught', $discard );
     
    148148        if ( 'true' != $response[1] && 'false' != $response[1] ) {
    149149            if ( !current_user_can('moderate_comments') ) {
    150                 add_filter('pre_comment_approved', array( 'Akismet',  'comment_needs_moderation' ) );
     150                add_filter('pre_comment_approved', array( 'Akismet',  'comment_needs_moderation' ) );
    151151            }
    152152            if ( function_exists('wp_next_scheduled') && function_exists('wp_schedule_single_event') ) {
     
    187187        // as was checked by auto_check_comment
    188188        if ( is_object( $comment ) && !empty( self::$last_comment ) && is_array( self::$last_comment ) ) {
    189             if ( isset( self::$last_comment['comment_post_ID'] )
    190                 && intval( self::$last_comment['comment_post_ID'] ) == intval( $comment->comment_post_ID )
    191                 && self::$last_comment['comment_author'] == $comment->comment_author
    192                 && self::$last_comment['comment_author_email'] == $comment->comment_author_email ) {
     189            if ( self::matches_last_comment( $comment ) ) {
    193190                   
    194191                    load_plugin_textdomain( 'akismet' );
     
    443440        return defined('AKISMET_TEST_MODE') && AKISMET_TEST_MODE;
    444441    }
     442
     443
     444
     445
     446
     447
     448
     449
     450
    445451
    446452    public static function get_ip_address() {
    447453        return isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : null;
     454
     455
     456
     457
     458
     459
     460
     461
     462
     463
     464
     465
     466
     467
     468
     469
     470
     471
     472
     473
    448474    }
    449475
     
    482508
    483509    // filter handler used to return a spam result to pre_comment_approved
    484     public static function comment_is_spam( $approved ) {
    485         static $just_once = false;
    486         if ( $just_once )
     510    public static function comment_is_spam( $approved, $comment ) {
     511        // Only do this if it's the correct comment
     512        if ( !self::matches_last_comment( $comment ) ) {
     513            self::log( "comment_is_spam mismatched comment, returning unaltered $approved" );
    487514            return $approved;
     515
    488516
    489517        // bump the counter here instead of when the filter is added to reduce the possibility of overcounting
     
    491519            update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr );
    492520
    493         // this is a one-shot deal
    494         $just_once = true;
    495521        return 'spam';
    496522    }
    497523
    498     public static function comment_needs_moderation( $approved ) {
    499         static $just_once = false;
    500         if ( $just_once )
     524    public static function comment_needs_moderation( $approved ) {
     525       
     526   
    501527            return $approved;
    502 
    503         // once only
    504         $just_once = true;
    505         return '0';
     528        }   
     529        return '0';
    506530    }
    507531
Note: See TracChangeset for help on using the changeset viewer.