diff --git a/includes/Admin/SetupWizard.php b/includes/Admin/SetupWizard.php index 800c02ada4..b664636271 100644 --- a/includes/Admin/SetupWizard.php +++ b/includes/Admin/SetupWizard.php @@ -11,9 +11,11 @@ */ class SetupWizard { - /** @var string Currenct Step */ - protected $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 = []; @@ -266,10 +268,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 +280,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 +294,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' ), ] ); @@ -310,10 +312,14 @@ public function setup_wizard_header() { <?php esc_html_e( 'Dokan › Setup Wizard', 'dokan-lite' ); ?> - - - - + - step ) : ?> + current_step ) : ?> @@ -347,9 +353,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 +506,7 @@ public function dokan_setup_selling() { /** * Commission step. * - * @since 3.14.0 + * @since DOKAN_SINCE * * @return void */ @@ -547,7 +553,7 @@ public function dokan_setup_selling_save() { /** * Save commission options. * - * @since 3.14.0 + * @since DOKAN_SINCE * * @return void */ @@ -831,12 +837,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 +65,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 +101,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 +115,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 +194,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 +206,14 @@ public function dokan_setup_store() { - + ' . __( 'This is required', 'dokan-lite' ) . ''; } ?> @@ -247,7 +230,7 @@ public function dokan_setup_store() { ' . __( 'This is required', 'dokan-lite' ) . ''; } ?> @@ -259,13 +242,13 @@ public function dokan_setup_store() { - + ' . __( 'This is required', 'dokan-lite' ) . ''; } ?> @@ -276,13 +259,13 @@ public function dokan_setup_store() { - + ' . __( 'This is required', 'dokan-lite' ) . ''; } ?> @@ -293,7 +276,7 @@ public function dokan_setup_store() { - + ' . __( 'This is required', 'dokan-lite' ) . ''; } ?> @@ -313,13 +296,13 @@ public function dokan_setup_store() { - + ' . __( 'This is required', 'dokan-lite' ) . ''; } ?> @@ -502,7 +485,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 +506,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 +590,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 +653,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 ) ); + } }