fix: enable post expiration always turned on#1854
Conversation
WalkthroughThe ChangesForm Settings Field Resolution & Toggle Rendering
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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.1.51)PHPStan was skipped because the sandbox runner could not parse its output. 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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
admin/form-builder/views/post-form-settings.php (1)
344-358: 💤 Low valueNested-name DB lookup runs before the
$is_pro_previewguard.When a field is both a pro-preview field and has a nested
wpuf_settings[x][y]name,$valueis read from DB at line 350 and$resolved_from_nested_nameis set totrue, then the value is immediately overwritten at line 356 — making the lookup a no-op. The correctness is fine (theelseifis never reached for pro-preview fields), but the ordering makes the intent slightly harder to follow.♻️ Optional guard to skip the DB lookup for pro-preview fields
- $resolved_from_nested_name = false; - if ( ! empty( $field['name'] ) && preg_match( '/wpuf_settings\[(.*?)\]\[(.*?)\]/', $field['name'], $matches ) ) { - $dynamic_key = $matches[1]; - $temp_key = $matches[2]; - $value = isset( $form_settings[ $dynamic_key ][ $temp_key ] ) ? $form_settings[ $dynamic_key ][ $temp_key ] : $value; - $resolved_from_nested_name = true; - } - - // if the field is a pro fields preview, no need to load fields from db - if ( $is_pro_preview ) { - $value = ! empty( $field['value'] ) ? $field['value'] : $value; - } elseif ( ! $resolved_from_nested_name ) { - $value = isset( $form_settings[ $field_key ] ) ? $form_settings[ $field_key ] : $value; - } + // if the field is a pro fields preview, no need to load fields from db + if ( $is_pro_preview ) { + $value = ! empty( $field['value'] ) ? $field['value'] : $value; + } else { + // When an explicit nested name like wpuf_settings[group][key] is provided, read from the nested path. + if ( ! empty( $field['name'] ) && preg_match( '/wpuf_settings\[(.*?)\]\[(.*?)\]/', $field['name'], $matches ) ) { + $value = isset( $form_settings[ $matches[1] ][ $matches[2] ] ) ? $form_settings[ $matches[1] ][ $matches[2] ] : $value; + } else { + $value = isset( $form_settings[ $field_key ] ) ? $form_settings[ $field_key ] : $value; + } + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@admin/form-builder/views/post-form-settings.php` around lines 344 - 358, The nested wpuf_settings[...] lookup (preg_match on $field['name'] that sets $resolved_from_nested_name and reads from $form_settings) runs before the $is_pro_preview guard, making that DB read dead when $is_pro_preview is true; move the pro-preview check earlier or wrap the nested-name logic inside the non-pro branch so that if ($is_pro_preview) sets $value = ! empty($field['value']) ? $field['value'] : $value and returns/skips, otherwise perform the preg_match/$resolved_from_nested_name logic and the subsequent isset($form_settings[$field_key]) assignment. Ensure you reference the same variables: $is_pro_preview, $field['name'], preg_match(...), $resolved_from_nested_name, $form_settings and $field_key.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@admin/form-builder/views/post-form-settings.php`:
- Around line 344-358: The nested wpuf_settings[...] lookup (preg_match on
$field['name'] that sets $resolved_from_nested_name and reads from
$form_settings) runs before the $is_pro_preview guard, making that DB read dead
when $is_pro_preview is true; move the pro-preview check earlier or wrap the
nested-name logic inside the non-pro branch so that if ($is_pro_preview) sets
$value = ! empty($field['value']) ? $field['value'] : $value and returns/skips,
otherwise perform the preg_match/$resolved_from_nested_name logic and the
subsequent isset($form_settings[$field_key]) assignment. Ensure you reference
the same variables: $is_pro_preview, $field['name'], preg_match(...),
$resolved_from_nested_name, $form_settings and $field_key.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a91cf754-2954-493b-bfcf-c9ae55a0e268
📒 Files selected for processing (1)
admin/form-builder/views/post-form-settings.php
In WPUF > Post Forms > Settings > Post Expiration >
Enable Post Expirationis always turned onSummary by CodeRabbit
Bug Fixes