From 33fc50f7a6f49c4ea48138387edb7c4f04dd91d8 Mon Sep 17 00:00:00 2001 From: osman sufy Date: Fri, 6 Dec 2024 15:43:33 +0600 Subject: [PATCH 1/4] [Skip] payment in Setup wizard --- includes/Admin/SetupWizard.php | 38 ++--- includes/Admin/SetupWizardNoWC.php | 8 +- includes/Vendor/SetupWizard.php | 242 +++++++++++++++++++---------- 3 files changed, 181 insertions(+), 107 deletions(-) diff --git a/includes/Admin/SetupWizard.php b/includes/Admin/SetupWizard.php index 800c02ada4..81a38ab354 100644 --- a/includes/Admin/SetupWizard.php +++ b/includes/Admin/SetupWizard.php @@ -12,7 +12,7 @@ class SetupWizard { /** @var string Currenct Step */ - protected $step = ''; + protected string $current_step = ''; /** @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 ], '_admin_sw_nonce' => wp_create_nonce( 'dokan_admin_setup_wizard_nonce' ), ] ); @@ -328,7 +328,7 @@ public function setup_wizard_header() { */ public function setup_wizard_footer() { ?> - step ) : ?> + current_step ) : ?> @@ -347,9 +347,9 @@ public function setup_wizard_steps() { $step ) : ?>
  • '; - call_user_func( $this->steps[ $this->step ]['view'] ); + call_user_func( $this->steps[ $this->current_step ]['view'] ); echo ''; } @@ -500,7 +500,7 @@ public function dokan_setup_selling() { /** * Commission step. * - * @since 3.14.0 + * @since DOKAN_SINCE * * @return void */ @@ -547,7 +547,7 @@ public function dokan_setup_selling_save() { /** * Save commission options. * - * @since 3.14.0 + * @since DOKAN_SINCE * * @return void */ @@ -831,12 +831,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 diff --git a/includes/Admin/SetupWizardNoWC.php b/includes/Admin/SetupWizardNoWC.php index 3c15210fe9..50816728ba 100644 --- a/includes/Admin/SetupWizardNoWC.php +++ b/includes/Admin/SetupWizardNoWC.php @@ -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 '
    '; - call_user_func( $this->steps[ $this->step ]['view'] ); + call_user_func( $this->steps[ $this->current_step ]['view'] ); echo '
    '; } @@ -92,8 +92,8 @@ public function setup_wizard_content() { */ public function setup_wizard_footer() { ?> - - + + roles, true ) ) { @@ -73,39 +73,25 @@ public function setup_wizard() { $this->store_id = dokan_get_current_user_id(); $this->store_info = dokan_get_store_info( $this->store_id ); - $steps = [ - 'introduction' => [ - 'name' => __( 'Introduction', 'dokan-lite' ), - 'view' => [ $this, 'dokan_setup_introduction' ], - 'handler' => '', - ], - 'store' => [ - 'name' => __( 'Store', 'dokan-lite' ), - 'view' => [ $this, 'dokan_setup_store' ], - 'handler' => [ $this, 'dokan_setup_store_save' ], - ], - 'payment' => [ - 'name' => __( 'Payment', 'dokan-lite' ), - 'view' => [ $this, 'dokan_setup_payment' ], - 'handler' => [ $this, 'dokan_setup_payment_save' ], - ], - 'next_steps' => [ - 'name' => __( 'Ready!', 'dokan-lite' ), - 'view' => [ $this, 'dokan_setup_ready' ], - 'handler' => '', - ], - ]; + // Setup wizard steps + $this->set_steps(); - $this->steps = apply_filters( 'dokan_seller_wizard_steps', $steps ); - $this->step = current( array_keys( $this->steps ) ); + // If payment step is accessed but no active methods exist, redirect to next step + if ( isset( $_GET['step'] ) && 'payment' === $_GET['step'] ) { + $active_methods = dokan_withdraw_get_active_methods(); + if ( empty( $active_methods ) ) { + wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); + exit; + } + } // 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 ) ); } - if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { // WPCS: CSRF ok. - call_user_func( $this->steps[ $this->step ]['handler'] ); + if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->current_step ]['handler'] ) ) { // WPCS: CSRF ok. + call_user_func( $this->steps[ $this->current_step ]['handler'] ); } $this->enqueue_scripts(); @@ -123,6 +109,7 @@ public function setup_wizard() { */ public function frontend_enqueue_scripts() { wp_enqueue_style( 'jquery-ui' ); + wp_enqueue_emoji_styles(); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery-tiptip' ); wp_enqueue_script( 'jquery-blockui' ); @@ -136,50 +123,51 @@ public function frontend_enqueue_scripts() { /** * Setup Wizard Header. */ - public function setup_wizard_header() { - ?> - - > - - - - <?php esc_attr_e( 'Vendor › Setup Wizard', 'dokan-lite' ); ?> - - - - - - custom_logo ) ) { ?> -

    - - <?php echo esc_attr( get_bloginfo( 'name' ) ); ?> - -

    - ' . esc_attr( get_bloginfo( 'name' ) ) . ''; - } + public function setup_wizard_header() { + ?> + + > + + + + <?php esc_attr_e( 'Vendor › Setup Wizard', 'dokan-lite' ); ?> + + + + + + custom_logo ) ) { ?> +

    + + <?php echo esc_attr( get_bloginfo( 'name' ) ); ?> + +

    + ' . esc_attr( get_bloginfo( 'name' ) ) . ''; + } } /** * Setup Wizard Footer. */ public function setup_wizard_footer() { - ?> - step ) : ?> - - - - - + current_step ) : ?> + + + + + Thank you for choosing The Marketplace to power your online store! This quick setup wizard will help you configure the basic settings. It’s completely optional and shouldn’t take longer than two minutes.

    ', 'dokan-lite' ) ); + $dashboard_url = dokan_get_navigation_url(); + // translators: %1$s and %2$s are HTML tags for bold text + $default_message = wp_kses_post( sprintf( __( 'Thank you for choosing The Marketplace to power your online store! This quick setup wizard will help you configure the basic settings. %1$sIt’s completely optional and shouldn’t take longer than two minutes.%2$s', 'dokan-lite' ), '', '' ) ); $setup_wizard_message = dokan_get_option( 'setup_wizard_message', 'dokan_general', $default_message ); ?>

    @@ -214,6 +202,9 @@ public function dokan_setup_store() { $country_obj = new WC_Countries(); $countries = $country_obj->get_allowed_countries(); $states = $country_obj->states; + + $request_data = wc_clean( wp_unslash( $_POST ) ); // phpcs:ignore + ?>

    @@ -223,14 +214,14 @@ public function dokan_setup_store() { - + ' . __( 'This is required', 'dokan-lite' ) . ''; } ?> @@ -247,7 +238,7 @@ public function dokan_setup_store() { ' . __( 'This is required', 'dokan-lite' ) . ''; } ?> @@ -259,13 +250,13 @@ public function dokan_setup_store() { - + ' . __( 'This is required', 'dokan-lite' ) . ''; } ?> @@ -276,13 +267,13 @@ public function dokan_setup_store() { - + ' . __( 'This is required', 'dokan-lite' ) . ''; } ?> @@ -293,7 +284,7 @@ public function dokan_setup_store() { - + ' . __( 'This is required', 'dokan-lite' ) . ''; } ?> @@ -313,13 +304,13 @@ public function dokan_setup_store() { - + ' . __( 'This is required', 'dokan-lite' ) . ''; } ?> @@ -502,7 +493,10 @@ public function dokan_setup_store_save() { $dokan_settings['location'] = isset( $_POST['location'] ) ? sanitize_text_field( wp_unslash( $_POST['location'] ) ) : ''; $dokan_settings['find_address'] = isset( $_POST['find_address'] ) ? sanitize_text_field( wp_unslash( $_POST['find_address'] ) ) : ''; $dokan_settings['show_email'] = isset( $_POST['show_email'] ) ? 'yes' : 'no'; - + $country = $dokan_settings['address']['country'] ?? ''; + $state = $dokan_settings['address']['state'] ?? ''; + $country_has_states = isset( $states[ $country ] ) && count( $states[ $country ] ) > 0; + $state_is_empty = empty( $state ); // Validating fileds. // Validating fileds. $is_valid_form = true; if ( empty( $dokan_settings['address']['street_1'] ) ) { @@ -520,12 +514,9 @@ public function dokan_setup_store_save() { if ( empty( $dokan_settings['address']['country'] ) ) { $is_valid_form = false; $_POST['error_address[country]'] = 'error'; - } - else { - if ( ( isset( $states[ $dokan_settings['address']['country'] ] ) && count( $states[ $dokan_settings['address']['country'] ] ) && empty( $dokan_settings['address']['state'] ) || ( ! isset( $states[ $dokan_settings['address']['country'] ] ) && empty( $dokan_settings['address']['state'] ) ) ) ) { - $is_valid_form = false; - $_POST['error_address[state]'] = 'error'; - } + } elseif ( ( $country_has_states && $state_is_empty ) || ( ! $country_has_states && $state_is_empty ) ) { + $is_valid_form = false; + $_POST['error_address[state]'] = 'error'; } if ( ! $is_valid_form ) { @@ -607,12 +598,16 @@ public function dokan_setup_payment_save() { 'swift' => $bank['swift'], ]; - $user_bank_data = array_filter( $dokan_settings['payment']['bank'], function( $item ) { return ! empty( $item ); } ); + $user_bank_data = array_filter( + $dokan_settings['payment']['bank'], function ( $item ) { + return ! empty( $item ); + } + ); $require_fields = array_keys( dokan_bank_payment_required_fields() ); $has_bank_information = true; foreach ( $require_fields as $require_field ) { - if( empty( $user_bank_data[ $require_field ] ) ) { + if ( empty( $user_bank_data[ $require_field ] ) ) { $_POST[ 'error_' . $require_field ] = 'error'; $has_bank_information = false; } @@ -666,4 +661,83 @@ public function dokan_setup_ready() { steps ); + $step = array_search( $this->current_step, $keys, true ); + ++$step; + + // If next step is payment but there are no active methods, skip to the following step + if ( 'payment' === $keys[ $step ] && empty( dokan_withdraw_get_active_methods() ) ) { + ++$step; + } + $next_step = $keys[ $step ] ?? ''; + return add_query_arg( + [ + 'step' => apply_filters( 'dokan_seller_wizard_next_step', $next_step, $this->current_step, $this->steps ), + '_admin_sw_nonce' => wp_create_nonce( 'dokan_admin_setup_wizard_nonce' ), + ] + ); + } + + /** + * Sets up the wizard steps + * + * Defines the steps for the setup wizard, conditionally including + * the payment step only if active withdrawal methods exist + * + * @since 2.9.27 + * + * @return void + */ + protected function set_steps() { + $steps = [ + 'introduction' => [ + 'name' => __( 'Introduction', 'dokan-lite' ), + 'view' => [ $this, 'dokan_setup_introduction' ], + 'handler' => '', + ], + 'store' => [ + 'name' => __( 'Store', 'dokan-lite' ), + 'view' => [ $this, 'dokan_setup_store' ], + 'handler' => [ $this, 'dokan_setup_store_save' ], + ], + ]; + + // Only add payment step if there are active withdrawal methods + $active_methods = dokan_withdraw_get_active_methods(); + if ( ! empty( $active_methods ) ) { + $steps['payment'] = [ + 'name' => __( 'Payment', 'dokan-lite' ), + 'view' => [ $this, 'dokan_setup_payment' ], + 'handler' => [ $this, 'dokan_setup_payment_save' ], + ]; + } + + $steps['next_steps'] = [ + 'name' => __( 'Ready!', 'dokan-lite' ), + 'view' => [ $this, 'dokan_setup_ready' ], + 'handler' => '', + ]; + + /** + * Filter the seller wizard steps + * + * @since 2.9.27 + * + * @param array $steps Array of wizard steps + */ + $this->steps = apply_filters( 'dokan_seller_wizard_steps', $steps ); + $this->current_step = current( array_keys( $this->steps ) ); + } } From 61b707da572894c0e8d46532aaa671a05e8d5856 Mon Sep 17 00:00:00 2001 From: osman sufy Date: Thu, 12 Dec 2024 10:31:47 +0600 Subject: [PATCH 2/4] fix: deprecated notice in admin setup wizard --- includes/Admin/SetupWizard.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/includes/Admin/SetupWizard.php b/includes/Admin/SetupWizard.php index 81a38ab354..710753a6e4 100644 --- a/includes/Admin/SetupWizard.php +++ b/includes/Admin/SetupWizard.php @@ -310,10 +310,14 @@ public function setup_wizard_header() { <?php esc_html_e( 'Dokan › Setup Wizard', 'dokan-lite' ); ?> - - - - + Date: Fri, 27 Dec 2024 15:51:30 +0600 Subject: [PATCH 3/4] update: according to feedback $custom_logo & type mistake --- includes/Admin/SetupWizard.php | 4 +++- includes/Vendor/SetupWizard.php | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/Admin/SetupWizard.php b/includes/Admin/SetupWizard.php index 710753a6e4..b664636271 100644 --- a/includes/Admin/SetupWizard.php +++ b/includes/Admin/SetupWizard.php @@ -11,9 +11,11 @@ */ class SetupWizard { - /** @var string Currenct Step */ + /** @var string Current Step */ protected string $current_step = ''; + /** @var string custom logo url of the theme */ + protected $custom_logo = ''; /** @var array Steps for the setup wizard */ protected $steps = []; diff --git a/includes/Vendor/SetupWizard.php b/includes/Vendor/SetupWizard.php index 8bf2a12530..be1aa167d3 100644 --- a/includes/Vendor/SetupWizard.php +++ b/includes/Vendor/SetupWizard.php @@ -15,8 +15,6 @@ class SetupWizard extends DokanSetupWizard { /** @var array Steps for the setup wizard */ protected $steps = []; - /** @var string custom logo url of the theme */ - protected $custom_logo = ''; /** * @var int */ From e71788ecf441caaf77e6908fd91b5401c7bd2af0 Mon Sep 17 00:00:00 2001 From: osman sufy Date: Mon, 30 Dec 2024 12:04:47 +0600 Subject: [PATCH 4/4] update: removed redundant properties declare in vendor/SetupWizard --- includes/Vendor/SetupWizard.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/includes/Vendor/SetupWizard.php b/includes/Vendor/SetupWizard.php index be1aa167d3..2ca068a64c 100644 --- a/includes/Vendor/SetupWizard.php +++ b/includes/Vendor/SetupWizard.php @@ -9,12 +9,6 @@ * Seller setup wizard class */ class SetupWizard extends DokanSetupWizard { - /** @var string Current Step */ - protected string $current_step = ''; - - /** @var array Steps for the setup wizard */ - protected $steps = []; - /** * @var int */