PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.8
Yatra – Travel Booking & Tour Operator Software v3.0.8
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 / Providers / AppServiceProvider.php

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

193 lines 6.5 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 // Capability filters MUST install for every request type (admin,
19 // REST, AJAX, frontend, CLI). Previously they were only installed
20 // from AdminServiceProvider::registerAdminMenu(), which is hooked
21 // on `admin_menu` — a hook that DOES NOT fire during REST API
22 // requests. The admin SPA loads all data via REST, so the admin
23 // fallback that grants every yatra_* cap to users with
24 // manage_options never ran for those requests → site admins hit
25 // 403 "REST forbidden" on Settings, Bookings, Trips, etc.
26 //
27 // AdminServiceProvider itself is gated behind is_admin() in
28 // Bootstrap, which is false during pure REST requests, so even
29 // calling the static from there isn't enough. AppServiceProvider
30 // is in the always-loaded providers list, so calling the
31 // installer here guarantees the filters exist for every entry
32 // point. add_filter is idempotent — the AdminServiceProvider
33 // call stays in place for defence-in-depth.
34 \Yatra\Providers\AdminServiceProvider::bootstrapMenuCapability();
35
36 // Activation hook
37 register_activation_hook(YATRA_PLUGIN_FILE, [$this, 'activate']);
38
39 // Deactivation hook
40 register_deactivation_hook(YATRA_PLUGIN_FILE, [$this, 'deactivate']);
41
42 // Database tables: created on activation (see activate()) and on version bump (FreeUpgradeRunner on admin_init).
43
44 // Register shortcodes
45 $this->registerShortcodes();
46
47 // Blocks are registered in Bootstrap, not here
48
49 // Initialize template loader for all frontend routing
50 \Yatra\Core\TemplateLoader::init();
51
52 // Initialize ItineraryCostService for free itinerary costs feature
53 \Yatra\Services\ItineraryCostService::init();
54
55 // Persist + expose selected additional services on bookings (free fallback).
56 \Yatra\Services\AdditionalServicesBookingService::init();
57
58 // Ensure frontend bundles are marked as ES modules
59 add_filter('script_loader_tag', [$this, 'addFrontendModuleType'], 10, 2);
60
61 // Initialize utility hooks (admin bar, etc.)
62 \Yatra\Hooks\UtilsHooks::init();
63
64 // Initialize review and enquiry hooks
65 \Yatra\Hooks\ReviewHooks::init();
66
67 // Garbage-collect deleted-trip IDs out of user wishlist meta.
68 \Yatra\Hooks\SavedTripHooks::init();
69
70 // Initialize REST API hooks
71 \Yatra\Hooks\RestApiHooks::init();
72
73 // Initialize cron hooks (trip lifecycle, etc.)
74 \Yatra\Hooks\CronHooks::init();
75
76 // Initialize notification hooks
77 \Yatra\Hooks\NotificationHooks::init();
78
79 // Initialize review reminder service
80 \Yatra\Services\ReviewReminderService::init();
81
82 // Initialize availability inventory hooks
83 \Yatra\Hooks\AvailabilityInventoryHooks::init();
84
85 // Initialize cache hooks
86 \Yatra\Hooks\CacheHooks::init();
87
88 // Publish Yatra trips/destinations/activities/categories to sitemaps
89 // (WP core, Yoast, Rank Math, AIOSEO) — Yatra content lives in custom
90 // tables, so no SEO generator can discover it without this.
91 \Yatra\Sitemap\SitemapManager::init();
92
93 add_filter('yatra_require_email_verification', static function (): bool {
94 return \Yatra\Services\SettingsService::isEnabled('require_email_verification');
95 });
96 }
97
98 /**
99 * Plugin activation
100 */
101 public function activate(): void
102 {
103 // Flush rewrite rules
104 flush_rewrite_rules();
105
106 // Run installer for fresh installation setup (centralized location)
107 \Yatra\Services\InstallerService::install();
108 }
109
110 /**
111 * Plugin deactivation
112 */
113 public function deactivate(): void
114 {
115 // Flush rewrite rules
116 flush_rewrite_rules();
117 }
118
119 /**
120 * Set default options
121 */
122 private function setDefaultOptions(): void
123 {
124 $defaults = [
125 'yatra_currency' => 'USD',
126 'yatra_currency_position' => 'before',
127 'yatra_decimal_places' => 2,
128 'yatra_thousand_separator' => ',',
129 'yatra_decimal_separator' => '.',
130 'yatra_trip_base' => 'trip',
131 'yatra_destination_base' => 'destination',
132 'yatra_activity_base' => 'activity',
133 'yatra_trip_category_base' => 'trip-category',
134 'yatra_booking_base' => 'bookings',
135 'yatra_use_booking_page' => false,
136 'yatra_customer_account_page' => '/my-account',
137 'yatra_auto_approve_reviews' => false,
138 'yatra_enable_reviews' => true,
139 'yatra_enable_enquiries' => true,
140 'yatra_enable_wishlist' => false,
141 'yatra_enable_coupons' => false,
142 'yatra_enable_dynamic_pricing' => false,
143 'yatra_enable_additional_services' => false,
144 'yatra_company_name' => get_bloginfo('name'),
145 'yatra_company_email' => get_option('admin_email'),
146 'yatra_company_phone' => '',
147 'yatra_company_address' => '',
148 'yatra_date_format' => get_option('date_format'),
149 'yatra_time_format' => get_option('time_format'),
150 ];
151
152 foreach ($defaults as $option => $default) {
153 if (get_option($option) === false) {
154 update_option($option, $default);
155 }
156 }
157 }
158
159 /**
160 * Register shortcodes
161 */
162 public function registerShortcodes(): void
163 {
164 // Initialize shortcode classes
165 $shortcodes = [
166 new \Yatra\Shortcodes\MyAccountShortcode(),
167 new \Yatra\Shortcodes\TripShortcode(),
168 ];
169
170 foreach ($shortcodes as $shortcode) {
171 $shortcode->register();
172 }
173 }
174
175
176 /**
177 * Add type="module" to frontend React bundles
178 */
179 public function addFrontendModuleType(string $tag, string $handle): string
180 {
181 static $module_handles = ['yatra-account-page'];
182
183 if (in_array($handle, $module_handles, true)) {
184 if (strpos($tag, 'type="module"') === false && strpos($tag, "type='module'") === false) {
185 $tag = str_replace('<script ', '<script type="module" ', $tag);
186 }
187 }
188
189 return $tag;
190 }
191
192 }
193