Skip to content

Commit 12d233d

Browse files
committed
Redirect to setup wizard on install
1 parent 9aec53a commit 12d233d

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

includes/admin/class-activator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ public static function single_activate() {
9797
// Then flush them.
9898
global $wp_rewrite;
9999
$wp_rewrite->init();
100-
flush_rewrite_rules( false );
100+
flush_rewrite_rules();
101+
102+
// Set a transient to trigger wizard redirect (30-second expiry).
103+
set_transient( 'wzkb_activation_redirect', true, 30 );
101104
}
102105

103106
/**

includes/admin/class-setup-wizard.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Setup_Wizard {
4848
public function __construct() {
4949
Hook_Registry::add_action( 'admin_menu', array( $this, 'admin_menus' ), PHP_INT_MAX );
5050
Hook_Registry::add_action( 'admin_init', array( $this, 'setup_wizard' ), PHP_INT_MAX );
51+
Hook_Registry::add_action( 'admin_init', array( $this, 'redirect_on_activation' ) );
5152
Hook_Registry::add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), PHP_INT_MAX );
5253
}
5354

@@ -721,4 +722,35 @@ public function enqueue_scripts() {
721722
);
722723
wp_enqueue_script( 'wzkb-wizard' );
723724
}
725+
726+
/**
727+
* Redirect to wizard on plugin activation.
728+
*
729+
* @since 3.0.0
730+
*
731+
* @return void
732+
*/
733+
public function redirect_on_activation() {
734+
// Check if transient is set (plugin was just activated).
735+
if ( ! get_transient( 'wzkb_activation_redirect' ) ) {
736+
return;
737+
}
738+
739+
// Delete transient to prevent repeated redirects.
740+
delete_transient( 'wzkb_activation_redirect' );
741+
742+
// Only redirect for users with manage_options and if wizard not completed.
743+
if ( ! current_user_can( 'manage_options' ) || get_option( 'wzkb_setup_completed' ) ) {
744+
return;
745+
}
746+
747+
// Avoid redirecting during bulk activations or AJAX requests.
748+
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_GET['activate-multi'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
749+
return;
750+
}
751+
752+
// Redirect to wizard page.
753+
wp_safe_redirect( admin_url( 'edit.php?post_type=wz_knowledgebase&page=wzkb-setup' ) );
754+
exit;
755+
}
724756
}

0 commit comments

Comments
 (0)