Skip to content

fix: enable post expiration always turned on#1854

Merged
sapayth merged 1 commit into
weDevsOfficial:developfrom
sapayth:fix/enable_post_expiration_always_turned_on
May 4, 2026
Merged

fix: enable post expiration always turned on#1854
sapayth merged 1 commit into
weDevsOfficial:developfrom
sapayth:fix/enable_post_expiration_always_turned_on

Conversation

@sapayth
Copy link
Copy Markdown
Contributor

@sapayth sapayth commented May 4, 2026

In WPUF > Post Forms > Settings > Post Expiration > Enable Post Expiration is always turned on

CleanShot 2026-05-04 at 08 56 07

Summary by CodeRabbit

Bug Fixes

  • Improved handling of form field values for nested field structures, ensuring proper value resolution during form rendering
  • Enhanced toggle field behavior to correctly preserve and submit state information when unchecked, preventing submission ambiguity

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

Walkthrough

The wpuf_render_settings_field() function in the form-builder settings view is enhanced to explicitly resolve nested field names (e.g., wpuf_settings[group][key]) and improved to ensure toggle fields submit explicit on/off values through companion hidden inputs.

Changes

Form Settings Field Resolution & Toggle Rendering

Layer / File(s) Summary
Nested Field Value Resolution
admin/form-builder/views/post-form-settings.php (lines 344–359)
Parses nested wpuf_settings[group][key] field names and introduces a $resolved_from_nested_name flag. Values are loaded from $form_settings[$dynamic_key][$temp_key] for nested paths, with fallback to $form_settings[$field_key] outside PRO preview mode; PRO preview mode preserves the field's provided value.
Toggle Field Hidden Input
admin/form-builder/views/post-form-settings.php (lines 418–435)
Adds a companion hidden input with value="off" (when not in PRO preview) alongside the checkbox to ensure unchecked toggles submit an explicit value; checkbox input now explicitly sets value="on".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

QA Approved

Poem

🐰 A toggle's journey through the form,
Now off and on, both states confirmed,
With nested paths unpacked just right,
The settings render clear and bright,
No more ambiguous checkbox blight! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the reported issue where 'Enable Post Expiration' is always turned on, matching the PR objective to fix this behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@sapayth sapayth self-assigned this May 4, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
admin/form-builder/views/post-form-settings.php (1)

344-358: 💤 Low value

Nested-name DB lookup runs before the $is_pro_preview guard.

When a field is both a pro-preview field and has a nested wpuf_settings[x][y] name, $value is read from DB at line 350 and $resolved_from_nested_name is set to true, then the value is immediately overwritten at line 356 — making the lookup a no-op. The correctness is fine (the elseif is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2b0727b and 5348603.

📒 Files selected for processing (1)
  • admin/form-builder/views/post-form-settings.php

@Rubaiyat-E-Mohammad Rubaiyat-E-Mohammad added QA Approved This PR is approved by the QA team and removed needs: testing labels May 4, 2026
@sapayth sapayth merged commit 51c9a04 into weDevsOfficial:develop May 4, 2026
1 of 2 checks passed
@arifulhoque7 arifulhoque7 mentioned this pull request May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QA Approved This PR is approved by the QA team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants