Fix: guard method_exists() against null $wpuf_field to prevent PHP 8+ fatal error#1900
Conversation
|
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 selected for processing (1)
WalkthroughA conditional check in prepare_meta_fields() was modified to require $wpuf_field to be truthy before calling method_exists() on it, preventing a runtime error when the field value is null or invalid. ChangesNull-safe field sanitization check
Estimated code review effort: 1 (Trivial) | ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Fixes #1832
Problem
In both
FieldableTrait::prepare_meta_fields()andWPUF_Frontend_Render_Form::prepare_meta_fields(),$wpuf_fieldis resolved via:When
get_field()returnsnull— e.g. the submitted field'stemplateno longer matches a registered field type (deprecated/removed field, or a Pro-only field type referenced while Pro is inactive) — the next line calls:method_exists()requires its first parameter to beobject|string. Passingnullthrows aTypeErroron PHP 8.0+ (PHP 7.x only warned and returnedfalse), so any frontend form submission hitting this path with an unresolvable field type currently white-screens for the site visitor.Fix
Add a truthy check on
$wpuf_fieldbefore callingmethod_exists(), matching the guard style already used elsewhere in the codebase (wpuf-functions.php:1094already does! empty( $wpuf_field ) && method_exists(...)):Applied to both occurrences of the identical pattern:
includes/Traits/FieldableTrait.phpincludes/class-frontend-render-form.phpTesting
wpuf-functions.phpalready guards correctly.templatethat doesn't resolve; confirmed it now falls through gracefully to theelseif/elsebranches instead of throwing.Notes for reviewers
Didn't touch
wpuf-functions.php:1094since it's already correctly guarded. Happy to add a regression test if there's a preferred location/harness forFieldableTraittests.Summary by CodeRabbit