Merge pull request #13817 from woocommerce/improvement-13716

Allow setup wizard filtering
This commit is contained in:
Mike Jolley 2017-04-03 19:26:39 +01:00 committed by GitHub
commit c844ec6487
1 changed files with 28 additions and 5 deletions

View File

@ -54,7 +54,7 @@ class WC_Admin_Setup_Wizard {
if ( empty( $_GET['page'] ) || 'wc-setup' !== $_GET['page'] ) {
return;
}
$this->steps = array(
$default_steps = array(
'introduction' => array(
'name' => __( 'Introduction', 'woocommerce' ),
'view' => array( $this, 'wc_setup_introduction' ),
@ -86,6 +86,8 @@ class WC_Admin_Setup_Wizard {
'handler' => '',
),
);
$this->steps = apply_filters( 'woocommerce_setup_wizard_steps', $default_steps );
$this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) );
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
@ -116,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 );
}
ob_start();
@ -127,9 +129,30 @@ class WC_Admin_Setup_Wizard {
exit;
}
public function get_next_step_link() {
/**
* Get the URL for the next step's screen.
* @param string step slug (default: current step)
* @return string URL for next step if a next step exists.
* Admin URL if it's the last step.
* Empty string on failure.
* @since 3.0.0
*/
public function get_next_step_link( $step = '' ) {
if ( ! $step ) {
$step = $this->step;
}
$keys = array_keys( $this->steps );
return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ] );
if ( end( $keys ) === $step ) {
return admin_url();
}
$step_index = array_search( $step, $keys );
if ( false === $step_index ) {
return '';
}
return add_query_arg( 'step', $keys[ $step_index + 1 ] );
}
/**
@ -191,7 +214,7 @@ 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 );
echo '</div>';
}