PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.6
Yatra – Travel Booking & Tour Operator Software v3.0.6
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.6, at app/Providers/AppServiceProvider.php

188 lines 6.2 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 add_filter('yatra_require_email_verification', static function (): bool {
89 return \Yatra\Services\SettingsService::isEnabled('require_email_verification');
90 });
91 }
92
93 /**
94 * Plugin activation
95 */
96 public function activate(): void
97 {
98 // Flush rewrite rules
99 flush_rewrite_rules();
100
101 // Run installer for fresh installation setup (centralized location)
102 \Yatra\Services\InstallerService::install();
103 }
104
105 /**
106 * Plugin deactivation
107 */
108 public function deactivate(): void
109 {
110 // Flush rewrite rules
111 flush_rewrite_rules();
112 }
113
114 /**
115 * Set default options
116 */
117 private function setDefaultOptions(): void
118 {
119 $defaults = [
120 'yatra_currency' => 'USD',
121 'yatra_currency_position' => 'before',
122 'yatra_decimal_places' => 2,
123 'yatra_thousand_separator' => ',',
124 'yatra_decimal_separator' => '.',
125 'yatra_trip_base' => 'trip',
126 'yatra_destination_base' => 'destination',
127 'yatra_activity_base' => 'activity',
128 'yatra_trip_category_base' => 'trip-category',
129 'yatra_booking_base' => 'bookings',
130 'yatra_use_booking_page' => false,
131 'yatra_customer_account_page' => '/my-account',
132 'yatra_auto_approve_reviews' => false,
133 'yatra_enable_reviews' => true,
134 'yatra_enable_enquiries' => true,
135 'yatra_enable_wishlist' => false,
136 'yatra_enable_coupons' => false,
137 'yatra_enable_dynamic_pricing' => false,
138 'yatra_enable_additional_services' => false,
139 'yatra_company_name' => get_bloginfo('name'),
140 'yatra_company_email' => get_option('admin_email'),
141 'yatra_company_phone' => '',
142 'yatra_company_address' => '',
143 'yatra_date_format' => get_option('date_format'),
144 'yatra_time_format' => get_option('time_format'),
145 ];
146
147 foreach ($defaults as $option => $default) {
148 if (get_option($option) === false) {
149 update_option($option, $default);
150 }
151 }
152 }
153
154 /**
155 * Register shortcodes
156 */
157 public function registerShortcodes(): void
158 {
159 // Initialize shortcode classes
160 $shortcodes = [
161 new \Yatra\Shortcodes\MyAccountShortcode(),
162 new \Yatra\Shortcodes\TripShortcode(),
163 ];
164
165 foreach ($shortcodes as $shortcode) {
166 $shortcode->register();
167 }
168 }
169
170
171 /**
172 * Add type="module" to frontend React bundles
173 */
174 public function addFrontendModuleType(string $tag, string $handle): string
175 {
176 static $module_handles = ['yatra-account-page'];
177
178 if (in_array($handle, $module_handles, true)) {
179 if (strpos($tag, 'type="module"') === false && strpos($tag, "type='module'") === false) {
180 $tag = str_replace('<script ', '<script type="module" ', $tag);
181 }
182 }
183
184 return $tag;
185 }
186
187 }
188