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] Deprecated Noticed on Admin Setup Wizard #2414

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

osmansufy
Copy link
Contributor

@osmansufy osmansufy commented Oct 24, 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

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

  • Bug Fixes

    • Improved the handling of styles and scripts in the setup wizard's header for better visual consistency, including the addition of emoji styles.
  • Chores

    • Minor adjustments made to the setup wizard's methods for enhanced style management and readability without changing functionality.
    • Enhanced clarity in method parameters and improved error handling for better readability.

@osmansufy osmansufy added the Needs: Dev Review It requires a developer review and approval label Oct 24, 2024
@osmansufy osmansufy self-assigned this Oct 24, 2024
Copy link
Contributor

coderabbitai bot commented Oct 24, 2024

Walkthrough

The changes in SetupWizard.php focus on the setup_wizard_header method, where the handling of styles and scripts has been updated. The implementation now includes calls to wp_enqueue_emoji_styles() and wp_enqueue_admin_bar_header_styles() before invoking the existing actions for admin_print_styles and admin_head. Additionally, the frontend_enqueue_scripts method in Vendor/SetupWizard.php has been modified to enqueue emoji styles, and various minor adjustments have been made for clarity and readability.

Changes

File Change Summary
includes/Admin/SetupWizard.php Updated setup_wizard_header to include wp_enqueue_emoji_styles() and wp_enqueue_admin_bar_header_styles().
includes/Vendor/SetupWizard.php Modified frontend_enqueue_scripts to enqueue wp_enqueue_emoji_styles(). Updated parameter name in filter_woocommerce_registration_redirect and improved formatting in dokan_setup_introduction. Adjusted error handling in dokan_setup_store_save.

Assessment against linked issues

Objective Addressed Explanation
Resolve deprecated notices in Admin and Vendor Setup Wizard (#3303)

Possibly related PRs

Suggested labels

QA approved, :+1: Dev Review Done, Upcoming Release

Suggested reviewers

  • mrabbani
  • shohag121

Poem

In the wizard's realm, scripts now dance,
With emojis and styles, they take a chance.
A hop and a skip, the header's aglow,
In the setup's embrace, new styles will flow! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 06cb2ec and 25d4277.

📒 Files selected for processing (1)
  • includes/Vendor/SetupWizard.php (12 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • includes/Vendor/SetupWizard.php

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.

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: 0

🧹 Outside diff range and nitpick comments (3)
includes/Admin/SetupWizard.php (3)

Line range hint 1019-1029: Improve withdraw limit validation.

The withdraw limit validation could be strengthened to ensure proper numeric handling and prevent potential issues.

Consider this improved validation:

-if ( ! empty( $_POST['withdraw_limit'] ) ) {
-    $input_limit                = sanitize_text_field( wp_unslash( $_POST['withdraw_limit'] ) );
-    $options['withdraw_limit']  = is_numeric( $input_limit ) && $input_limit >= 0 ? wc_format_decimal( $input_limit ) : 0;
-} else {
-    $options['withdraw_limit'] = 0;
-}
+$input_limit = isset( $_POST['withdraw_limit'] ) ? sanitize_text_field( wp_unslash( $_POST['withdraw_limit'] ) ) : '';
+$options['withdraw_limit'] = is_numeric( $input_limit ) && $input_limit >= 0 ? wc_format_decimal( $input_limit ) : 0;

Line range hint 1264-1277: Consider adding nonce verification for plugin installation.

The plugin installation process should include additional security checks to prevent unauthorized installations.

Add nonce verification before proceeding with plugin installation:

 protected function install_plugin( $plugin_id, $plugin_info ) {
+    if ( ! current_user_can( 'install_plugins' ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'dokan-setup' ) ) {
+        wp_die( esc_html__( 'You are not authorized to perform this action.', 'dokan-lite' ) );
+    }
+
     // Make sure we don't trigger multiple simultaneous installs.
     if ( get_option( 'woocommerce_setup_background_installing_' . $plugin_id ) ) {
         return;
     }

Based on the gathered information, I can now provide a final response about the race condition concern.

The race condition concern is valid and the suggested solution using transients is appropriate

The current implementation has these potential issues:

  • Uses permanent options instead of transients for temporary installation flags
  • The cleanup of the installation flag happens in a shutdown hook, which might not execute if the process fails
  • No timeout mechanism exists for stale installation flags

The suggested solution using WordPress transients is better because:

  • Transients have built-in expiration, automatically cleaning up stale flags
  • They're designed for temporary data storage
  • The 5-minute timeout provides a safety net if the cleanup code doesn't execute
  • They use the object cache when available, providing better performance
🔗 Analysis chain

Line range hint 1267-1269: Potential race condition in background installation check.

The current implementation of preventing multiple simultaneous installs might be susceptible to race conditions.

Let's verify if there are any existing issues with concurrent installations:

Consider using WordPress transients with a short expiration time instead of options for the installation flag:

-if ( get_option( 'woocommerce_setup_background_installing_' . $plugin_id ) ) {
+if ( get_transient( 'woocommerce_setup_background_installing_' . $plugin_id ) ) {
     return;
 }
-update_option( 'woocommerce_setup_background_installing_' . $plugin_id, true );
+set_transient( 'woocommerce_setup_background_installing_' . $plugin_id, true, 5 * MINUTE_IN_SECONDS );

Let me gather more information about how this background installation process works and if there are any error handling mechanisms in place.


Let me check one more thing to understand how the deferred actions and shutdown hooks are implemented for the background installation process.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any reported issues or error handling related to concurrent plugin installations
rg -A 5 "woocommerce_setup_background_installing_"

Length of output: 1295


Script:

#!/bin/bash
# Search for the background installation method and related error handling
ast-grep --pattern 'function install_plugin_background($$$)'

# Look for any cleanup or error handling related to these installation flags
rg -B 2 -A 5 "delete_option.*woocommerce_setup_background_installing"

# Check if there are any other places where plugin installation status is checked
rg -B 2 -A 5 "is_plugin_active.*plugin_info"

Length of output: 1227


Script:

#!/bin/bash
# Look for the deferred actions implementation and shutdown hook handling
ast-grep --pattern 'function run_deferred_actions() {
  $$$
}'

# Check if there are any error handlers or status checks during installation
rg -B 2 -A 10 "class SetupWizard"

Length of output: 3900

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3832003 and 3e1082d.

📒 Files selected for processing (1)
  • includes/Admin/SetupWizard.php (1 hunks)
🔇 Additional comments (1)
includes/Admin/SetupWizard.php (1)

273-280: LGTM! Proper fix for deprecated notices.

The changes correctly address the deprecated notices by explicitly enqueueing required WordPress styles before the action hooks. The order of operations is correct:

  1. Enqueue emoji styles
  2. Print admin styles
  3. Enqueue admin bar header styles
  4. Execute admin head actions

Comment on lines 272 to 281
<?php wp_print_scripts(); ?>
<?php do_action( 'admin_print_styles' ); ?>
<?php do_action( 'admin_head' ); ?>
<?php
wp_enqueue_emoji_styles();
do_action( 'admin_print_styles' );
?>
<?php
wp_enqueue_admin_bar_header_styles();
do_action( 'admin_head' );
?>
<?php do_action( 'dokan_setup_wizard_styles' ); ?>
Copy link
Member

Choose a reason for hiding this comment

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

Pls put all PHP codeblock inside a single php tag.

Copy link
Member

@mrabbani mrabbani left a comment

Choose a reason for hiding this comment

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

@@ -319,7 +321,7 @@ public function dokan_setup_store() {
<input type="text" id="calc_shipping_state" name="address[state]" value="<?php echo esc_attr( $address_state ); ?>" / placeholder="<?php esc_attr_e( 'State Name', 'dokan-lite' ); ?>">
<span class="error-container">
<?php
if ( ! empty( $_POST['error_address[state]'] ) ) {
if ( ! empty( $_POST['error_address[state]'] ) ) { // phpcs:ignore
Copy link
Member

Choose a reason for hiding this comment

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

Assign the $_POST to a variable like $request_data to use safely instead of ignoring PHPCS everywhere.

@mrabbani mrabbani added Needs: Author Reply and removed Needs: Dev Review It requires a developer review and approval labels Nov 15, 2024
@osmansufy osmansufy added Needs: Dev Review It requires a developer review and approval and removed Needs: Author Reply labels Nov 18, 2024
Copy link
Member

@mrabbani mrabbani left a comment

Choose a reason for hiding this comment

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

Pls remove the existing $_POST usage.

@mrabbani mrabbani added Needs: Testing This requires further testing 👍 Dev Review Done and removed Needs: Dev Review It requires a developer review and approval labels Nov 19, 2024
@shashwatahalder01 shashwatahalder01 added QA In Progress QA approved This PR is approved by the QA team and removed Needs: Testing This requires further testing QA In Progress labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QA approved This PR is approved by the QA team 👍 Dev Review Done
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants