Skip to content

Commit

Permalink
[Skip] payment in Setup wizard when no payment is active (#2468)
Browse files Browse the repository at this point in the history
* [Skip] payment in Setup wizard

* fix: deprecated notice in admin setup wizard

* update: according to feedback $custom_logo & type mistake

* update: removed redundant properties declare in vendor/SetupWizard
  • Loading branch information
osmansufy authored Jan 3, 2025
1 parent 4a5d435 commit c159994
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 118 deletions.
54 changes: 30 additions & 24 deletions includes/Admin/SetupWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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' ),
]
);
Expand All @@ -310,10 +312,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
Expand All @@ -328,7 +334,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>
Expand All @@ -347,9 +353,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';
}
?>
Expand All @@ -363,13 +369,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>';
}

Expand Down Expand Up @@ -500,7 +506,7 @@ public function dokan_setup_selling() {
/**
* Commission step.
*
* @since 3.14.0
* @since DOKAN_SINCE
*
* @return void
*/
Expand Down Expand Up @@ -547,7 +553,7 @@ public function dokan_setup_selling_save() {
/**
* Save commission options.
*
* @since 3.14.0
* @since DOKAN_SINCE
*
* @return void
*/
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions includes/Admin/SetupWizardNoWC.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>';
}

Expand All @@ -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
}
Expand Down
Loading

0 comments on commit c159994

Please sign in to comment.