PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
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
← All changes | app/Shortcodes/ActivityShortcode.php +36 -13 3.0.2.9trunk View file →
@@ -3,8 +3,9 @@
3 3 declare(strict_types=1);
4 4
5 5 namespace Yatra\Shortcodes;
6 6
7 +use Yatra\Helpers\TripListingFilterBuilder;
7 8 use Yatra\Services\SettingsService;
8 9
9 10 /**
10 11 * Activity Shortcode
@@ -22,10 +23,14 @@
22 23 'show_trip_count' => 'yes',
23 24 'show_description' => 'yes',
24 25 'show_image' => 'yes',
25 26 'show_pagination' => 'yes', // Default to show pagination like trip shortcode
26 - 'activity' => '', // Specific activity slug(s), comma separated
27 - 'hide_empty' => 'yes',
27 + 'activity' => '', // Classification IDs, comma-separated
28 + // hide_empty defaults to 'no' to preserve the historical
29 + // behavior (show every activity, even ones with zero
30 + // trips). Operators that prefer the empty-archive defense
31 + // opt in with hide_empty="yes".
32 + 'hide_empty' => 'no',
28 33 'title' => 'Activity Listings'
29 34 ]);
30 35 }
31 36
@@ -55,14 +60,15 @@
55 60 'total_found' => $activities_data['total_found'] ?? 0,
56 61 'per_page' => $per_page
57 62 ];
58 63
59 - // Enqueue shortcode-specific CSS
64 + $activityCssPath = YATRA_PLUGIN_PATH . 'assets/css/shortcodes/activity-shortcode.css';
65 + $activityCssVer = is_readable($activityCssPath) ? YATRA_VERSION . '.' . filemtime($activityCssPath) : YATRA_VERSION;
60 66 wp_enqueue_style(
61 67 'yatra-activity-shortcode',
62 68 YATRA_PLUGIN_URL . 'assets/css/shortcodes/activity-shortcode.css',
63 - [],
64 - YATRA_VERSION
69 + \Yatra\Providers\FrontendAssetsProvider::shortcodeStyleDependencies(),
70 + $activityCssVer
65 71 );
66 72
67 73 // Enqueue shortcode-specific JavaScript
68 74 wp_enqueue_script(
@@ -108,12 +114,16 @@
108 114 'order_by' => 'name',
109 115 'order' => $atts['order'] === 'asc' ? 'ASC' : 'DESC'
110 116 ];
111 117
112 - // Filter by specific activities if provided
113 - if (!empty($atts['activity'])) {
114 - $args['where']['slug'] = explode(',', $atts['activity']);
115 - }
118 + $args['where'] = $args['where'] ?? [];
119 + TripListingFilterBuilder::applyTaxonomyWhere(
120 + $args['where'],
121 + $atts,
122 + 'activityIds',
123 + 'activity_ids',
124 + 'activity'
125 + );
116 126
117 127 // Get total count for pagination
118 128 $count_args = $args;
119 129 unset($count_args['limit']);
@@ -252,12 +262,25 @@
252 262 'difficulty' => !empty($difficulties) ? $this->getMostCommonDifficulty($difficulties) : null
253 263 ];
254 264 }
255 265
256 - // Filter out empty activities if requested
266 + // Filter out activities that have no published trips.
267 + //
268 + // Previously this only checked term name/slug presence —
269 + // which never actually fires because all valid terms have
270 + // both. As a result the shortcode would render activity
271 + // cards with "0 trips" badges, leading users to click
272 + // into empty archive pages. With hide_empty=yes we now
273 + // drop any activity whose trip_count (computed above
274 + // from TripClassificationsTable JOIN TripsTable WHERE
275 + // status=publish) is zero. Term-metadata sanity is also
276 + // preserved as a secondary safety check so we don't
277 + // render orphan terms.
257 278 if ($atts['hide_empty'] === 'yes') {
258 - $activities = array_filter($activities, function($activity) {
259 - return !empty($activity['term']->name) && !empty($activity['term']->slug);
279 + $activities = array_filter($activities, static function ($activity) {
280 + return (int) ($activity['trip_count'] ?? 0) > 0
281 + && !empty($activity['term']->name)
282 + && !empty($activity['term']->slug);
260 283 });
261 284 }
262 285
263 286 // Calculate pagination data
@@ -354,9 +377,9 @@
354 377 if (function_exists('yatra_get_activity_permalink')) {
355 378 return yatra_get_activity_permalink($activity);
356 379 }
357 380
358 - $base = SettingsService::getString('activity_base', 'activity');
381 + $base = SettingsService::getActivityBase();
359 382 return home_url('/' . $base . '/' . $activity->slug . '/');
360 383 }
361 384
362 385 return '#'; // Fallback