-
Notifications
You must be signed in to change notification settings - Fork 151
Fix: Disable Update Post Notification in free version #1614
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
Fix: Disable Update Post Notification in free version #1614
Conversation
- 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
WalkthroughThis 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
Possibly related issues
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 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_Cleanupclass 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
📒 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
booltoarrayaccurately reflects that the method returns$saved_wpuf_inputsarray.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_Cleanupclass 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_posthook correctly filters forwpuf_formspost 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_previewvariable 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.
| 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; | ||
| } | ||
| } |
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.
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.
| 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.
Summary by CodeRabbit
New Features
Bug Fixes
Chores