-
Notifications
You must be signed in to change notification settings - Fork 205
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/setup wizard enhancements PHPCS Fix #2465
base: fix/Setup-wizard-enhancements-#3454
Are you sure you want to change the base?
Fix/setup wizard enhancements PHPCS Fix #2465
Conversation
…r-Setup-Wizard-#3303
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes primarily involve modifications to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 and nitpick comments (5)
includes/Vendor/SetupWizard.php (5)
220-220
: Specify the PHPCS sniff when ignoring coding standardsWhen using
// phpcs:ignore
, it's recommended to specify the exact PHPCS sniff code being ignored for clarity and maintainability.Apply this diff:
- $request_data = wc_clean( wp_unslash( $_POST ) ); // phpcs:ignore + $request_data = wc_clean( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
238-240
: Improve error message handling for required fieldsThe error messages for required fields are repeated multiple times. Consider creating a helper function to display error messages to reduce code duplication and improve maintainability.
You could refactor the error message display into a function:
function display_error( $field_name ) { echo '<span class="required">' . __( 'This is required', 'dokan-lite' ) . '</span>'; }Then use it like this:
if ( ! empty( $request_data[ 'error_' . $field_name ] ) ) { display_error( $field_name ); }Also applies to: 255-257, 273-275, 290-292, 309-311, 327-329
528-529
: Simplify complex conditional for better readabilityThe conditional expression is complex and hard to read. Simplifying it will improve readability and maintainability.
Consider refactoring the condition as follows:
if ( empty( $dokan_settings['address']['country'] ) ) { $is_valid_form = false; $_POST['error_address[country]'] = 'error'; } elseif ( isset( $states[ $dokan_settings['address']['country'] ] ) && count( $states[ $dokan_settings['address']['country'] ] ) && empty( $dokan_settings['address']['state'] ) ) { $is_valid_form = false; $_POST['error_address[state]'] = 'error'; }
612-616
: Simplifyarray_filter
usage by omitting the callback
array_filter
without a callback automatically removes empty elements. You can simplify the code by omitting the custom callback function.Apply this diff:
- $user_bank_data = array_filter( - $dokan_settings['payment']['bank'], function ( $item ) { - return ! empty( $item ); - } - ); + $user_bank_data = array_filter( $dokan_settings['payment']['bank'] );
621-624
: Avoid using$_POST
to store error messagesStoring error messages in
$_POST
is not recommended as it may lead to unexpected behavior. Consider using a separate array to store and handle error messages.You could introduce an
$errors
array:$errors[ 'error_' . $require_field ] = 'error';And use it accordingly throughout your validation logic.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
includes/Admin/SetupWizard.php
(1 hunks)includes/Vendor/SetupWizard.php
(12 hunks)
🔇 Additional comments (2)
includes/Vendor/SetupWizard.php (2)
39-40
: Parameter rename improves clarity
The parameter $var
has been renamed to $url
, enhancing code readability and understanding of its purpose.
126-126
: Enqueue emoji styles on the frontend
Including wp_enqueue_emoji_styles();
ensures that emoji styles are loaded on the frontend, improving user experience.
wp_print_scripts(); | ||
wp_enqueue_emoji_styles(); | ||
do_action( 'admin_print_styles' ); | ||
wp_enqueue_admin_bar_header_styles(); | ||
do_action( 'admin_head' ); | ||
do_action( 'dokan_setup_wizard_styles' ); | ||
?> |
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.
Adjust the order of function calls to ensure styles are properly enqueued and printed
Currently, wp_enqueue_emoji_styles();
and wp_enqueue_admin_bar_header_styles();
are called after wp_print_scripts();
, which means the styles may not be printed correctly. Enqueue all scripts and styles before calling wp_print_scripts();
to ensure they are included in the output.
Apply this diff to fix the order:
<?php
+ wp_enqueue_emoji_styles();
+ wp_enqueue_admin_bar_header_styles();
wp_print_scripts();
do_action( 'admin_print_styles' );
- wp_enqueue_emoji_styles();
- wp_enqueue_admin_bar_header_styles();
do_action( 'admin_head' );
do_action( 'dokan_setup_wizard_styles' );
?>
📝 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.
wp_print_scripts(); | |
wp_enqueue_emoji_styles(); | |
do_action( 'admin_print_styles' ); | |
wp_enqueue_admin_bar_header_styles(); | |
do_action( 'admin_head' ); | |
do_action( 'dokan_setup_wizard_styles' ); | |
?> | |
wp_enqueue_emoji_styles(); | |
wp_enqueue_admin_bar_header_styles(); | |
wp_print_scripts(); | |
do_action( 'admin_print_styles' ); | |
do_action( 'admin_head' ); | |
do_action( 'dokan_setup_wizard_styles' ); | |
?> |
All Submissions:
Changes proposed in this Pull Request:
Related Pull Request(s)
Closes
How to test the changes in this Pull Request:
Changelog entry
Title
Detailed Description of the pull request. What was previous behaviour
and what will be changed in this PR.
Before Changes
Describe the issue before changes with screenshots(s).
After Changes
Describe the issue after changes with screenshot(s).
Feature Video (optional)
Link of detailed video if this PR is for a feature.
PR Self Review Checklist:
FOR PR REVIEWER ONLY:
Summary by CodeRabbit
New Features
Bug Fixes
Documentation