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

Replace strlen with custom callback that accepts null #1513

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion classes/class-log.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ public function is_record_excluded( $connector, $context, $action, $user = null,
'role' => ( ! empty( $exclude_rule['author_or_role'] ) && ! is_numeric( $exclude_rule['author_or_role'] ) ) ? $exclude_rule['author_or_role'] : null,
);

$exclude_rules = array_filter( $exclude, 'strlen' );
$exclude_rules = array_filter(
$exclude,
function ( $value ) {
return ! is_null( $value ) && '' !== $value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@delawski I am approving this but I think all we need is a check on is_null()? I'm kind of asking because I want to make sure I understand the bit above it 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I absolutely love your reviews, @tharsheblows! You're totally right about the second check (removed in 9d47e25) - in this scenario it's redundant since we are explicitly setting every empty property to null above.

One of the solutions I was considering and trying out involved setting the properties above to empty strings instead of null so that the original strlen-based solution would still work. I guess I got lost somewhere in between 😅

}
);

if ( $this->record_matches_rules( $record, $exclude_rules ) ) {
$exclude_record = true;
Expand Down
Loading