PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
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
← All changes | app/Shortcodes/SearchShortcode.php +79 -2 3.0.5trunk View file →
@@ -23,9 +23,19 @@
23 23 'show_price_range' => 'yes',
24 24 'show_duration' => 'yes',
25 25 'show_difficulty' => 'yes',
26 26 'placeholder' => 'Search for tours...',
27 - 'button_text' => 'Search Tours'
27 + 'button_text' => 'Search Tours',
28 + // Per-field visibility overrides. Empty string = inherit the global
29 + // Settings → Search & Listing toggle (so [yatra_search] is unchanged).
30 + // Pass yes/no (or true/false, on/off, 1/0) to force a field on/off for
31 + // this one placement, e.g. [yatra_search budget="no" keyword="yes"].
32 + 'keyword' => '',
33 + 'destination' => '',
34 + 'activities' => '',
35 + 'duration' => '',
36 + 'budget' => '',
37 + 'date' => '',
28 38 ]);
29 39
30 40 // [yatra_search] may appear in posts, widgets, builders, FSE templates, or do_shortcode()
31 41 // with no reliable way to detect that before output. Enqueue on every public frontend
@@ -57,8 +67,35 @@
57 67 [],
58 68 $tripSearchCssVer
59 69 );
60 70
71 + // When the date field is enabled, load the same flatpickr library the
72 + // checkout/booking page uses, so the search date field gets the styled
73 + // calendar instead of the browser's native one. Gated on the global
74 + // toggle so the extra CSS/JS only ships where the field is actually
75 + // used; the search JS self-guards on `typeof flatpickr`, so a per-
76 + // placement [yatra_search date="yes"] override still falls back safely
77 + // to the native input when flatpickr is not present. Shared 'yatra-
78 + // flatpickr' handle → WordPress de-dupes if another component enqueues
79 + // it too.
80 + $searchJsDeps = ['jquery'];
81 + if (\Yatra\Services\SettingsService::isEnabled('search_show_date')) {
82 + wp_enqueue_style(
83 + 'yatra-flatpickr',
84 + 'https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css',
85 + [],
86 + YATRA_VERSION
87 + );
88 + wp_enqueue_script(
89 + 'yatra-flatpickr',
90 + 'https://cdn.jsdelivr.net/npm/flatpickr',
91 + [],
92 + YATRA_VERSION,
93 + true
94 + );
95 + $searchJsDeps[] = 'yatra-flatpickr';
96 + }
97 +
61 98 $tripSearchJsPath = YATRA_PLUGIN_PATH . 'assets/js/trip-search-shortcode.js';
62 99 $tripSearchJsVer = is_readable($tripSearchJsPath)
63 100 ? (string) filemtime($tripSearchJsPath)
64 101 : YATRA_VERSION;
@@ -64,9 +101,9 @@
64 101 : YATRA_VERSION;
65 102 wp_enqueue_script(
66 103 'yatra-trip-search-shortcode',
67 104 YATRA_PLUGIN_URL . 'assets/js/trip-search-shortcode.js',
68 - ['jquery'],
105 + $searchJsDeps,
69 106 $tripSearchJsVer,
70 107 true
71 108 );
72 109
@@ -110,7 +147,47 @@
110 147 'activities' => $activities,
111 148 'listing_url' => $listing_url,
112 149 'duration_bounds' => $tripRepository->getDurationDaysBounds(),
113 150 'budget_presets' => $tripListingService->getSearchBudgetPresets(),
151 + 'field_visibility' => $this->resolveFieldVisibility($atts),
114 152 ]);
153 + }
154 +
155 + /**
156 + * Resolve which search fields are visible for THIS shortcode instance.
157 + *
158 + * Each field follows the rule: an explicit shortcode attribute wins; when the
159 + * attribute is omitted (empty), inherit the global Settings → Search & Listing
160 + * toggle. This keeps a bare [yatra_search] identical to before while allowing
161 + * per-placement overrides like [yatra_search budget="no"].
162 + *
163 + * @param array<string,mixed> $atts Resolved shortcode attributes.
164 + * @return array<string,bool> Keyed by field: keyword/destination/activities/duration/budget.
165 + */
166 + private function resolveFieldVisibility(array $atts): array
167 + {
168 + $resolve = static function ($attr_value, string $setting_key): bool {
169 + $value = strtolower(trim((string) $attr_value));
170 + if ($value === '') {
171 + // No override → inherit the global toggle (defaults to true).
172 + return \Yatra\Services\SettingsService::isEnabled($setting_key);
173 + }
174 + if (\in_array($value, ['1', 'yes', 'true', 'on', 'show'], true)) {
175 + return true;
176 + }
177 + if (\in_array($value, ['0', 'no', 'false', 'off', 'hide'], true)) {
178 + return false;
179 + }
180 + // Unrecognised value → fall back to the global toggle, never guess.
181 + return \Yatra\Services\SettingsService::isEnabled($setting_key);
182 + };
183 +
184 + return [
185 + 'keyword' => $resolve($atts['keyword'] ?? '', 'search_show_keyword'),
186 + 'destination' => $resolve($atts['destination'] ?? '', 'search_show_destination'),
187 + 'activities' => $resolve($atts['activities'] ?? '', 'search_show_activities'),
188 + 'duration' => $resolve($atts['duration'] ?? '', 'search_show_duration'),
189 + 'budget' => $resolve($atts['budget'] ?? '', 'search_show_budget'),
190 + 'date' => $resolve($atts['date'] ?? '', 'search_show_date'),
191 + ];
115 192 }
116 193 }