Skip to content

Commit

Permalink
chore: move threshold filters in Rules.php before the loop and the …
Browse files Browse the repository at this point in the history
…score check after it
  • Loading branch information
florianbrinkmann committed Dec 15, 2023
1 parent 12d1e89 commit 0b4f8e7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Handlers/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public function apply( $item ) {
$item['reaction_type'] = $this->type;
$rules = self::get( $this->type, true );

$no_spam_threshold = (float) apply_filters( 'antispam_bee_no_spam_threshold', 0.0 );
$spam_threshold = (float) apply_filters( 'antispam_bee_spam_threshold', 0.0 );

$score = 0.0;
foreach ( $rules as $rule ) {
$rule_score = $rule::verify( $item ) * $rule::get_weight();
Expand All @@ -31,17 +34,14 @@ public function apply( $item ) {
}

$score += $rule_score;
}

$no_spam_threshold = (float) apply_filters( 'antispam_bee_no_spam_threshold', 0.0 );
$spam_threshold = (float) apply_filters( 'antispam_bee_spam_threshold', 0.0 );

if ( $no_spam_threshold < 0.0 && $score <= $no_spam_threshold ) {
return false;
}
if ( $no_spam_threshold < 0.0 && $score <= $no_spam_threshold ) {
return false;
}

if ( $spam_threshold > 0.0 && $score >= $spam_threshold ) {
return true;
}
if ( $spam_threshold > 0.0 && $score >= $spam_threshold ) {
return true;
}

return $score > 0.0;
Expand Down

0 comments on commit 0b4f8e7

Please sign in to comment.