Skip to content

Conversation

@arifulhoque7
Copy link
Contributor

@arifulhoque7 arifulhoque7 commented Jul 4, 2025

  • Prevent update post notification from being enabled by default in free version
  • Filter out pro notification fields from form settings before saving
  • Update UI to show Update Post Notification toggle as disabled/off in free version
  • Add Form_Settings_Cleanup hook to remove pro notification settings from saved form meta
  • Ensure backward compatibility and no impact on pro users
  • Resolves issue [Bug] The "Update Post Notification" option is enabled by default and cannot be disabled. [Ver. 4.1.6] #1613 where free users received unwanted update notifications

Summary by CodeRabbit

  • New Features

    • Pro-only notification settings are now hidden and disabled in the form builder when the pro version is inactive, ensuring a clearer distinction between free and pro features.
  • Bug Fixes

    • Prevented submission and editing of pro-only notification fields in the free version, avoiding accidental saving of unsupported settings.
  • Chores

    • Improved internal handling to automatically clean up pro-only notification settings from saved forms when the pro version is not active.

- Prevent update post notification from being enabled by default in free version
- Filter out pro notification fields from form settings before saving
- Update UI to show Update Post Notification toggle as disabled/off in free version
- Add Form_Settings_Cleanup hook to remove pro notification settings from saved form meta
- Ensure backward compatibility and no impact on pro users
- Resolves issue weDevsOfficial#1613 where free users received unwanted update notifications
@arifulhoque7 arifulhoque7 requested a review from sapayth July 4, 2025 03:57
@arifulhoque7 arifulhoque7 self-assigned this Jul 4, 2025
@arifulhoque7 arifulhoque7 added needs: testing needs: dev review This PR needs review by a developer labels Jul 4, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 4, 2025

Walkthrough

This update introduces logic to disable, hide, and sanitize pro-only notification fields in the form settings UI and data when the pro version is inactive. It modifies rendering and saving of form settings, adds a cleanup class for form meta, and updates the loader to instantiate this cleanup functionality.

Changes

Files / Paths Change Summary
admin/form-builder/views/post-form-settings.php Updated field rendering to disable and hide pro-only notification fields, ensuring they are not submitted.
includes/Admin/Forms/Admin_Form_Builder.php Modified save_form to remove pro-only notification settings when pro is inactive; changed return type to array.
includes/Free/Free_Loader.php Added import, file inclusion, and instantiation for Form_Settings_Cleanup in admin context.
includes/Hooks/Form_Settings_Cleanup.php Introduced new class to remove pro-only notification settings from form meta on save actions.

Possibly related issues

Suggested labels

bug, QA Approved

Suggested reviewers

  • Rubaiyat-E-Mohammad
  • sapayth

Poem

A bunny hopped through fields of code,
Disabling pro where free is owed.
Notification toggles now asleep,
Only clean settings do we keep.
With gentle paws, the forms are neat—
No pro-only crumbs for users to eat!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
admin/form-builder/views/post-form-settings.php (1)

1-1: Fix the whitespace at end of line.

The pipeline failure indicates there's whitespace at the end of line 1. This should be removed for code cleanliness.

🧹 Nitpick comments (1)
includes/Admin/Forms/Admin_Form_Builder.php (1)

376-398: LGTM: Pro notification settings filtering logic is correct.

The filtering logic correctly removes pro-only notification settings when the pro version is inactive. The approach is consistent with the Form_Settings_Cleanup class and ensures data integrity.

Consider using the same key arrays as in Form_Settings_Cleanup::remove_pro_notification_settings() for consistency:

-        // Filter out pro notification settings if pro version is not active
-        if ( ! wpuf_is_pro_active() && isset( $data['form_settings']['notification'] ) ) {
-            // Remove update post notification settings for free version
-            if ( isset( $data['form_settings']['notification']['edit'] ) ) {
-                unset( $data['form_settings']['notification']['edit'] );
-            }
-            if ( isset( $data['form_settings']['notification']['edit_to'] ) ) {
-                unset( $data['form_settings']['notification']['edit_to'] );
-            }
-            if ( isset( $data['form_settings']['notification']['edit_subject'] ) ) {
-                unset( $data['form_settings']['notification']['edit_subject'] );
-            }
-            if ( isset( $data['form_settings']['notification']['edit_body'] ) ) {
-                unset( $data['form_settings']['notification']['edit_body'] );
-            }
-        }
-        
-        // Also filter out standalone notification_edit field if it exists
-        if ( ! wpuf_is_pro_active() && isset( $data['form_settings']['notification_edit'] ) ) {
-            unset( $data['form_settings']['notification_edit'] );
-        }
+        // Filter out pro notification settings if pro version is not active
+        if ( ! wpuf_is_pro_active() ) {
+            $notification_pro_keys = [ 'edit', 'edit_to', 'edit_subject', 'edit_body' ];
+            
+            if ( isset( $data['form_settings']['notification'] ) && is_array( $data['form_settings']['notification'] ) ) {
+                foreach ( $notification_pro_keys as $key ) {
+                    if ( isset( $data['form_settings']['notification'][ $key ] ) ) {
+                        unset( $data['form_settings']['notification'][ $key ] );
+                    }
+                }
+            }
+            
+            // Also filter out standalone notification_edit field if it exists
+            if ( isset( $data['form_settings']['notification_edit'] ) ) {
+                unset( $data['form_settings']['notification_edit'] );
+            }
+        }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6713e4f and 75e2efe.

📒 Files selected for processing (4)
  • admin/form-builder/views/post-form-settings.php (6 hunks)
  • includes/Admin/Forms/Admin_Form_Builder.php (2 hunks)
  • includes/Free/Free_Loader.php (3 hunks)
  • includes/Hooks/Form_Settings_Cleanup.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
includes/Admin/Forms/Admin_Form_Builder.php (1)
wpuf-functions.php (1)
  • wpuf_is_pro_active (4869-4871)
includes/Hooks/Form_Settings_Cleanup.php (1)
wpuf-functions.php (2)
  • wpuf_is_pro_active (4869-4871)
  • wpuf_get_form_settings (1903-1905)
includes/Free/Free_Loader.php (1)
includes/Hooks/Form_Settings_Cleanup.php (1)
  • Form_Settings_Cleanup (11-107)
admin/form-builder/views/post-form-settings.php (1)
wpuf-functions.php (1)
  • wpuf_is_pro_active (4869-4871)
🪛 GitHub Check: Run PHPCS inspection
includes/Hooks/Form_Settings_Cleanup.php

[failure] 97-97:
Whitespace found at end of line


[failure] 86-86:
There should be a comma after the last array item in a multi-line array.


[failure] 84-84:
Whitespace found at end of line


[failure] 63-63:
Whitespace found at end of line


[failure] 57-57:
Whitespace found at end of line


[failure] 38-38:
Whitespace found at end of line


[failure] 32-32:
Whitespace found at end of line


[failure] 7-7:
Whitespace found at end of line

🪛 GitHub Actions: Inspections
admin/form-builder/views/post-form-settings.php

[error] 1-1: PHP CodeSniffer: Whitespace found at end of line.

🔇 Additional comments (13)
includes/Admin/Forms/Admin_Form_Builder.php (1)

340-340: LGTM: Correct return type annotation update.

The return type change from bool to array accurately reflects that the method returns $saved_wpuf_inputs array.

includes/Free/Free_Loader.php (3)

9-9: LGTM: Correct import statement for the new cleanup class.


76-76: LGTM: Proper file inclusion for the cleanup functionality.


95-95: LGTM: Appropriate instantiation in admin context.

The Form_Settings_Cleanup class is correctly instantiated within the admin context where form operations occur.

includes/Hooks/Form_Settings_Cleanup.php (2)

11-43: LGTM: Solid cleanup logic with proper validation.

The class correctly hooks into form save actions and implements proper validation with early returns when pro is active or form settings are empty.


51-68: LGTM: Proper post save hook implementation.

The save_post hook correctly filters for wpuf_forms post type and follows the same validation pattern as the form builder save method.

admin/form-builder/views/post-form-settings.php (7)

316-316: LGTM! Well-implemented pro feature detection logic.

The $is_pro_preview variable correctly identifies fields that should be treated as pro preview fields, combining both explicit pro preview fields and notification fields when the pro version is inactive. The specific notification field keys match the PR objectives.


332-336: Correct value handling for pro preview fields.

The conditional logic appropriately handles value determination - pro preview fields use their default values instead of saved form settings, which prevents saved pro settings from being displayed in the free version.


349-351: Effective form submission prevention for pro fields.

The modifications correctly disable checkbox inputs and remove their name attributes when in pro preview mode, preventing these fields from being submitted with the form data.


381-387: Excellent special handling for notification toggles.

The implementation correctly forces notification toggle fields to appear as "off" in pro preview mode, regardless of their actual saved value. This ensures consistent UI behavior for free users.


394-396: Consistent toggle field protection.

The toggle input modifications mirror the checkbox approach - removing name attributes and disabling the field when in pro preview mode. This maintains consistency across input types.


473-475: Proper text/number input field restrictions.

Text and number inputs are appropriately disabled and have their name attributes removed when in pro preview mode, maintaining the same protective pattern as other input types.


486-487: Complete textarea field protection.

Textarea inputs follow the same protective pattern as other input types, ensuring comprehensive coverage of form fields that could contain pro-only settings.

Comment on lines +76 to +107
private function remove_pro_notification_settings( $form_settings ) {
if ( ! is_array( $form_settings ) ) {
return $form_settings;
}

// List of pro-only notification settings to remove
$pro_notification_keys = [
'notification_edit',
'notification_edit_to',
'notification_edit_subject',
'notification_edit_body'
];

foreach ( $pro_notification_keys as $key ) {
if ( isset( $form_settings[ $key ] ) ) {
unset( $form_settings[ $key ] );
}
}

if ( isset( $form_settings['notification'] ) && is_array( $form_settings['notification'] ) ) {
$notification_pro_keys = [ 'edit', 'edit_to', 'edit_subject', 'edit_body' ];

foreach ( $notification_pro_keys as $key ) {
if ( isset( $form_settings['notification'][ $key ] ) ) {
unset( $form_settings['notification'][ $key ] );
}
}
}

return $form_settings;
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix code formatting issues identified by PHPCS.

The logic is correct, but there are several formatting issues that need to be addressed.

Apply this diff to fix the formatting issues:

-    /**
-     * Remove pro notification settings from form settings
-     *
-     * @param array $form_settings Form settings array
-     * @return array Cleaned form settings
-     */
-    private function remove_pro_notification_settings( $form_settings ) {
-        if ( ! is_array( $form_settings ) ) {
-            return $form_settings;
-        }
-
-        // List of pro-only notification settings to remove
-        $pro_notification_keys = [
-            'notification_edit',
-            'notification_edit_to', 
-            'notification_edit_subject',
-            'notification_edit_body'
-        ];
-
-        foreach ( $pro_notification_keys as $key ) {
-            if ( isset( $form_settings[ $key ] ) ) {
-                unset( $form_settings[ $key ] );
-            }
-        }
-
-        if ( isset( $form_settings['notification'] ) && is_array( $form_settings['notification'] ) ) {
-            $notification_pro_keys = [ 'edit', 'edit_to', 'edit_subject', 'edit_body' ];
-            
-            foreach ( $notification_pro_keys as $key ) {
-                if ( isset( $form_settings['notification'][ $key ] ) ) {
-                    unset( $form_settings['notification'][ $key ] );
-                }
-            }
-        }
-
-        return $form_settings;
-    }
+    /**
+     * Remove pro notification settings from form settings
+     *
+     * @param array $form_settings Form settings array
+     * @return array Cleaned form settings
+     */
+    private function remove_pro_notification_settings( $form_settings ) {
+        if ( ! is_array( $form_settings ) ) {
+            return $form_settings;
+        }
+
+        // List of pro-only notification settings to remove
+        $pro_notification_keys = [
+            'notification_edit',
+            'notification_edit_to',
+            'notification_edit_subject',
+            'notification_edit_body',
+        ];
+
+        foreach ( $pro_notification_keys as $key ) {
+            if ( isset( $form_settings[ $key ] ) ) {
+                unset( $form_settings[ $key ] );
+            }
+        }
+
+        if ( isset( $form_settings['notification'] ) && is_array( $form_settings['notification'] ) ) {
+            $notification_pro_keys = [ 'edit', 'edit_to', 'edit_subject', 'edit_body' ];
+
+            foreach ( $notification_pro_keys as $key ) {
+                if ( isset( $form_settings['notification'][ $key ] ) ) {
+                    unset( $form_settings['notification'][ $key ] );
+                }
+            }
+        }
+
+        return $form_settings;
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private function remove_pro_notification_settings( $form_settings ) {
if ( ! is_array( $form_settings ) ) {
return $form_settings;
}
// List of pro-only notification settings to remove
$pro_notification_keys = [
'notification_edit',
'notification_edit_to',
'notification_edit_subject',
'notification_edit_body'
];
foreach ( $pro_notification_keys as $key ) {
if ( isset( $form_settings[ $key ] ) ) {
unset( $form_settings[ $key ] );
}
}
if ( isset( $form_settings['notification'] ) && is_array( $form_settings['notification'] ) ) {
$notification_pro_keys = [ 'edit', 'edit_to', 'edit_subject', 'edit_body' ];
foreach ( $notification_pro_keys as $key ) {
if ( isset( $form_settings['notification'][ $key ] ) ) {
unset( $form_settings['notification'][ $key ] );
}
}
}
return $form_settings;
}
}
private function remove_pro_notification_settings( $form_settings ) {
if ( ! is_array( $form_settings ) ) {
return $form_settings;
}
// List of pro-only notification settings to remove
$pro_notification_keys = [
'notification_edit',
'notification_edit_to',
'notification_edit_subject',
'notification_edit_body',
];
foreach ( $pro_notification_keys as $key ) {
if ( isset( $form_settings[ $key ] ) ) {
unset( $form_settings[ $key ] );
}
}
if ( isset( $form_settings['notification'] ) && is_array( $form_settings['notification'] ) ) {
$notification_pro_keys = [ 'edit', 'edit_to', 'edit_subject', 'edit_body' ];
foreach ( $notification_pro_keys as $key ) {
if ( isset( $form_settings['notification'][ $key ] ) ) {
unset( $form_settings['notification'][ $key ] );
}
}
}
return $form_settings;
}
}
🧰 Tools
🪛 GitHub Check: Run PHPCS inspection

[failure] 97-97:
Whitespace found at end of line


[failure] 86-86:
There should be a comma after the last array item in a multi-line array.


[failure] 84-84:
Whitespace found at end of line

🤖 Prompt for AI Agents
In includes/Hooks/Form_Settings_Cleanup.php around lines 76 to 107, the code
logic is correct but the formatting does not comply with PHPCS standards. Fix
the formatting issues by ensuring proper indentation, consistent spacing around
array elements and control structures, and correct placement of braces according
to the project's coding standards. This includes aligning array keys and values,
adding or removing blank lines where necessary, and making sure the overall code
style matches the rest of the codebase.

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

Labels

needs: dev review This PR needs review by a developer QA Approved This PR is approved by the QA team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants