Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wp_stream_is_record_excluded filter #921

Merged
merged 1 commit into from
Sep 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions classes/class-log.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ public function is_record_excluded( $connector, $context, $action, $user = null,
}
}

$exclude_record = false;

if ( isset( $exclude_settings['exclude_row'] ) && ! empty( $exclude_settings['exclude_row'] ) ) {
foreach ( $exclude_settings['exclude_row'] as $key => $value ) {
// Prepare values
Expand All @@ -217,29 +219,39 @@ public function is_record_excluded( $connector, $context, $action, $user = null,
$exclude_rules = array_filter( $exclude, 'strlen' );

if ( ! empty( $exclude_rules ) ) {
$excluded = true;
$matches_exclusion_rule = true;

foreach ( $exclude_rules as $exclude_key => $exclude_value ) {
if ( 'ip_address' === $exclude_key ) {
$ip_addresses = explode( ',', $exclude_value );
if ( ! in_array( $record['ip_address'], $ip_addresses, true ) ) {
$excluded = false;
$matches_exclusion_rule = false;
break;
}
} elseif ( $record[ $exclude_key ] !== $exclude_value ) {
$excluded = false;
$matches_exclusion_rule = false;
break;
}
}

if ( $excluded ) {
return true;
if ( $matches_exclusion_rule ) {
$exclude_record = true;
break;
}
}
}
}

return false;
/**
* Filters whether or not a record should be excluded from the log
*
* If true, the record is not logged.
*
* @param array $exclude_record Whether the record should excluded
* @param array $recordarr The record to log
*
* @return bool
*/
return apply_filters( 'wp_stream_is_record_excluded', $exclude_record, $record );
}

/**
Expand Down