PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.7
Yatra – Travel Booking & Tour Operator Software v3.0.7
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / app / Services / SetupWizardService.php

SetupWizardService.php in Yatra – Travel Booking & Tour Operator Software 3.0.7, at app/Services/SetupWizardService.php

97 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Setup Wizard Service
4 * Handles setup wizard initialization and registration
5 *
6 * @package Yatra\Services
7 * @since 3.0.0
8 */
9
10 namespace Yatra\Services;
11
12 use Yatra\Controllers\SetupWizardController;
13
14 defined('ABSPATH') || exit;
15
16 class SetupWizardService
17 {
18 /**
19 * Initialize the setup wizard service
20 */
21 public static function init(): void
22 {
23 // Only initialize in admin
24 if (!is_admin()) {
25 return;
26 }
27
28 // Initialize the setup wizard controller on plugins_loaded
29 add_action('plugins_loaded', [__CLASS__, 'initController']);
30
31 // Register activation hook handler
32 add_action('admin_init', [__CLASS__, 'handleWizardRedirect']);
33
34 // Force redirect to setup wizard if not completed
35 add_action('admin_init', [__CLASS__, 'forceWizardRedirect']);
36 }
37
38 /**
39 * Initialize the setup wizard controller
40 */
41 public static function initController(): void
42 {
43 new SetupWizardController();
44 }
45
46 /**
47 * Handle wizard redirect after plugin activation
48 */
49 public static function handleWizardRedirect(): void
50 {
51 SetupWizardController::setup_wizard_redirect();
52 }
53
54 /**
55 * Force redirect to setup wizard if not completed
56 * This implements the legacy logic: if yatra_setup_wizard_ran != '1', redirect to setup wizard
57 */
58 public static function forceWizardRedirect(): void
59 {
60 // Only apply to users who can manage options
61 if (!current_user_can('manage_options')) {
62 return;
63 }
64
65 // Check if setup wizard is enabled via filter (legacy compatibility)
66 if (!apply_filters('yatra_enable_setup_wizard', true)) {
67 return;
68 }
69
70 // Check if wizard has been completed (yatra_setup_wizard_ran != '1')
71 if (get_option('yatra_setup_wizard_ran') !== '1') {
72 // Don't redirect if we're already on the setup wizard page
73 if (isset($_GET['page']) && $_GET['page'] === 'yatra-setup') {
74 return;
75 }
76
77 // Don't redirect on AJAX requests
78 if (wp_doing_ajax()) {
79 return;
80 }
81
82 // Force redirect to setup wizard
83 wp_safe_redirect(admin_url('admin.php?page=yatra-setup'));
84 exit;
85 }
86 }
87
88 /**
89 * Trigger wizard redirect on plugin activation
90 * Called from activation hook
91 */
92 public static function triggerWizardOnActivation(): void
93 {
94 set_transient('yatra_setup_wizard_redirect', 1, 30);
95 }
96 }
97