PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.7
Yatra – Travel Booking & Tour Operator Software v3.0.2.7
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 / ShortcodeServiceProvider.php

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

123 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Providers;
6
7 use Yatra\Shortcodes\MyAccountShortcode;
8 use Yatra\Shortcodes\TripShortcode;
9 use Yatra\Shortcodes\ActivityShortcode;
10 use Yatra\Shortcodes\DestinationShortcode;
11 use Yatra\Shortcodes\DiscountAndDealsShortcode;
12 use Yatra\Shortcodes\SearchShortcode;
13 use Yatra\Shortcodes\LoginShortcode;
14 use Yatra\Ajax\TripShortcodeAjax;
15 use Yatra\Ajax\ActivityShortcodeAjax;
16 use Yatra\Ajax\DestinationShortcodeAjax;
17 use Yatra\Ajax\DiscountShortcodeAjax;
18 use Yatra\Ajax\LoginAjax;
19 use Yatra\Ajax\GeocodingAjax;
20
21 /**
22 * Shortcode Service Provider
23 *
24 * Registers all Yatra shortcodes
25 */
26 class ShortcodeServiceProvider extends \Yatra\Core\ServiceProvider
27 {
28 /**
29 * Register services with production optimizations
30 */
31 public function register(): void
32 {
33 // Register all shortcodes immediately, not on init hook
34 $this->registerShortcodes();
35
36 // Register AJAX handlers with error handling
37 $this->registerAjaxHandlers();
38 }
39
40 /**
41 * Register AJAX handlers with error handling and lazy loading
42 */
43 private function registerAjaxHandlers(): void
44 {
45 $ajax_handlers = [
46 'TripShortcodeAjax',
47 'ActivityShortcodeAjax',
48 'DestinationShortcodeAjax',
49 'DiscountShortcodeAjax',
50 'LoginAjax',
51 'GeocodingAjax',
52 'DirectAttributeQuery',
53 ];
54
55 foreach ($ajax_handlers as $handler_class) {
56 try {
57 $full_class_name = "\\Yatra\\Ajax\\{$handler_class}";
58
59 if (class_exists($full_class_name)) {
60 new $full_class_name();
61 } else {
62 // Log error for debugging
63 if (defined('WP_DEBUG') && WP_DEBUG) {
64 error_log("Yatra ShortcodeServiceProvider: AJAX handler class {$full_class_name} not found");
65 }
66 }
67 } catch (Exception $e) {
68 // Log error for debugging
69 if (defined('WP_DEBUG') && WP_DEBUG) {
70 error_log("Yatra ShortcodeServiceProvider: Failed to register AJAX handler {$handler_class}: " . $e->getMessage());
71 }
72 }
73 }
74 }
75
76 /**
77 * Register all shortcodes with production optimizations
78 */
79 public function registerShortcodes(): void
80 {
81 $shortcodes = [
82 'yatra_my_account' => MyAccountShortcode::class,
83 'yatra_trip' => TripShortcode::class,
84 'yatra_activity' => ActivityShortcode::class,
85 'yatra_destination' => DestinationShortcode::class,
86 'yatra_discount_and_deals' => DiscountAndDealsShortcode::class,
87 'yatra_search' => SearchShortcode::class,
88 'yatra_login' => LoginShortcode::class,
89 ];
90
91 foreach ($shortcodes as $tag => $class) {
92 try {
93 if (class_exists($class)) {
94 $shortcode = new $class();
95
96 // Validate that the shortcode class has the register method
97 if (method_exists($shortcode, 'register')) {
98 $shortcode->register();
99 } else {
100 // Log error for debugging
101 if (defined('WP_DEBUG') && WP_DEBUG) {
102 error_log("Yatra ShortcodeServiceProvider: Shortcode class {$class} missing register method");
103 }
104 }
105 } else {
106 // Log error for debugging
107 if (defined('WP_DEBUG') && WP_DEBUG) {
108 error_log("Yatra ShortcodeServiceProvider: Shortcode class {$class} not found");
109 }
110 }
111 } catch (Exception $e) {
112 // Log error for debugging
113 if (defined('WP_DEBUG') && WP_DEBUG) {
114 error_log("Yatra ShortcodeServiceProvider: Failed to register shortcode {$tag}: " . $e->getMessage());
115 }
116
117 // Continue with other shortcodes even if one fails
118 continue;
119 }
120 }
121 }
122 }
123