Fix: Store actual WordPress role instead of first user cap for role filtering - #239
Open
KingYes wants to merge 6 commits into
Open
Fix: Store actual WordPress role instead of first user cap for role filtering#239KingYes wants to merge 6 commits into
KingYes wants to merge 6 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✨ PR Description
1. Problem & Context
The plugin was incorrectly storing user capabilities by reading the first key from
$user->caps(a capability map), which could be any granted capability rather than the user's actual WordPress role. This broke role-based filtering in activity logs and caused inconsistent data storage, especially on multisite with plugins like bbPress.2. What Changed (Where)
$user->roles[0]instead ofkey($user->caps); remove bbPress fallback hack; add fallback for super_admin detectionuser_capsvalue with fallback to current role; handle missing role names gracefully$user->roles[0]for capability filtering; add role name labels to dropdown from global$wp_roles3. How It Works
User role is captured at log insertion time (
$user->roles[0]lowercased) and stored inuser_caps. On display, the presenter prefers the stored historical role but falls back to current role if missing. Query filtering matches logs by stored role against the permission matrix. Role names are now resolved from WordPress global$wp_roles->role_namesinstead of just ucwords-formatting.4. Risks
Role schema assumption: relies on
$user->roles[0]being present and meaningful. Edge case if users have no roles assigned (unlikely but handled with 'guest' fallback). Backward compatibility: existing logs with capability keys won't resolve to role names without a migration—mitigation is the fallback to current user role.Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Description using Guidelines Learn how