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

196 lines 6.7 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 // Load the reCAPTCHA v3 script on the frontend when enabled (self-guards).
68 add_action('wp_enqueue_scripts', ['\\Yatra\\Services\\RecaptchaService', 'enqueueScript']);
69
70 // Garbage-collect deleted-trip IDs out of user wishlist meta.
71 \Yatra\Hooks\SavedTripHooks::init();
72
73 // Initialize REST API hooks
74 \Yatra\Hooks\RestApiHooks::init();
75
76 // Initialize cron hooks (trip lifecycle, etc.)
77 \Yatra\Hooks\CronHooks::init();
78
79 // Initialize notification hooks
80 \Yatra\Hooks\NotificationHooks::init();
81
82 // Initialize review reminder service
83 \Yatra\Services\ReviewReminderService::init();
84
85 // Initialize availability inventory hooks
86 \Yatra\Hooks\AvailabilityInventoryHooks::init();
87
88 // Initialize cache hooks
89 \Yatra\Hooks\CacheHooks::init();
90
91 // Publish Yatra trips/destinations/activities/categories to sitemaps
92 // (WP core, Yoast, Rank Math, AIOSEO) — Yatra content lives in custom
93 // tables, so no SEO generator can discover it without this.
94 \Yatra\Sitemap\SitemapManager::init();
95
96 add_filter('yatra_require_email_verification', static function (): bool {
97 return \Yatra\Services\SettingsService::isEnabled('require_email_verification');
98 });
99 }
100
101 /**
102 * Plugin activation
103 */
104 public function activate(): void
105 {
106 // Flush rewrite rules
107 flush_rewrite_rules();
108
109 // Run installer for fresh installation setup (centralized location)
110 \Yatra\Services\InstallerService::install();
111 }
112
113 /**
114 * Plugin deactivation
115 */
116 public function deactivate(): void
117 {
118 // Flush rewrite rules
119 flush_rewrite_rules();
120 }
121
122 /**
123 * Set default options
124 */
125 private function setDefaultOptions(): void
126 {
127 $defaults = [
128 'yatra_currency' => 'USD',
129 'yatra_currency_position' => 'before',
130 'yatra_decimal_places' => 2,
131 'yatra_thousand_separator' => ',',
132 'yatra_decimal_separator' => '.',
133 'yatra_trip_base' => 'trip',
134 'yatra_destination_base' => 'destination',
135 'yatra_activity_base' => 'activity',
136 'yatra_trip_category_base' => 'trip-category',
137 'yatra_booking_base' => 'bookings',
138 'yatra_use_booking_page' => false,
139 'yatra_customer_account_page' => '/my-account',
140 'yatra_auto_approve_reviews' => false,
141 'yatra_enable_reviews' => true,
142 'yatra_enable_enquiries' => true,
143 'yatra_enable_wishlist' => false,
144 'yatra_enable_coupons' => false,
145 'yatra_enable_dynamic_pricing' => false,
146 'yatra_enable_additional_services' => false,
147 'yatra_company_name' => get_bloginfo('name'),
148 'yatra_company_email' => get_option('admin_email'),
149 'yatra_company_phone' => '',
150 'yatra_company_address' => '',
151 'yatra_date_format' => get_option('date_format'),
152 'yatra_time_format' => get_option('time_format'),
153 ];
154
155 foreach ($defaults as $option => $default) {
156 if (get_option($option) === false) {
157 update_option($option, $default);
158 }
159 }
160 }
161
162 /**
163 * Register shortcodes
164 */
165 public function registerShortcodes(): void
166 {
167 // Initialize shortcode classes
168 $shortcodes = [
169 new \Yatra\Shortcodes\MyAccountShortcode(),
170 new \Yatra\Shortcodes\TripShortcode(),
171 ];
172
173 foreach ($shortcodes as $shortcode) {
174 $shortcode->register();
175 }
176 }
177
178
179 /**
180 * Add type="module" to frontend React bundles
181 */
182 public function addFrontendModuleType(string $tag, string $handle): string
183 {
184 static $module_handles = ['yatra-account-page'];
185
186 if (in_array($handle, $module_handles, true)) {
187 if (strpos($tag, 'type="module"') === false && strpos($tag, "type='module'") === false) {
188 $tag = str_replace('<script ', '<script type="module" ', $tag);
189 }
190 }
191
192 return $tag;
193 }
194
195 }
196