-
Notifications
You must be signed in to change notification settings - Fork 214
Enhancement: Form validation when vendor Terms & Conditions content is empty #3082
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
base: develop
Are you sure you want to change the base?
Conversation
…method is configured
…method is configured
…method is configured
📝 WalkthroughWalkthroughAdds server-side validation and persisted processing for vendor Terms & Conditions: when Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Vendor as Vendor (Client)
participant Settings as Dashboard Settings Handler
participant Storage as Settings Storage/DB
participant Storefront as Storefront Renderer
Vendor->>Settings: Submit settings (dokan_store_tnc_enable, dokan_store_tnc)
Note right of Settings: If dokan_store_tnc_enable == on\nprocess dokan_store_tnc
Settings->>Settings: strip_tags, html_entity_decode, remove whitespace
alt processed content is empty
Settings-->>Vendor: return validation error (dokan_tnc_content)
else processed content non-empty
Settings->>Settings: sanitize with wp_kses_post -> store_tnc_processed
Settings->>Storage: persist settings (store_tnc_processed)
Settings-->>Vendor: success / settings saved
Vendor->>Storefront: customer visits T&C page
Storefront->>Storage: retrieve store_tnc_processed
Storefront-->>Vendor: render sanitized T&C
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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. Comment |
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
🤖 Fix all issues with AI agents
In `@includes/Dashboard/Templates/Settings.php`:
- Around line 483-492: Remove the trailing whitespace and make the input
sanitization explicit: when reading $_POST use wp_unslash for $store_tnc, then
apply a sanitizer such as sanitize_textarea_field (or wp_kses_post if HTML is
allowed) instead of relying only on wp_strip_all_tags for the emptiness check;
assign the sanitized value to $store_tnc_clean (or similarly named variable),
trim it and then run the empty() check; ensure no trailing spaces remain in that
line and keep the $enable_tnc / $store_tnc / $store_tnc_clean variable names
referenced in the Settings.php block.
🧹 Nitpick comments (1)
includes/Dashboard/Templates/Settings.php (1)
898-915: Address unused parameter and alignment inconsistency.The method logic is correct. Two minor issues:
- The
$requestparameter is required by the filter signature but unused. Consider prefixing with underscore or adding a PHPCS ignore comment.- Inconsistent alignment at lines 909-911 (
connected_methodsvs others).Proposed fix
- public function add_payment_methods_to_rest_response( $additional_fields, $store, $request ) { + public function add_payment_methods_to_rest_response( $additional_fields, $store, $request ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed $vendor_id = method_exists( $store, 'get_id' ) ? (int) $store->get_id() : 0; if ( $vendor_id > 0 ) { // Get payment methods data using the same logic as vendor dashboard. $payment_data = $this->get_seller_payment_methods( $vendor_id ); // Add flag to indicate if any withdraw method is globally available. $additional_fields['withdraw_methods_available'] = ! empty( $payment_data['active_methods'] ); // Add payment method data. $additional_fields['active_payment_methods'] = $payment_data['active_methods']; - $additional_fields['connected_methods'] = $payment_data['connected_methods']; - $additional_fields['disconnected_methods'] = $payment_data['disconnected_methods']; + $additional_fields['connected_methods'] = $payment_data['connected_methods']; + $additional_fields['disconnected_methods'] = $payment_data['disconnected_methods']; } return $additional_fields; }
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
🤖 Fix all issues with AI agents
In `@includes/Dashboard/Templates/Settings.php`:
- Around line 482-489: Normalize and fully empty-check the T&C input: after
obtaining the raw value (currently via wp_strip_all_tags( wp_unslash(
$_POST['dokan_store_tnc'] ?? '' ) )), run html_entity_decode to convert entities
like to real characters, replace or normalize non‑breaking spaces
(U+00A0) to regular spaces (or remove them), then trim the result before testing
emptiness; update the $store_tnc normalization and the empty( trim( $store_tnc )
) check used when $enable_tnc is true so that entity-only or NBSP-only content
correctly triggers $error->add('dokan_tnc_content', ...).
|
@midu-01 validation not work for if I escape input by space, enter without any char. |
All Submissions:
Changes proposed in this Pull Request:
Previously, vendors could enable the Terms & Conditions option without providing any content.
This resulted in a blank storefront page for customers, which appeared broken and caused confusion.
This pull request adds backend form validation to prevent vendors from saving settings when:
The validation ensures that invalid state cannot be saved and improves both vendor and customer experience.
Related Pull Request(s)
Closes
How to test the changes in this Pull Request:
Changelog entry
Title:
Prevent enabling vendor Terms & Conditions without content
Description:
Previously, enabling Terms & Conditions without content caused a blank storefront page.
This change adds backend validation to block saving when the content field is empty, ensuring data integrity and preventing broken storefront pages.
Before Changes
After Changes
Feature Video (optional)
N/A
PR Self Review Checklist:
FOR PR REVIEWER ONLY:
Summary by CodeRabbit
Bug Fixes
Style
✏️ Tip: You can customize this high-level summary in your review settings.