Fix 359#512
Conversation
Validate submitted options and escape legacy radio values on display.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@includes/fields/class-fieldtypes-radiobutton.php`:
- Around line 96-111: The radio input IDs in the field rendering logic are not
guaranteed to be unique because the ID built in the radio option loop only uses
normalize_name($label), which can collapse distinct labels into the same DOM id.
Update the ID generation in the radio rendering method to include an unambiguous
unique suffix from the current option (such as the loop index or option key) so
each input/label pair in this class remains distinct and the label[for]
attribute always points to the correct radio.
- Around line 133-140: The radio field save path in
class-fieldtypes-radiobutton::store_field_value is treating invalid submitted
values the same as empty values, so tampered input still reaches the parent
store logic and clears the stored meta. Update the flow to distinguish an
invalid submission (from convert_input() returning an empty string after bad
input) from a user intentionally clearing the field, and only call
parent::store_field_value() when the value is truly valid or intentionally
empty; otherwise preserve the existing saved choice and avoid deleting or
overwriting the _wpbdp[fields][id] meta.
In `@tests/wpunit/Fields/RadioButtonFieldTest.php`:
- Around line 99-111: The create_listing() helper currently only checks that
wp_insert_post() returned an int, which still allows 0 to pass and masks fixture
setup failures. Update create_listing() to validate that the returned listing ID
is a positive integer, or switch wp_insert_post() to return WP_Error on failure
and assert/fail accordingly so invalid listing IDs are never returned.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7cccafbf-f485-419c-83a5-3e28ed362ef4
📒 Files selected for processing (2)
includes/fields/class-fieldtypes-radiobutton.phptests/wpunit/Fields/RadioButtonFieldTest.php
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughUpdates radio-button field handling for meta-associated values by validating submitted options, tracking invalid submissions, changing meta storage/deletion behavior, and escaping displayed HTML values. Adds tests for valid, invalid, empty, special-character, and legacy stored values. ChangesRadioButton field input validation, storage, and rendering
Sequence DiagramsequenceDiagram
participant ListingFields as $_POST['listingfields'][field_id]
participant RadioButton as WPBDP_FieldTypes_RadioButton
participant PostMeta as post meta
ListingFields->>RadioButton: convert_input($field, $input)
RadioButton->>RadioButton: get_stored_options()
RadioButton-->>ListingFields: string value or empty string
ListingFields->>RadioButton: store_field_value($field, $post_id, $value)
RadioButton->>PostMeta: update_post_meta() or delete_post_meta()
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 PHPStan (2.2.2)PHPStan was skipped because the user-provided config is missing the required 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. Comment |
|
Radio options containing a |
|
Thanks @garretlaxton, my last commit should fix that |
garretlaxton
left a comment
There was a problem hiding this comment.
Nice, this works great!
fixes https://github.com/Strategy11/business-directory-premium/issues/359