PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.3
Yatra – Travel Booking & Tour Operator Software v3.0.3
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 2.0.11 All 82 releases
yatra / app / Providers / AppServiceProvider.php

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

169 lines 5.0 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 (FreeUpgradeRunner 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 // Persist + expose selected additional services on bookings (free fallback).
40 \Yatra\Services\AdditionalServicesBookingService::init();
41
42 // Ensure frontend bundles are marked as ES modules
43 add_filter('script_loader_tag', [$this, 'addFrontendModuleType'], 10, 2);
44
45 // Initialize utility hooks (admin bar, etc.)
46 \Yatra\Hooks\UtilsHooks::init();
47
48 // Initialize review and enquiry hooks
49 \Yatra\Hooks\ReviewHooks::init();
50
51 // Initialize REST API hooks
52 \Yatra\Hooks\RestApiHooks::init();
53
54 // Initialize cron hooks (trip lifecycle, etc.)
55 \Yatra\Hooks\CronHooks::init();
56
57 // Initialize notification hooks
58 \Yatra\Hooks\NotificationHooks::init();
59
60 // Initialize review reminder service
61 \Yatra\Services\ReviewReminderService::init();
62
63 // Initialize availability inventory hooks
64 \Yatra\Hooks\AvailabilityInventoryHooks::init();
65
66 // Initialize cache hooks
67 \Yatra\Hooks\CacheHooks::init();
68
69 add_filter('yatra_require_email_verification', static function (): bool {
70 return \Yatra\Services\SettingsService::isEnabled('require_email_verification');
71 });
72 }
73
74 /**
75 * Plugin activation
76 */
77 public function activate(): void
78 {
79 // Flush rewrite rules
80 flush_rewrite_rules();
81
82 // Run installer for fresh installation setup (centralized location)
83 \Yatra\Services\InstallerService::install();
84 }
85
86 /**
87 * Plugin deactivation
88 */
89 public function deactivate(): void
90 {
91 // Flush rewrite rules
92 flush_rewrite_rules();
93 }
94
95 /**
96 * Set default options
97 */
98 private function setDefaultOptions(): void
99 {
100 $defaults = [
101 'yatra_currency' => 'USD',
102 'yatra_currency_position' => 'before',
103 'yatra_decimal_places' => 2,
104 'yatra_thousand_separator' => ',',
105 'yatra_decimal_separator' => '.',
106 'yatra_trip_base' => 'trip',
107 'yatra_destination_base' => 'destination',
108 'yatra_activity_base' => 'activity',
109 'yatra_trip_category_base' => 'trip-category',
110 'yatra_booking_base' => 'bookings',
111 'yatra_use_booking_page' => false,
112 'yatra_customer_account_page' => '/my-account',
113 'yatra_auto_approve_reviews' => false,
114 'yatra_enable_reviews' => true,
115 'yatra_enable_enquiries' => true,
116 'yatra_enable_wishlist' => false,
117 'yatra_enable_coupons' => false,
118 'yatra_enable_dynamic_pricing' => false,
119 'yatra_enable_additional_services' => false,
120 'yatra_company_name' => get_bloginfo('name'),
121 'yatra_company_email' => get_option('admin_email'),
122 'yatra_company_phone' => '',
123 'yatra_company_address' => '',
124 'yatra_date_format' => get_option('date_format'),
125 'yatra_time_format' => get_option('time_format'),
126 ];
127
128 foreach ($defaults as $option => $default) {
129 if (get_option($option) === false) {
130 update_option($option, $default);
131 }
132 }
133 }
134
135 /**
136 * Register shortcodes
137 */
138 public function registerShortcodes(): void
139 {
140 // Initialize shortcode classes
141 $shortcodes = [
142 new \Yatra\Shortcodes\MyAccountShortcode(),
143 new \Yatra\Shortcodes\TripShortcode(),
144 ];
145
146 foreach ($shortcodes as $shortcode) {
147 $shortcode->register();
148 }
149 }
150
151
152 /**
153 * Add type="module" to frontend React bundles
154 */
155 public function addFrontendModuleType(string $tag, string $handle): string
156 {
157 static $module_handles = ['yatra-account-page'];
158
159 if (in_array($handle, $module_handles, true)) {
160 if (strpos($tag, 'type="module"') === false && strpos($tag, "type='module'") === false) {
161 $tag = str_replace('<script ', '<script type="module" ', $tag);
162 }
163 }
164
165 return $tag;
166 }
167
168 }
169