PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.6
Yatra – Travel Booking & Tour Operator Software v3.0.2.6
3.0.16 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 All 84 releases
yatra / app / Providers / AppServiceProvider.php

AppServiceProvider.php in Yatra – Travel Booking & Tour Operator Software 3.0.2.6, at app/Providers/AppServiceProvider.php

166 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yatra\Providers;
4
5 use WP_REST_Request;
6 use Yatra\Core\ServiceProvider;
7
8 /**
9 * Service provider for Yatra plugin
10 */
11 class AppServiceProvider extends ServiceProvider
12 {
13 /**
14 * Register services
15 */
16 public function register(): void
17 {
18
19
20 // Activation hook
21 register_activation_hook(YATRA_PLUGIN_FILE, [$this, 'activate']);
22
23 // Deactivation hook
24 register_deactivation_hook(YATRA_PLUGIN_FILE, [$this, 'deactivate']);
25
26 // Database tables: created on activation (see activate()) and on version bump (Bootstrap::upgrade on admin_init).
27
28 // Register shortcodes
29 $this->registerShortcodes();
30
31 // Blocks are registered in Bootstrap, not here
32
33 // Initialize template loader for all frontend routing
34 \Yatra\Core\TemplateLoader::init();
35
36 // Initialize ItineraryCostService for free itinerary costs feature
37 \Yatra\Services\ItineraryCostService::init();
38
39 // Ensure frontend bundles are marked as ES modules
40 add_filter('script_loader_tag', [$this, 'addFrontendModuleType'], 10, 2);
41
42 // Initialize utility hooks (admin bar, etc.)
43 \Yatra\Hooks\UtilsHooks::init();
44
45 // Initialize review and enquiry hooks
46 \Yatra\Hooks\ReviewHooks::init();
47
48 // Initialize REST API hooks
49 \Yatra\Hooks\RestApiHooks::init();
50
51 // Initialize cron hooks (trip lifecycle, etc.)
52 \Yatra\Hooks\CronHooks::init();
53
54 // Initialize notification hooks
55 \Yatra\Hooks\NotificationHooks::init();
56
57 // Initialize review reminder service
58 \Yatra\Services\ReviewReminderService::init();
59
60 // Initialize availability inventory hooks
61 \Yatra\Hooks\AvailabilityInventoryHooks::init();
62
63 // Initialize cache hooks
64 \Yatra\Hooks\CacheHooks::init();
65
66 add_filter('yatra_require_email_verification', static function (): bool {
67 return \Yatra\Services\SettingsService::isEnabled('require_email_verification');
68 });
69 }
70
71 /**
72 * Plugin activation
73 */
74 public function activate(): void
75 {
76 // Flush rewrite rules
77 flush_rewrite_rules();
78
79 // Run installer for fresh installation setup (centralized location)
80 \Yatra\Services\InstallerService::install();
81 }
82
83 /**
84 * Plugin deactivation
85 */
86 public function deactivate(): void
87 {
88 // Flush rewrite rules
89 flush_rewrite_rules();
90 }
91
92 /**
93 * Set default options
94 */
95 private function setDefaultOptions(): void
96 {
97 $defaults = [
98 'yatra_currency' => 'USD',
99 'yatra_currency_position' => 'before',
100 'yatra_decimal_places' => 2,
101 'yatra_thousand_separator' => ',',
102 'yatra_decimal_separator' => '.',
103 'yatra_trip_base' => 'trip',
104 'yatra_destination_base' => 'destination',
105 'yatra_activity_base' => 'activity',
106 'yatra_trip_category_base' => 'trip-category',
107 'yatra_booking_base' => 'bookings',
108 'yatra_use_booking_page' => false,
109 'yatra_customer_account_page' => '/my-account',
110 'yatra_auto_approve_reviews' => false,
111 'yatra_enable_reviews' => true,
112 'yatra_enable_enquiries' => true,
113 'yatra_enable_wishlist' => false,
114 'yatra_enable_coupons' => false,
115 'yatra_enable_dynamic_pricing' => false,
116 'yatra_enable_additional_services' => false,
117 'yatra_company_name' => get_bloginfo('name'),
118 'yatra_company_email' => get_option('admin_email'),
119 'yatra_company_phone' => '',
120 'yatra_company_address' => '',
121 'yatra_date_format' => get_option('date_format'),
122 'yatra_time_format' => get_option('time_format'),
123 ];
124
125 foreach ($defaults as $option => $default) {
126 if (get_option($option) === false) {
127 update_option($option, $default);
128 }
129 }
130 }
131
132 /**
133 * Register shortcodes
134 */
135 public function registerShortcodes(): void
136 {
137 // Initialize shortcode classes
138 $shortcodes = [
139 new \Yatra\Shortcodes\MyAccountShortcode(),
140 new \Yatra\Shortcodes\TripShortcode(),
141 ];
142
143 foreach ($shortcodes as $shortcode) {
144 $shortcode->register();
145 }
146 }
147
148
149 /**
150 * Add type="module" to frontend React bundles
151 */
152 public function addFrontendModuleType(string $tag, string $handle): string
153 {
154 static $module_handles = ['yatra-account-page'];
155
156 if (in_array($handle, $module_handles, true)) {
157 if (strpos($tag, 'type="module"') === false && strpos($tag, "type='module'") === false) {
158 $tag = str_replace('<script ', '<script type="module" ', $tag);
159 }
160 }
161
162 return $tag;
163 }
164
165 }
166