Skip to content

Commit

Permalink
Merge pull request #1242 from xwp/bugfix/records-exclude-rules
Browse files Browse the repository at this point in the history
"Log::record_matches_rules()" refactored.
  • Loading branch information
kidunot89 authored Mar 26, 2021
2 parents 0d0f7fc + 157e879 commit 2c05fb5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions classes/class-log.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,23 +242,25 @@ public function is_record_excluded( $connector, $context, $action, $user = null,
* @return boolean
*/
public function record_matches_rules( $record, $exclude_rules ) {
$matches_needed = count( $exclude_rules );
$matches_found = 0;
foreach ( $exclude_rules as $exclude_key => $exclude_value ) {
if ( ! isset( $record[ $exclude_key ] ) ) {
if ( ! isset( $record[ $exclude_key ] ) || is_null( $exclude_value ) ) {
continue;
}

if ( 'ip_address' === $exclude_key ) {
$ip_addresses = explode( ',', $exclude_value );

if ( in_array( $record['ip_address'], $ip_addresses, true ) ) {
return true;
$matches_found++;
}
} elseif ( $record[ $exclude_key ] === $exclude_value ) {
return true;
$matches_found++;
}
}

return false;
return $matches_found === $matches_needed;
}

/**
Expand Down

0 comments on commit 2c05fb5

Please sign in to comment.