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 / Ajax / DestinationShortcodeAjax.php

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

95 lines 3.7 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 handlers for Destination Shortcode
9 */
10 class DestinationShortcodeAjax
11 {
12 public function __construct()
13 {
14 add_action('wp_ajax_yatra_destination_shortcode_load', [$this, 'loadDestinations']);
15 add_action('wp_ajax_nopriv_yatra_destination_shortcode_load', [$this, 'loadDestinations']);
16 }
17
18 /**
19 * Load destinations via AJAX for pagination
20 */
21 public function loadDestinations(): void
22 {
23
24 // Verify nonce
25 if (!wp_verify_nonce($_POST['nonce'] ?? '', 'yatra_destination_shortcode_nonce')) {
26 if (defined('WP_DEBUG') && WP_DEBUG) {
27 error_log('Yatra Destination AJAX - Security check failed');
28 }
29 wp_die(esc_html__('Security check failed', 'yatra'), '', ['response' => 403]);
30 }
31
32 // Parse shortcode attributes
33 $atts = $_POST['atts'] ?? [];
34 $page = (int) ($_POST['page'] ?? 1);
35
36 // Add page to attributes for AJAX pagination
37 $atts['current_page'] = $page;
38
39 try {
40 $destinationShortcode = new \Yatra\Shortcodes\DestinationShortcode();
41 $destinations_data = $destinationShortcode->getDestinations($atts);
42
43 // Prepare data for template - extract variables for template scope
44 $destinations = [
45 'destinations' => $destinations_data['destinations'] ?? [],
46 'max_pages' => $destinations_data['max_pages'] ?? 1,
47 'current_page' => $destinations_data['current_page'] ?? 1,
48 'total_found' => $destinations_data['total_found'] ?? 0
49 ];
50
51 // Extract variables to make them available in template
52 $atts = $atts;
53 $max_pages = $destinations_data['max_pages'] ?? 1;
54 $current_page = $destinations_data['current_page'] ?? 1;
55 $total_found = $destinations_data['total_found'] ?? 0;
56 $columns = (int) $atts['columns'];
57 $column_class = 'yatra-destination-grid-' . min(max($columns, 1), 4);
58
59
60 // Load the template content with variables in scope
61 ob_start();
62 // Extract variables to make them available in template (matching trip shortcode pattern)
63 $destinations = $destinations_data['destinations'] ?? [];
64 $max_pages = $destinations_data['max_pages'] ?? 1;
65 $current_page = $destinations_data['current_page'] ?? 1;
66 $total_found = $destinations_data['total_found'] ?? 0;
67 $columns = (int) $atts['columns'];
68 $column_class = 'yatra-destination-grid-' . min(max($columns, 1), 4);
69
70 include YATRA_PLUGIN_PATH . 'templates/shortcodes/destination.php';
71 $html = ob_get_clean();
72
73 wp_send_json_success([
74 'html' => $html,
75 'current_page' => $destinations_data['current_page'] ?? 1,
76 'max_pages' => $destinations_data['max_pages'] ?? 1,
77 'total_found' => $destinations_data['total_found'] ?? 0
78 ]);
79
80 } catch (\Exception $e) {
81 // Log error for debugging
82 if (defined('WP_DEBUG') && WP_DEBUG) {
83 error_log('Yatra DestinationShortcode AJAX Error: ' . $e->getMessage());
84 error_log('Yatra DestinationShortcode AJAX Trace: ' . $e->getTraceAsString());
85 }
86
87 wp_send_json_error([
88 'message' => (defined('WP_DEBUG') && WP_DEBUG)
89 ? 'Error loading destinations: ' . $e->getMessage()
90 : __('Unable to load destinations. Please try again.', 'yatra'),
91 ]);
92 }
93 }
94 }
95