fix: disable inactive rule checkboxes in delete-for-reasons - #853
Open
faisalahammad wants to merge 4 commits into
Open
fix: disable inactive rule checkboxes in delete-for-reasons#853faisalahammad wants to merge 4 commits into
faisalahammad wants to merge 4 commits into
Conversation
- Use the core is-dismissible close button and drop the hand-rolled one.
- Keep i18n one translatable string per message.
- Persist dismissal keyed to PR PLUGIN_VERSION so it returns on newer builds.
- Fold is_pre_release into PreReleaseNotice and allow build metadata.
- Deny without capability via wp_send_json_error(403) or wp_die('', 403).
- Rename the dismiss script to pre-release-notice.js and persist on X clicks.
Add an input case to the honeypot renderer so themes that output the comment field as a text input get a working honeypot. The visible input keeps its id and gets an obfuscated name, and a hidden duplicate with the comment name is appended as the bait, matching how the textarea case works. Fixes pluginkollektiv#738
In the post-processor options, a reason whose underlying rule is inactive in the rules section used to render as an enabled checkbox. A user could tick it, the choice would be stored, but the rule never fires, so the stored reason is dead weight with no UI hint that it can never trigger. The DeleteForReasons post-processor now builds a disabled_keys map per reaction type: any rule that implements Controllable and is inactive for that type is marked disabled. The CheckboxGroup renderer reads the optional disabled_keys key and emits a disabled <input> plus a dimmed label. Non-controllable rules (no is_active method) keep their existing behaviour. The sanitize closure still keys on the full option list, so a stored value for a disabled reason survives the round-trip and is restored when the rule is re-enabled. Fixes pluginkollektiv#740
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.
Summary
In the post-processor options, a reason whose underlying rule is inactive in the rules section used to render as an enabled checkbox. A user could tick it, the choice would be stored, but the rule never fires, so the stored reason was dead weight with no UI hint that it can never trigger.
DeleteForReasons::get_options()now builds adisabled_keysmap per reaction type. Any rule that implementsControllableand is inactive for that type is marked disabled.CheckboxGroup::render()reads the optionaldisabled_keyskey and emits adisabledinput plus a dimmed label. Non-controllable rules (nois_activemethod) keep their existing behaviour. Thesanitizeclosure still keys on the full option list, so a stored value for a disabled reason survives the round-trip and is restored when the rule is re-enabled.Fixes #740
Changes
src/PostProcessors/DeleteForReasons.phpBuild
$disabled_keysper reaction type from controllable rules whoseis_active( $reaction_type )is falsy. The new key is added to the emitted option entry alongside the existingoptionsmap.sanitizeis unchanged on purpose.Why: makes the post-processor options section a faithful view of what can actually happen at runtime, without silently dropping stored preferences.
src/Admin/Fields/CheckboxGroup.phpReads
$this->option['disabled_keys'] ?? []before the row loop. When a row's slug is in the map, the input gets adisabledattribute and the wrapping label gets a newasb-checkbox-group-disabledclass.Why: opt-in renderer change. No other call site sets
disabled_keys, so CountrySpam and LangSpam output is byte-equivalent to today.assets/css/admin.cssOne new rule:
.asb-checkbox-group-disabled { color: #8c8f94; }. Reuses the existing secondary-text colour used elsewhere in the admin stylesheet.Tests
tests/Unit/PostProcessors/DeleteForReasonsTest.php(new, 6 cases): a controllable rule is disabled only when inactive, an active controllable rule is never disabled, a non-controllable rule is never disabled, an option list with no controllable rules yields an emptydisabled_keys, the map is built per reaction type (not collapsed across the form), andsanitizestill accepts a posted value for a disabled key.tests/Unit/Admin/Fields/CheckboxGroupTest.php(new, 5 cases): output is unchanged whendisabled_keysis absent (regression guard for other call sites), a disabled row renders thedisabledattribute plus the label class and only that row, a storedonvalue still renders aschecked="checked"while the row is disabled, a storedoffvalue renders unchecked but still disabled, and the row'sname/idare the full controllable path with the slug suffix and are escaped.Testing
Test 1: Manual round-trip on a fresh WordPress site
antispam-bee.740-test.zip(built from this branch) viaPlugins → Add New → Upload Plugin, then activate.Settings → Antispam Bee, expand the Rules section, confirm "BBCode link" is active.checked="checked"and enabled (pre-existing baseline).checked="checked", but the checkbox isdisabledand the label text is dimmed. Clicking or unchecking the row has no effect.onvalue is honoured, no further user action is needed.Test 2: Per-reaction-type check
This proves the
disabled_keysmap is built per reaction type, not collapsed across the form.Test 3: Automated checks in the worktree
composer test:unit199 tests, 0 failures, 0 regressions (the 11 errors in the output are pre-existing PHP 8.5ReflectionProperty::setAccessible()deprecations intests/Unit/Helpers/DebugModeTest.php, unrelated to this change).composer lint-phpclean.composer phpstanlevel 8 clean.Edge cases covered by unit tests
Controllable(e.g.asb-empty,asb-deny-country) is never disabled.is_active()does not exist on it, andComponentsHelper::filter()treats it as always-on.'off'(the user explicitly unticked it before deactivation) renders unchecked but still disabled.disabled_keysarray. The disable branch is correctly short-circuited.Notes for reviewer
disabled_keysdefaults to[]in the renderer, no migration needed.disabledattribute and theasb-checkbox-group-disabledclass are not user-facing copy.Screen recording
https://videos.faisalahammad.com/recordings/WblPUVF5Okuc2YYIBfFL
antispam-bee-disable-inactive-rule-checkboxes-in-delete-for-reasons-853.mp4