@@ -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