PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.15
Yatra – Travel Booking & Tour Operator Software v3.0.15
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 / Ajax / TripCategoryShortcodeAjax.php

TripCategoryShortcodeAjax.php in Yatra – Travel Booking & Tour Operator Software 3.0.15, at app/Ajax/TripCategoryShortcodeAjax.php

62 lines 2.0 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\Ajax;
6
7 /**
8 * AJAX for {@see \Yatra\Shortcodes\TripCategoryShortcode} pagination.
9 */
10 class TripCategoryShortcodeAjax
11 {
12 public function __construct()
13 {
14 add_action('wp_ajax_yatra_trip_category_shortcode_load', [$this, 'loadCategories']);
15 add_action('wp_ajax_nopriv_yatra_trip_category_shortcode_load', [$this, 'loadCategories']);
16 }
17
18 public function loadCategories(): void
19 {
20 if (!wp_verify_nonce($_POST['nonce'] ?? '', 'yatra_trip_category_shortcode_nonce')) {
21 wp_die(esc_html__('Security check failed', 'yatra'), '', ['response' => 403]);
22 }
23
24 $atts = $_POST['atts'] ?? [];
25 if (!is_array($atts)) {
26 $atts = [];
27 }
28
29 $page = (int) ($_POST['page'] ?? 1);
30 $atts['current_page'] = $page;
31
32 try {
33 $shortcode = new \Yatra\Shortcodes\TripCategoryShortcode();
34 $data = $shortcode->getCategories($atts);
35
36 $categories = $data['categories'] ?? [];
37 $max_pages = $data['max_pages'] ?? 1;
38 $current_page = $data['current_page'] ?? 1;
39 $total_found = $data['total_found'] ?? 0;
40 $columns = (int) ($atts['columns'] ?? 3);
41 $column_class = 'yatra-destination-grid-' . min(max($columns, 1), 6);
42
43 ob_start();
44 include YATRA_PLUGIN_PATH . 'templates/shortcodes/trip-category.php';
45 $html = ob_get_clean();
46
47 wp_send_json_success([
48 'html' => $html,
49 'current_page' => $current_page,
50 'max_pages' => $max_pages,
51 'total_found' => $total_found,
52 ]);
53 } catch (\Exception $e) {
54 wp_send_json_error([
55 'message' => (defined('WP_DEBUG') && WP_DEBUG)
56 ? 'Error loading categories: ' . $e->getMessage()
57 : __('Unable to load categories. Please try again.', 'yatra'),
58 ]);
59 }
60 }
61 }
62