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

[Skip] payment in Setup wizard when no payment is active #2468

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions includes/Admin/SetupWizard.php
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
class SetupWizard {

/** @var string Currenct Step */
Copy link
Member

Choose a reason for hiding this comment

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

Pls fix the typo Currenct

protected $step = '';
protected string $current_step = '';
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

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.

Copy link
Member

Choose a reason for hiding this comment

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

Move the $custom_log prop declaration from WeDevs\Dokan\Vendor\SetupWizard class to this class.

    /** @var string custom logo url of the theme */
    protected $custom_logo = '';


/** @var array Steps for the setup wizard */
protected $steps = [];
@@ -266,10 +266,10 @@ public function setup_wizard() {
unset( $this->steps['recommended'] );
}

$this->step = current( array_keys( $this->steps ) );
$this->current_step = current( array_keys( $this->steps ) );
// 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'] ) );
}

$this->enqueue_scripts();
@@ -278,8 +278,8 @@ public function setup_wizard() {
isset( $_POST['_wpnonce'], $_POST['save_step'] )
&& wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'dokan-setup' )
&& ! empty( $_POST['save_step'] )
&& isset( $this->steps[ $this->step ]['handler'] ) ) {
call_user_func_array( $this->steps[ $this->step ]['handler'], [ $this ] );
&& isset( $this->steps[ $this->current_step ]['handler'] ) ) {
call_user_func_array( $this->steps[ $this->current_step ]['handler'], [ $this ] );
}

ob_start();
@@ -292,7 +292,7 @@ public function get_next_step_link() {

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 ],
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

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.

'_admin_sw_nonce' => wp_create_nonce( 'dokan_admin_setup_wizard_nonce' ),
]
);
@@ -310,10 +310,14 @@ public function setup_wizard_header() {
<meta name="viewport" content="width=device-width"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title><?php esc_html_e( 'Dokan &rsaquo; Setup Wizard', 'dokan-lite' ); ?></title>
<?php wp_print_scripts(); ?>
<?php do_action( 'admin_print_styles' ); ?>
<?php do_action( 'admin_head' ); ?>
<?php do_action( 'dokan_setup_wizard_styles' ); ?>
<?php
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' );
?>
</head>
<body class="wc-setup dokan-admin-setup-wizard wp-core-ui<?php echo get_transient( 'dokan_setup_wizard_no_wc' ) ? ' dokan-setup-wizard-activated-wc' : ''; ?>">
<?php
@@ -328,7 +332,7 @@ public function setup_wizard_header() {
*/
public function setup_wizard_footer() {
?>
<?php if ( 'next_steps' === $this->step ) : ?>
<?php if ( 'next_steps' === $this->current_step ) : ?>
<a class="wc-return-to-dashboard" href="<?php echo esc_url( admin_url() ); ?>"><?php esc_html_e( 'Return to the WordPress Dashboard', 'dokan-lite' ); ?></a>
<?php endif; ?>
</body>
@@ -347,9 +351,9 @@ public function setup_wizard_steps() {
<?php foreach ( $ouput_steps as $step_key => $step ) : ?>
<li class="
<?php
if ( $step_key === $this->step ) {
if ( $step_key === $this->current_step ) {
echo 'active';
} elseif ( array_search( $this->step, array_keys( $this->steps ), true ) > array_search( $step_key, array_keys( $this->steps ), true ) ) {
} elseif ( array_search( $this->current_step, array_keys( $this->steps ), true ) > array_search( $step_key, array_keys( $this->steps ), true ) ) {
echo 'done';
}
?>
@@ -363,13 +367,13 @@ public function setup_wizard_steps() {
* Output the content for the current step.
*/
public function setup_wizard_content() {
if ( empty( $this->steps[ $this->step ]['view'] ) ) {
if ( empty( $this->steps[ $this->current_step ]['view'] ) ) {
wp_safe_redirect( esc_url_raw( add_query_arg( 'step', 'introduction' ) ) );
exit;
}

echo '<div class="wc-setup-content">';
call_user_func( $this->steps[ $this->step ]['view'] );
call_user_func( $this->steps[ $this->current_step ]['view'] );
echo '</div>';
}

@@ -500,7 +504,7 @@ public function dokan_setup_selling() {
/**
* Commission step.
*
* @since 3.14.0
* @since DOKAN_SINCE
*
* @return void
*/
@@ -547,7 +551,7 @@ public function dokan_setup_selling_save() {
/**
* Save commission options.
*
* @since 3.14.0
* @since DOKAN_SINCE
*
* @return void
*/
@@ -831,12 +835,12 @@ public function dokan_setup_withdraw_save() {
$options['withdraw_methods'] = ! empty( $_POST['withdraw_methods'] ) ? wc_clean( wp_unslash( $_POST['withdraw_methods'] ) ) : [];
$options['withdraw_order_status'] = ! empty( $_POST['withdraw_order_status'] ) ? wc_clean( wp_unslash( $_POST['withdraw_order_status'] ) ) : [];

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;
}
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;
}

/**
* Filter dokan_withdraw options before saving in setup wizard
8 changes: 4 additions & 4 deletions includes/Admin/SetupWizardNoWC.php
Original file line number Diff line number Diff line change
@@ -73,13 +73,13 @@ protected function set_setup_wizard_template() {
* @return void
*/
public function setup_wizard_content() {
if ( empty( $this->steps[ $this->step ]['view'] ) ) {
if ( empty( $this->steps[ $this->current_step ]['view'] ) ) {
wp_safe_redirect( esc_url_raw( add_query_arg( 'step', 'install_woocommerce' ) ) );
exit;
}

echo '<div class="wc-setup-content">';
call_user_func( $this->steps[ $this->step ]['view'] );
call_user_func( $this->steps[ $this->current_step ]['view'] );
echo '</div>';
}

@@ -92,8 +92,8 @@ public function setup_wizard_content() {
*/
public function setup_wizard_footer() {
?>
<a class="wc-return-to-dashboard" href="<?php echo esc_url( admin_url() ); ?>"><?php esc_html_e( 'Return to the WordPress Dashboard', 'dokan-lite' ); ?></a>
</body>
<a class="wc-return-to-dashboard" href="<?php echo esc_url( admin_url() ); ?>"><?php esc_html_e( 'Return to the WordPress Dashboard', 'dokan-lite' ); ?></a>
</body>
</html>
<?php
}
Loading