-
Notifications
You must be signed in to change notification settings - Fork 92
gppa-filter-terms-by-depth.php: Fixed an issue where taxonomy selections were not saving in Multiple Choice fields when using checkbox input types.
#1182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe change modifies choice processing in the filter-terms-by-depth script, implementing a two-stage approach with a Changes
Sequence Diagram(s)sequenceDiagram
participant Func as gppa_filter_terms_by_depth()
participant Terms as terms[]
participant Filtered as filtered_choices[]
participant Orig as original_choices[]
participant Logic as Merge Logic
Func->>Terms: iterate terms
rect rgb(230, 240, 255)
Note over Func: create per-term $choice object
Func->>Filtered: append tentative $choice
end
alt field supports persistent choices
rect rgb(220, 245, 220)
Note over Logic: lookup by term_id in original_choices
Orig->>Logic: provide matching choice?
Logic-->>Filtered: merge properties into existing key if match
end
else no match / non-persistent field
rect rgb(255, 235, 235)
Note over Logic: ensure key exists
Logic->>Logic: generate key = md5(term_id) if needed
Logic-->>Filtered: add new choice with generated key
end
end
Func->>Func: return filtered_choices
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (3)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
gp-populate-anything/gppa-filter-terms-by-depth.php (1)
55-68: Core fix looks solid; consider minor defensive improvements.The persistent choice preservation logic correctly addresses the bug by:
- Using
method_exists()for backward compatibility- Merging original choices to preserve existing keys
- Generating stable MD5 keys for new choices
Consider these improvements:
- Use strict comparison for term_id matching (Line 59):
-if ( isset( $original_choice['object'] ) && $original_choice['object']->term_id == $object->term_id ) { +if ( isset( $original_choice['object'], $original_choice['object']->term_id ) && $original_choice['object']->term_id === $object->term_id ) {This adds a property existence check and uses strict comparison to avoid type coercion edge cases.
- Optional: Optimize lookup for large datasets by indexing original choices first:
// Before the foreach loop at line 48 $original_choices_by_term_id = array(); foreach ( $choices as $original_choice ) { if ( isset( $original_choice['object']->term_id ) ) { $original_choices_by_term_id[ $original_choice['object']->term_id ] = $original_choice; } }Then replace lines 58-63 with a direct lookup. This reduces complexity from O(n×m) to O(n+m).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
gp-populate-anything/gppa-filter-terms-by-depth.php(1 hunks)
🔇 Additional comments (3)
gp-populate-anything/gppa-filter-terms-by-depth.php (3)
46-47: LGTM: Clean separation of input and output.The two-stage approach with
$filtered_choicesimproves clarity and correctly implements the choice preservation logic.
49-53: LGTM: Correct choice structure.The choice array structure properly maps term data to GPPA's expected format.
73-73: LGTM: Correct return value.Returning
$filtered_choicesproperly completes the two-stage filtering and choice preservation logic.
…tions were not saving in Multiple Choice fields when using checkbox input types.
308ecd3 to
60fde0e
Compare
gppa-filter-terms-by-depth.php: Fixed an issue where taxonomy selections were not saving in Multiple Choice fields when using checkbox input types.
Context
⛑️ Ticket(s): https://secure.helpscout.net/link/to/conversation
Summary
Issue: When using the taxonomy depth filter snippet with Multiple Choice fields (configured with anything other than "Select One" input type), selected taxonomy terms were not being saved. This affected any Multiple Choice field using checkbox-style inputs with dynamically populated taxonomy choices.
The issue occurred because GF introduced persistent choices for Multiple Choice fields, where each choice requires a unique
keyproperty for proper tracking and saving.Fix: Updated the
gppa_input_choicesfilter to keep existing choice data instead of replacing it. The fix maintains the unique keys that GPPA already generated for each choice and only creates new MD5 keys when needed. Useshas_persistent_choices()to identify fields that need this approach while staying compatible with older field types.