Skip to content
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

Open
wants to merge 8 commits into
base: fix/Setup-wizard-enhancements-#3454
Choose a base branch
from

Conversation

osmansufy
Copy link
Contributor

@osmansufy osmansufy commented Dec 6, 2024

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

  • Full PR Link

Closes

  • Closes #

How to test the changes in this Pull Request:

  • Steps or issue link

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:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • New Features

    • Enhanced setup wizard functionality, including improved handling of user input and script/style management.
    • Added checks for user capabilities and plugin activation status during setup.
    • Streamlined process for installing recommended plugins.
  • Bug Fixes

    • Improved error handling for address fields and validation logic in the setup process.
  • Documentation

    • Updated method signatures for better clarity and consistency.

Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes primarily involve modifications to the SetupWizard class in two files: includes/Admin/SetupWizard.php and includes/Vendor/SetupWizard.php. Enhancements focus on improving the setup wizard's functionality, including better handling of scripts and styles, user input validation, and error handling. Key updates include new checks for user capabilities, refined logic for displaying setup steps, and improved security measures for handling user data.

Changes

File Path Change Summary
includes/Admin/SetupWizard.php - Added enqueue calls for admin bar and emoji styles in the constructor and setup_wizard_header method.
- Updated setup_wizard method to check user capabilities before setup steps.
- Enhanced dokan_setup_recommended method to check plugin activation status.
- Updated dokan_setup_recommended_save method to install inactive plugins.
includes/Vendor/SetupWizard.php - Renamed parameter $var to $url in filter_woocommerce_registration_redirect method.
- Added emoji styles in frontend_enqueue_scripts method.
- Used sprintf for message formatting in dokan_setup_introduction method.
- Introduced $request_data for sanitized input in dokan_setup_store method.
- Refined validation logic in dokan_setup_store_save method.

Possibly related PRs

  • [Fix] Deprecated Noticed on Admin Setup Wizard #2414: This PR modifies the SetupWizard.php file, specifically enhancing the setup_wizard_header method to properly enqueue styles, which is directly related to the changes made in the main PR that also focuses on improving the handling of scripts and styles in the SetupWizard class.
  • Fix admin fixed commission setting validation #2437: This PR updates the dokan_setup_commission_save method in SetupWizard.php to include validation logic for commission percentage inputs, which aligns with the main PR's focus on refining the setup wizard's functionality and user experience.
  • Fix commission upgrader #2463: This PR addresses the commission upgrader functionality, which involves changes to the handling of commission values that may relate to the overall setup process managed by the SetupWizard, indicating a connection to the main PR's enhancements in user interface and setup logic.

Suggested labels

QA approved, :+1: Dev Review Done

Suggested reviewers

  • mrabbani
  • shohag121

Poem

🐰 In the wizard's realm, we hop and play,
With styles and scripts, we pave the way.
User checks in place, so smooth the ride,
Plugins activated, with joy we abide.
A setup so bright, like the sun's warm glow,
Let's dance through the steps, and let the magic flow! ✨


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?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

@osmansufy osmansufy changed the base branch from develop to fix/Setup-wizard-enhancements-#3454 December 6, 2024 06:19
Copy link
Contributor

@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 and nitpick comments (5)
includes/Vendor/SetupWizard.php (5)

220-220: Specify the PHPCS sniff when ignoring coding standards

When 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 fields

The 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 readability

The 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: Simplify array_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 messages

Storing 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

📥 Commits

Reviewing files that changed from the base of the PR and between 490a380 and 25d4277.

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

Comment on lines +273 to +279
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' );
?>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
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' );
?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant