Skip to content

Support Forums: Audit Log: Avoid a PHP warning when a forum role is set to the user's current role - #1092

Closed
bor0 wants to merge 2 commits into
WordPress:trunkfrom
bor0:fix/forums-audit-log-null-role
Closed

bor0 wants to merge 2 commits into
WordPress:trunkfrom
bor0:fix/forums-audit-log-null-role

Conversation

@bor0

@bor0 bor0 commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Fixes a PHP warning in the support forums audit log:

E_WARNING: Attempt to read property "name" on null in support-forums/inc/class-audit-log.php:120
Source: POST https://wordpress.org/wp-login.php?action=confirmaction
Filter stack: user_request_action_confirmed, bbp_set_user_role

Cause

bbp_set_user_role() passes false to the bbp_set_user_role filter when the user already has the requested role:

// User already has this role so no new role is set
if ( $new_role === $role ) {
    $new_role = false;

Audit_Log records the removed role in $this->last_role_change but never clears it. When the forum role is set twice for the same user in one request (which the production warning suggests happens when a personal data erasure request is confirmed; that handler isn't in this repository), the second call sees $new_role = false alongside the stale previous role from the first call. That skips the $new_role === $previous_role bail-out and reaches get_role( false )->name.

Fix

  • Clear the tracked role for the user once it's been read.
  • Bail when bbPress reports no role change.
  • Use the role slugs directly instead of get_role()->name. WP_Role::$name holds the slug, so the note text is unchanged.

Testing

On a sandbox, via wp eval-file, with note writes blocked by a throwing wporg_bbp_forum_role_changed_note_text filter:

  • Before: a stale previous role plus $new_role = false gives ErrorException: Attempt to read property "name" on null @ class-audit-log.php:120, matching production.
  • After:
    • Stale previous role + false: returns without logging.
    • A real bbp_moderator → bbp_blocked change still logs Forum role changed to bbp_blocked from bbp_moderator via wordpress.org. (same wording as before).
    • A repeat call with false after that change: returns without logging.
  • php -l passes; no new PHPCS violations.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved role-change audit records: role identifiers are used consistently, and updates with no new role are handled without processing a role change.

@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props bor0.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f51eaf17-73ce-4531-b548-473ee3841e1f
📥 Commits

Reviewing files that changed from the base of the PR and between 090ebbe and 82c235f.

📒 Files selected for processing: 1
  • wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-audit-log.php

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 26766254-48f0-40e3-a30b-11f45623eec6
📥 Commits

Reviewing files that changed from the base of the PR and between 6fc18e0 and 090ebbe.

📒 Files selected for processing: 1
  • wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-audit-log.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

📝 Walkthrough

The role update filter now clears stored role-change data on each call and returns falsey new roles immediately. Role-change notes use the new and previous role slugs.

Changes: Audit log role changes

Layer / File(s) Summary
Role update and notes
wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-audit-log.php
The filter clears the user's stored role-change data before processing. It returns immediately when the new role is falsey. Role-change notes use the new and previous role slugs.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 090eb

No actionable merge-blocking risk remains in the reviewed change.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the Support Forums audit log change and the PHP warning it prevents. It accurately summarizes the primary objective.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…et to the user's current role.

bbPress passes `false` to the `bbp_set_user_role` filter when the user already has the requested role. The previously removed role was kept for the rest of the request, so a repeat call in the same request (for example while erasing a user's personal data) skipped the no-change bail-out and called `get_role( false )->name`.

Clear the tracked role once it's been read, bail when no role was set, and use the role slugs directly, which is what `WP_Role::$name` held anyway.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bor0
bor0 force-pushed the fix/forums-audit-log-null-role branch from 6fc18e0 to 090ebbe Compare October 22, 2026 18:57
@bor0 bor0 changed the title Support Forums: Audit Log: Avoid a PHP warning when the forum role isn't registered Support Forums: Audit Log: Avoid a PHP warning when a forum role is set to the user's current role Oct 22, 2026
@bor0
bor0 deleted the fix/forums-audit-log-null-role branch October 22, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant