Skip to content

Add edac_dismiss_reasons filter to allow customizing dismiss options - #1726

Merged
SteveJonesDev merged 7 commits into
developfrom
steve/pro-632-feature-allow-dismiss-reasons-to-be-filterable-to-add-or
Jun 26, 2026
Merged

Add edac_dismiss_reasons filter to allow customizing dismiss options#1726
SteveJonesDev merged 7 commits into
developfrom
steve/pro-632-feature-allow-dismiss-reasons-to-be-filterable-to-add-or

Conversation

@SteveJonesDev

@SteveJonesDev SteveJonesDev commented May 29, 2026

Copy link
Copy Markdown
Member

Summary

  • Wraps the IgnoreUI::get_reasons() return value in apply_filters( 'edac_dismiss_reasons', ... ) so developers can add, remove, or reorder dismiss reasons without modifying core code
  • Defaults remain unchanged — no behaviour change for existing users

Usage example

add_filter( 'edac_dismiss_reasons', function( $reasons ) {
    $reasons['needs_review'] = [
        'label'       => 'Needs review',
        'description' => 'Flagged for manual review by the accessibility team.',
    ];
    unset( $reasons['remediated'] );
    return $reasons;
} );

Test plan

  • Confirm dismiss reasons appear unchanged with no filter applied
  • Add a filter that appends a custom reason and verify it appears in the dismiss UI
  • Add a filter that removes a default reason and verify it no longer appears
  • Confirm existing dismissed issues with legacy reason keys are unaffected

Closes #1511

Summary by CodeRabbit

Summary by CodeRabbit

  • Refactor

    • Dismiss reasons are now customizable via a filter, letting plugins/themes update labels and descriptions. If customization is missing, invalid, or empty, the app safely falls back to built-in default dismiss reasons.
  • Documentation

    • Updated guidance to describe the expected structure for custom dismiss reasons and the fallback behavior when customizations can’t be applied.

Wraps the dismiss reasons array in apply_filters() so developers can
add, remove, or reorder options without modifying core code.

Closes #1511

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 490b0f26-8fed-4b74-801e-3cfabf393bc8

📥 Commits

Reviewing files that changed from the base of the PR and between 475f466 and fa7b9b5.

📒 Files selected for processing (1)
  • admin/class-ignore-ui.php
💤 Files with no reviewable changes (1)
  • admin/class-ignore-ui.php

📝 Walkthrough

Walkthrough

The ignore UI dismiss reasons now pass through the edac_dismiss_reasons filter. The method documents the expected entry shape, validates filtered output, and falls back to defaults when needed.

Changes

Filterable dismiss reasons

Layer / File(s) Summary
Filter hook and docblock update
admin/class-ignore-ui.php
IgnoreUI::get_reasons() now builds default reasons, applies edac_dismiss_reasons, validates the filtered array shape, and returns defaults when the filter output is invalid or empty. The docblock now describes the filter and required label/description fields.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through reasons, neat and bright,
Filters may reshape them just right.
If forms go odd, defaults stay near,
My carrot list remains clear! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main change: adding the edac_dismiss_reasons filter for customizable dismiss options.
Linked Issues check ✅ Passed The change implements the requested filterability for dismiss reasons while preserving default behavior.
Out of Scope Changes check ✅ Passed The changes stay focused on making dismiss reasons filterable and do not introduce unrelated scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch steve/pro-632-feature-allow-dismiss-reasons-to-be-filterable-to-add-or

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the edac_dismiss_reasons filter to allow developers to customize the dismiss reasons in IgnoreUI::get_reasons(). The review feedback recommends adding defensive type checking to ensure the filtered value is an array before returning it, which prevents potential fatal TypeErrors if a filter callback returns an invalid type.

Comment thread admin/class-ignore-ui.php
SteveJonesDev and others added 3 commits May 28, 2026 20:09
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Falls back to default reasons if a filter callback returns an invalid
type, preventing a fatal TypeError from the array return type hint.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
admin/class-ignore-ui.php (1)

32-48: ⚖️ Poor tradeoff

Handle legacy dismiss reasons when edac_dismiss_reasons filters them out

  • IgnoreUI::render_reason_fieldset() only checks $current_reason against the filtered $reasons; if a stored key (e.g., remediated) is removed by edac_dismiss_reasons, no radio will be selected.
  • The React DismissPanel also builds its options from the same filtered IgnoreUI::get_reasons() payload, so the modal can similarly show no selected reason/label for legacy values.
  • admin/class-ajax.php saves $_REQUEST['reason'] after sanitization without validating against the current reasons list, so the legacy value can persist.

Consider documenting that filtered-out reasons won’t show as selected for already-dismissed issues, or add a UI fallback like “Dismissed as: ” when the stored key isn’t present in the current options.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@admin/class-ignore-ui.php` around lines 32 - 48,
IgnoreUI::render_reason_fieldset() and the React DismissPanel rely solely on the
filtered IgnoreUI::get_reasons() list so stored legacy keys removed by the
edac_dismiss_reasons filter won’t appear selected; fix by adding a fallback:
when $current_reason (or incoming saved reason in admin/class-ajax.php) is not
in IgnoreUI::get_reasons(), append a synthetic option like "legacy:<key>" with
label "Dismissed as: <key or stored label>" to the reasons payload returned by
IgnoreUI::get_reasons()/used by render_reason_fieldset() and include the same
fallback key/value in the data sent to the React DismissPanel, and additionally
validate/sanitize in admin/class-ajax.php that $_REQUEST['reason'] is either a
current key or the allowed legacy fallback before saving.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@admin/class-ignore-ui.php`:
- Around line 32-48: The edac_dismiss_reasons filter return must be validated
and sanitized before returning: in the method that builds this default (the
block returning apply_filters('edac_dismiss_reasons', [...])) call the filter
into a variable, verify it's an array, iterate each reason key/value ensuring
each value is an array with 'label' and 'description' keys that are strings; for
any missing/malformed entry fall back to the original default for that key, and
sanitize the strings (e.g., sanitize_text_field or wp_kses_post as appropriate)
before returning; this protects render_reason_fieldset() from non-array or
malformed entries and guarantees safe, expected structure.

---

Nitpick comments:
In `@admin/class-ignore-ui.php`:
- Around line 32-48: IgnoreUI::render_reason_fieldset() and the React
DismissPanel rely solely on the filtered IgnoreUI::get_reasons() list so stored
legacy keys removed by the edac_dismiss_reasons filter won’t appear selected;
fix by adding a fallback: when $current_reason (or incoming saved reason in
admin/class-ajax.php) is not in IgnoreUI::get_reasons(), append a synthetic
option like "legacy:<key>" with label "Dismissed as: <key or stored label>" to
the reasons payload returned by IgnoreUI::get_reasons()/used by
render_reason_fieldset() and include the same fallback key/value in the data
sent to the React DismissPanel, and additionally validate/sanitize in
admin/class-ajax.php that $_REQUEST['reason'] is either a current key or the
allowed legacy fallback before saving.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8cf2fbeb-4af0-4492-a1d5-35ea97a9558d

📥 Commits

Reviewing files that changed from the base of the PR and between 6986dfa and e5b4aac.

📒 Files selected for processing (1)
  • admin/class-ignore-ui.php

Comment thread admin/class-ignore-ui.php Outdated
Strip any entries missing label/description string keys rather than
returning malformed data that would cause fatal errors in render_reason_fieldset().
Falls back to defaults if the validated result is empty.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

✅ Accessibility Checker build (primary only)

@github-actions github-actions Bot removed the gha-build label Jun 2, 2026
@SteveJonesDev

Copy link
Copy Markdown
Member Author

Here is an example filter to test with.

add_filter( 'edac_dismiss_reasons', function( $reasons ) {
	// Add custom reasons.
	$reasons['needs_review'] = [
		'label'       => 'Needs review',
		'description' => 'Flagged for manual review by the accessibility team.',
	];
	$reasons['wont_fix'] = [
		'label'       => "Won't fix",
		'description' => 'Reviewed and determined not to be addressed.',
	];

	// Remove an existing reason.
	unset( $reasons['remediated'] );

	return $reasons;
} );
Screenshot 2026-06-01 at 9 32 14 PM

@SteveJonesDev
SteveJonesDev requested a review from pattonwebz June 2, 2026 01:34

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
admin/class-ignore-ui.php (1)

32-46: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Fix the parse error in admin/class-ignore-ui.php.
$default_reasons = [ is immediately followed by return [, so the method is syntactically invalid and the plugin cannot load. Remove the stray return [ and close the $default_reasons array before applying the filter.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@admin/class-ignore-ui.php` around lines 32 - 46, The method in
class-ignore-ui.php has a syntax error because $default_reasons is started and
then immediately interrupted by an unintended return array, preventing the
plugin from loading. Fix the structure in the relevant ignore-reasons method by
removing the stray return, properly closing the $default_reasons array, and then
returning the filtered/default reasons using the existing filter call and unique
symbols like $default_reasons and the ignore UI method name.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@admin/class-ignore-ui.php`:
- Around line 32-46: The method in class-ignore-ui.php has a syntax error
because $default_reasons is started and then immediately interrupted by an
unintended return array, preventing the plugin from loading. Fix the structure
in the relevant ignore-reasons method by removing the stray return, properly
closing the $default_reasons array, and then returning the filtered/default
reasons using the existing filter call and unique symbols like $default_reasons
and the ignore UI method name.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3024e466-4a3b-4848-84c3-3804e7129372

📥 Commits

Reviewing files that changed from the base of the PR and between 929760d and 475f466.

📒 Files selected for processing (1)
  • admin/class-ignore-ui.php

The merge of develop into this branch left a stray "return [" inside
the $default_reasons array literal, breaking PHP syntax and failing CI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@SteveJonesDev

Copy link
Copy Markdown
Member Author

Fixed in fa7b9b5 — removed the stray return [ left over from the merge resolution; $default_reasons now closes properly before the filter is applied. Verified with php -l.

🤖 Addressed by Claude Code

@pattonwebz pattonwebz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM :shipit:

@SteveJonesDev
SteveJonesDev merged commit 40a0b82 into develop Jun 26, 2026
21 of 22 checks passed
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.

[Feature] Allow dismiss reasons to be filterable to add or remove reasons

2 participants