| @@ -19,18 +19,13 @@ | ||
| 19 | 19 | * Load trips via AJAX for pagination |
| 20 | 20 | */ |
| 21 | 21 | public function loadTrips(): void |
| 22 | 22 | { |
| 23 | - // Debug: Log AJAX request | |
| 24 | - if (defined('WP_DEBUG') && WP_DEBUG) { | |
| 25 | - error_log('Yatra AJAX - Request received: ' . print_r($_POST, true)); | |
| 26 | - } | |
| 23 | + | |
| 27 | 24 | |
| 28 | 25 | // Verify nonce |
| 29 | 26 | if (!wp_verify_nonce($_POST['nonce'] ?? '', 'yatra_trip_shortcode_nonce')) { |
| 30 | - if (defined('WP_DEBUG') && WP_DEBUG) { | |
| 31 | - error_log('Yatra AJAX - Security check failed'); | |
| 32 | - } | |
| 27 | + | |
| 33 | 28 | wp_die(esc_html__('Security check failed', 'yatra'), '', ['response' => 403]); |
| 34 | 29 | } |
| 35 | 30 | |
| 36 | 31 | // Parse shortcode attributes |
| @@ -39,13 +34,10 @@ | ||
| 39 | 34 | |
| 40 | 35 | // Add page to attributes for AJAX pagination |
| 41 | 36 | $atts['current_page'] = $page; |
| 42 | 37 | |
| 43 | - // Debug: Log the page being set | |
| 44 | - if (defined('WP_DEBUG') && WP_DEBUG) { | |
| 45 | - error_log('Yatra Trip AJAX - Setting current_page in atts to: ' . $page); | |
| 46 | - } | |
| 47 | 38 | |
| 39 | + | |
| 48 | 40 | try { |
| 49 | 41 | $tripShortcode = new \Yatra\Shortcodes\TripShortcode(); |
| 50 | 42 | $trips_data = $tripShortcode->getTrips($atts); |
| 51 | 43 | |
| @@ -68,23 +60,10 @@ | ||
| 68 | 60 | $total_found = $trips_data['total_found'] ?? 0; |
| 69 | 61 | $columns = (int) $atts['columns']; |
| 70 | 62 | $column_class = 'yatra-tour-grid-' . min(max($columns, 1), 6); |
| 71 | 63 | |
| 72 | - // Debug: Log AJAX data with comprehensive pagination info | |
| 73 | - if (defined('WP_DEBUG') && WP_DEBUG) { | |
| 74 | - error_log('=== YATRA TRIP AJAX DEBUG ==='); | |
| 75 | - error_log('Yatra AJAX - Requested page: ' . $page); | |
| 76 | - error_log('Yatra AJAX - Trips count: ' . count($trips_data['trips'] ?? [])); | |
| 77 | - error_log('Yatra AJAX - Total found: ' . $total_found); | |
| 78 | - error_log('Yatra AJAX - Max pages: ' . $max_pages); | |
| 79 | - error_log('Yatra AJAX - Current page: ' . $current_page); | |
| 80 | - error_log('Yatra AJAX - Attributes received: ' . print_r($atts, true)); | |
| 81 | - error_log('Yatra AJAX - Is last page: ' . ($current_page === $max_pages ? 'YES' : 'NO')); | |
| 82 | - error_log('Yatra AJAX - Current page type: ' . gettype($current_page)); | |
| 83 | - error_log('Yatra AJAX - Max pages type: ' . gettype($max_pages)); | |
| 84 | - error_log('=== END TRIP AJAX DEBUG ==='); | |
| 85 | - } | |
| 86 | 64 | |
| 65 | + | |
| 87 | 66 | // Load the template content with variables in scope |
| 88 | 67 | ob_start(); |
| 89 | 68 | // Extract variables to make them available in template (matching other shortcode pattern) |
| 90 | 69 | $trips = [ |
| @@ -101,14 +80,9 @@ | ||
| 101 | 80 | |
| 102 | 81 | // Ensure atts includes the current_page for data-atts |
| 103 | 82 | $atts['current_page'] = $current_page; |
| 104 | 83 | |
| 105 | - // Debug: Log final atts being passed to template | |
| 106 | - if (defined('WP_DEBUG') && WP_DEBUG) { | |
| 107 | - error_log('Yatra Trip AJAX - Final atts for template: ' . print_r($atts, true)); | |
| 108 | - error_log('Yatra Trip AJAX - current_page in atts: ' . ($atts['current_page'] ?? 'NOT SET')); | |
| 109 | - } | |
| 110 | - | |
| 84 | + | |
| 111 | 85 | include YATRA_PLUGIN_PATH . 'templates/shortcodes/trip.php'; |
| 112 | 86 | $html = ob_get_clean(); |
| 113 | 87 | |
| 114 | 88 | wp_send_json_success([ |
| @@ -118,14 +92,9 @@ | ||
| 118 | 92 | 'total_found' => $trips_data['total_found'] ?? 0 |
| 119 | 93 | ]); |
| 120 | 94 | |
| 121 | 95 | } catch (\Exception $e) { |
| 122 | - // Log error for debugging | |
| 123 | - if (defined('WP_DEBUG') && WP_DEBUG) { | |
| 124 | - error_log('Yatra TripShortcode AJAX Error: ' . $e->getMessage()); | |
| 125 | - error_log('Yatra TripShortcode AJAX Trace: ' . $e->getTraceAsString()); | |
| 126 | - } | |
| 127 | - | |
| 96 | + | |
| 128 | 97 | wp_send_json_error([ |
| 129 | 98 | 'message' => (defined('WP_DEBUG') && WP_DEBUG) |
| 130 | 99 | ? 'Error loading trips: ' . $e->getMessage() |
| 131 | 100 | : __('Unable to load trips. Please try again.', 'yatra'), |