Onboarding: Update help tab with reset onboarding link (https://github.com/woocommerce/woocommerce-admin/pull/2658)
* Update help tab reset link for onboarding profiler * Update wc_admin_url to allow dashboard URL * Add function to reset onboarding profiler params
This commit is contained in:
parent
69245c848b
commit
8784ac9728
|
@ -34,13 +34,13 @@ function wc_admin_number_format( $number ) {
|
|||
*
|
||||
* @return string Fully qualified URL pointing to the desired path.
|
||||
*/
|
||||
function wc_admin_url( $path, $query = array() ) {
|
||||
function wc_admin_url( $path = null, $query = array() ) {
|
||||
if ( ! empty( $query ) ) {
|
||||
$query_string = http_build_query( $query );
|
||||
$path = $path . '&' . $query_string;
|
||||
$path = $path ? '&path=' . $path . '&' . $query_string : '';
|
||||
}
|
||||
|
||||
return admin_url( 'admin.php?page=wc-admin&path=' . $path, dirname( __FILE__ ) );
|
||||
return admin_url( 'admin.php?page=wc-admin' . $path, dirname( __FILE__ ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,6 +48,8 @@ class WC_Admin_Onboarding {
|
|||
add_action( 'woocommerce_components_settings', array( $this, 'component_settings' ), 20 ); // Run after WC_Admin_Loader.
|
||||
add_action( 'woocommerce_theme_installed', array( $this, 'delete_themes_transient' ) );
|
||||
add_action( 'after_switch_theme', array( $this, 'delete_themes_transient' ) );
|
||||
add_action( 'current_screen', array( $this, 'update_help_tab' ), 60 );
|
||||
add_action( 'admin_init', array( $this, 'reset_onboarding' ) );
|
||||
add_filter( 'woocommerce_admin_is_loading', array( $this, 'is_loading' ) );
|
||||
add_filter( 'woocommerce_rest_prepare_themes', array( $this, 'add_uploaded_theme_data' ) );
|
||||
}
|
||||
|
@ -315,6 +317,58 @@ class WC_Admin_Onboarding {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the help tab setup link to reset the onboarding profiler.
|
||||
*/
|
||||
public static function update_help_tab() {
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ( ! $screen || ! in_array( $screen->id, wc_get_screen_ids(), true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$help_tabs = $screen->get_help_tabs();
|
||||
|
||||
foreach ( $help_tabs as $help_tab ) {
|
||||
if ( 'woocommerce_onboard_tab' !== $help_tab['id'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$screen->remove_help_tab( 'woocommerce_onboard_tab' );
|
||||
$help_tab['content'] = '<h2>' . __( 'Setup wizard', 'woocommerce-admin' ) . '</h2>' .
|
||||
'<p>' . __( 'If you need to access the setup wizard again, please click on the button below.', 'woocommerce-admin' ) . '</p>' .
|
||||
'<p><a href="' . wc_admin_url( '&reset_onboarding=1' ) . '" class="button button-primary">' . __( 'Setup wizard', 'woocommerce-admin' ) . '</a></p>';
|
||||
$screen->add_help_tab( $help_tab );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the onboarding profiler and redirect to the profiler.
|
||||
*/
|
||||
public static function reset_onboarding() {
|
||||
if (
|
||||
! WC_Admin_Loader::is_admin_page() ||
|
||||
! isset( $_GET['reset_onboarding'] ) || // WPCS: CSRF ok.
|
||||
1 !== absint( $_GET['reset_onboarding'] ) // WPCS: CSRF ok.
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$request = new WP_REST_Request( 'POST', '/wc-admin/v1/onboarding/profile' );
|
||||
$request->set_headers( array( 'content-type' => 'application/json' ) );
|
||||
$request->set_body(
|
||||
wp_json_encode(
|
||||
array(
|
||||
'completed' => false,
|
||||
'skipped' => false,
|
||||
)
|
||||
)
|
||||
);
|
||||
$response = rest_do_request( $request );
|
||||
|
||||
wp_safe_redirect( wc_admin_url() );
|
||||
}
|
||||
}
|
||||
|
||||
WC_Admin_Onboarding::get_instance();
|
||||
|
|
Loading…
Reference in New Issue