-
Notifications
You must be signed in to change notification settings - Fork 206
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
[Skip] payment in Setup wizard when no payment is active #2468
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThe changes in this pull request involve renaming the protected variable Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
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: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
includes/Admin/SetupWizard.php
(10 hunks)includes/Admin/SetupWizardNoWC.php
(2 hunks)includes/Vendor/SetupWizard.php
(16 hunks)
🔇 Additional comments (1)
includes/Admin/SetupWizardNoWC.php (1)
76-82
: Consistent Use of $this->current_step
The variable $this->current_step
is correctly used to reference the current step, aligning with the updated property name and maintaining consistency across the setup wizard implementation.
includes/Vendor/SetupWizard.php
Outdated
/** @var string Current Step */ | ||
protected string $current_step = ''; |
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.
Ensure PHP Version Compatibility with Typed Properties
The use of typed properties, such as protected string $current_step = '';
, requires PHP 7.4 or higher. Please confirm that the project's minimum PHP version supports this feature to avoid compatibility issues.
|
||
// get step from url | ||
if ( isset( $_GET['_admin_sw_nonce'], $_GET['step'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_admin_sw_nonce'] ) ), 'dokan_admin_setup_wizard_nonce' ) ) { | ||
$this->step = sanitize_key( wp_unslash( $_GET['step'] ) ); | ||
$this->current_step = sanitize_key( wp_unslash( $_GET['step'] ) ) ?? current( array_keys( $this->steps ) ); |
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.
Confirm PHP Version Compatibility with Null Coalescing Operator
The use of the null coalescing operator ??
in $this->current_step = sanitize_key( wp_unslash( $_GET['step'] ) ) ?? current( array_keys( $this->steps ) );
requires PHP 7.0 or higher. Please verify that the project's minimum PHP version supports this operator.
@@ -12,7 +12,7 @@ | |||
class SetupWizard { | |||
|
|||
/** @var string Currenct Step */ | |||
protected $step = ''; | |||
protected string $current_step = ''; |
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.
Ensure PHP Version Compatibility with Typed Properties
The use of typed properties, such as protected string $current_step = '';
, requires PHP 7.4 or higher. Please confirm that the project's minimum PHP version supports this feature to avoid compatibility issues.
@@ -292,7 +292,7 @@ | |||
|
|||
return add_query_arg( | |||
[ | |||
'step' => $keys[ array_search( $this->step, array_keys( $this->steps ), true ) + 1 ], | |||
'step' => $keys[ array_search( $this->current_step, array_keys( $this->steps ), true ) + 1 ], |
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.
Handle Potential Array Offset Error in get_next_step_link
Method
When calculating the next step, array_search( $this->current_step, array_keys( $this->steps ), true ) + 1
may exceed the bounds of the $keys
array if $this->current_step
is the last element. This could lead to an undefined index notice. Consider adding a check to ensure the computed index exists in $keys
before accessing it.
Apply this diff to handle the array offset error:
public function get_next_step_link() {
$keys = array_keys( $this->steps );
- return add_query_arg(
- [
- 'step' => $keys[ array_search( $this->current_step, array_keys( $this->steps ), true ) + 1 ],
- '_admin_sw_nonce' => wp_create_nonce( 'dokan_admin_setup_wizard_nonce' ),
- ]
- );
+ $current_index = array_search( $this->current_step, $keys, true );
+ if ( false !== $current_index && isset( $keys[ $current_index + 1 ] ) ) {
+ $next_step = $keys[ $current_index + 1 ];
+ } else {
+ $next_step = '';
+ }
+ return add_query_arg(
+ [
+ 'step' => $next_step,
+ '_admin_sw_nonce' => wp_create_nonce( 'dokan_admin_setup_wizard_nonce' ),
+ ]
+ );
}
Committable suggestion skipped: line range outside the PR's diff.
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: 0
🧹 Nitpick comments (3)
includes/Vendor/SetupWizard.php (3)
Line range hint
31-46
: Consider refactoring for better readabilityThe method could be simplified using early returns and guard clauses.
public function filter_woocommerce_registration_redirect( $url ) { - $user = wp_get_current_user(); + $user = wp_get_current_user(); + if ( ! in_array( 'seller', $user->roles, true ) ) { + return $url; + } - if ( in_array( 'seller', $user->roles, true ) ) { - $url = dokan_get_navigation_url(); + $url = dokan_get_navigation_url(); - if ( 'off' === dokan_get_option( 'disable_welcome_wizard', 'dokan_selling', 'off' ) ) { - $url = apply_filters( 'dokan_seller_setup_wizard_url', site_url( '?page=dokan-seller-setup' ) ); - } + if ( 'off' === dokan_get_option( 'disable_welcome_wizard', 'dokan_selling', 'off' ) ) { + return apply_filters( 'dokan_seller_setup_wizard_url', site_url( '?page=dokan-seller-setup' ) ); } return $url; }
71-78
: LGTM! Consider adding more descriptive commentsThe payment step redirection logic is well-implemented and secure. However, the code would benefit from a more descriptive comment explaining the business logic.
- // If payment step is accessed but no active methods exist, redirect to next step + // Skip the payment step and redirect to the next step when accessed directly + // but no active payment/withdrawal methods are configured in the system. + // This prevents users from accessing an empty payment configuration page. if ( isset( $_GET['step'] ) && 'payment' === $_GET['step'] ) {
Line range hint
593-606
: Fix indentation in array_filter callbackThe indentation in the array_filter callback is using tabs instead of spaces, which is inconsistent with the rest of the file.
$user_bank_data = array_filter( $dokan_settings['payment']['bank'], function ( $item ) { - return ! empty( $item ); + return ! empty( $item ); } );
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
includes/Vendor/SetupWizard.php
(15 hunks)
🔇 Additional comments (2)
includes/Vendor/SetupWizard.php (2)
657-683
: LGTM! Well-documented and type-safe implementation
The get_next_step_link()
method is well-implemented with:
- Clear PHPDoc documentation
- Proper type hints and return type declaration
- Secure URL generation with proper escaping
- Edge case handling for payment step skipping
685-734
: LGTM! Well-structured and extensible implementation
The set_steps()
method is well-implemented with:
- Clear separation of concerns
- Proper conditional logic for payment step
- Good use of filters for extensibility
- Correct initialization of current step
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
Summary by CodeRabbit
New Features
Bug Fixes
Refactor