Better way of passing on the next stepg

This commit is contained in:
Claudiu Lodromanean 2017-03-29 11:22:55 -07:00
parent da0b048788
commit 27e1cffa30
3 changed files with 27 additions and 46 deletions

View File

@ -118,7 +118,7 @@ class WC_Admin_Setup_Wizard {
) );
if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) {
call_user_func( $this->steps[ $this->step ]['handler'] );
call_user_func( $this->steps[ $this->step ]['handler'], $this->get_next_step_link() );
}
ob_start();
@ -131,7 +131,11 @@ class WC_Admin_Setup_Wizard {
public function get_next_step_link() {
$keys = array_keys( $this->steps );
return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ] );
if ( end( $keys ) === $this->step ) {
return admin_url();
}
return add_query_arg( 'step', $keys[ array_search( $this->step, $keys ) + 1 ] );
}
/**
@ -193,20 +197,20 @@ class WC_Admin_Setup_Wizard {
*/
public function setup_wizard_content() {
echo '<div class="wc-setup-content">';
call_user_func( $this->steps[ $this->step ]['view'] );
call_user_func( $this->steps[ $this->step ]['view'], $this->get_next_step_link() );
echo '</div>';
}
/**
* Introduction step.
*/
public function wc_setup_introduction() {
public function wc_setup_introduction( $next_step_link ) {
?>
<h1><?php esc_html_e( 'Welcome to the world of WooCommerce!', 'woocommerce' ); ?></h1>
<p><?php _e( 'Thank you for choosing WooCommerce to power your online store! This quick setup wizard will help you configure the basic settings. <strong>Its completely optional and shouldnt take longer than five minutes.</strong>', 'woocommerce' ); ?></p>
<p><?php esc_html_e( 'No time right now? If you dont want to go through the wizard, you can skip and return to the WordPress dashboard. Come back anytime if you change your mind!', 'woocommerce' ); ?></p>
<p class="wc-setup-actions step">
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button-primary button button-large button-next"><?php esc_html_e( 'Let\'s go!', 'woocommerce' ); ?></a>
<a href="<?php echo esc_url( $next_step_link ); ?>" class="button-primary button button-large button-next"><?php esc_html_e( 'Let\'s go!', 'woocommerce' ); ?></a>
<a href="<?php echo esc_url( admin_url() ); ?>" class="button button-large"><?php esc_html_e( 'Not right now', 'woocommerce' ); ?></a>
</p>
<?php
@ -215,7 +219,7 @@ class WC_Admin_Setup_Wizard {
/**
* Page setup.
*/
public function wc_setup_pages() {
public function wc_setup_pages( $next_step_link ) {
?>
<h1><?php esc_html_e( 'Page setup', 'woocommerce' ); ?></h1>
<form method="post">
@ -255,7 +259,7 @@ class WC_Admin_Setup_Wizard {
<p class="wc-setup-actions step">
<input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Continue', 'woocommerce' ); ?>" name="save_step" />
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'woocommerce' ); ?></a>
<a href="<?php echo esc_url( $next_step_link ); ?>" class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'woocommerce' ); ?></a>
<?php wp_nonce_field( 'wc-setup' ); ?>
</p>
</form>
@ -265,18 +269,18 @@ class WC_Admin_Setup_Wizard {
/**
* Save Page Settings.
*/
public function wc_setup_pages_save() {
public function wc_setup_pages_save( $next_step_link ) {
check_admin_referer( 'wc-setup' );
WC_Install::create_pages();
wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
wp_redirect( esc_url_raw( $next_step_link ) );
exit;
}
/**
* Locale settings.
*/
public function wc_setup_locale() {
public function wc_setup_locale( $next_step_link ) {
$user_location = WC_Geolocation::geolocate_ip();
$country = ! empty( $user_location['country'] ) ? $user_location['country'] : 'US';
$state = ! empty( $user_location['state'] ) ? $user_location['state'] : '*';
@ -371,7 +375,7 @@ class WC_Admin_Setup_Wizard {
</table>
<p class="wc-setup-actions step">
<input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Continue', 'woocommerce' ); ?>" name="save_step" />
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'woocommerce' ); ?></a>
<a href="<?php echo esc_url( $next_step_link ); ?>" class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'woocommerce' ); ?></a>
<?php wp_nonce_field( 'wc-setup' ); ?>
</p>
</form>
@ -381,7 +385,7 @@ class WC_Admin_Setup_Wizard {
/**
* Save Locale Settings.
*/
public function wc_setup_locale_save() {
public function wc_setup_locale_save( $next_step_link ) {
check_admin_referer( 'wc-setup' );
$store_location = sanitize_text_field( $_POST['store_location'] );
@ -402,14 +406,14 @@ class WC_Admin_Setup_Wizard {
update_option( 'woocommerce_weight_unit', $weight_unit );
update_option( 'woocommerce_dimension_unit', $dimension_unit );
wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
wp_redirect( esc_url_raw( $next_step_link ) );
exit;
}
/**
* Shipping and taxes.
*/
public function wc_setup_shipping_taxes() {
public function wc_setup_shipping_taxes( $next_step_link ) {
?>
<h1><?php esc_html_e( 'Shipping &amp; Tax setup', 'woocommerce' ); ?></h1>
<form method="post">
@ -492,7 +496,7 @@ class WC_Admin_Setup_Wizard {
</table>
<p class="wc-setup-actions step">
<input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Continue', 'woocommerce' ); ?>" name="save_step" />
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'woocommerce' ); ?></a>
<a href="<?php echo esc_url( $next_step_link ); ?>" class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'woocommerce' ); ?></a>
<?php wp_nonce_field( 'wc-setup' ); ?>
</p>
</form>
@ -502,7 +506,7 @@ class WC_Admin_Setup_Wizard {
/**
* Save shipping and tax options.
*/
public function wc_setup_shipping_taxes_save() {
public function wc_setup_shipping_taxes_save( $next_step_link ) {
check_admin_referer( 'wc-setup' );
$enable_shipping = isset( $_POST['woocommerce_calc_shipping'] );
@ -553,7 +557,7 @@ class WC_Admin_Setup_Wizard {
}
}
wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
wp_redirect( esc_url_raw( $next_step_link ) );
exit;
}
@ -638,7 +642,7 @@ class WC_Admin_Setup_Wizard {
/**
* Payments Step.
*/
public function wc_setup_payments() {
public function wc_setup_payments( $next_step_link ) {
$gateways = $this->get_wizard_payment_gateways();
?>
<h1><?php esc_html_e( 'Payments', 'woocommerce' ); ?></h1>
@ -685,7 +689,7 @@ class WC_Admin_Setup_Wizard {
</ul>
<p class="wc-setup-actions step">
<input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Continue', 'woocommerce' ); ?>" name="save_step" />
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'woocommerce' ); ?></a>
<a href="<?php echo esc_url( $next_step_link ); ?>" class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'woocommerce' ); ?></a>
<?php wp_nonce_field( 'wc-setup' ); ?>
</p>
</form>
@ -695,7 +699,7 @@ class WC_Admin_Setup_Wizard {
/**
* Payments Step save.
*/
public function wc_setup_payments_save() {
public function wc_setup_payments_save( $next_step_link ) {
check_admin_referer( 'wc-setup' );
$gateways = $this->get_wizard_payment_gateways();
@ -719,7 +723,7 @@ class WC_Admin_Setup_Wizard {
update_option( $settings_key, $settings );
}
wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
wp_redirect( esc_url_raw( $next_step_link ) );
exit;
}
@ -741,7 +745,7 @@ class WC_Admin_Setup_Wizard {
/**
* Final step.
*/
public function wc_setup_ready() {
public function wc_setup_ready( $next_step_link ) {
$this->wc_setup_ready_actions();
shuffle( $this->tweets );
?>
@ -780,4 +784,4 @@ class WC_Admin_Setup_Wizard {
}
}
WC()->setup_wizard = new WC_Admin_Setup_Wizard();
new WC_Admin_Setup_Wizard();

View File

@ -299,19 +299,3 @@ function wc_save_order_items( $order_id, $items ) {
// Inform other plugins that the items have been saved
do_action( 'woocommerce_saved_order_items', $order_id, $items );
}
/**
* Get the URL for the next step in the setup wizard.
*
* @since 3.1
* @return string URL for step or empty string if called outside the setup wizard
*/
function woocommerce_setup_wizard_get_next_step_link() {
$wizard = WC()->setup_wizard;
if ( ! $wizard ) {
return "";
}
return $wizard->get_next_step_link();
}

View File

@ -108,13 +108,6 @@ final class WooCommerce {
*/
public $structured_data = null;
/**
* Setup Wizard instance.
*
* @var WC_Admin_Setup_Wizard
*/
public $setup_wizard = null;
/**
* Array of deprecated hook handlers.
*