'; } if (!$yatra_ai_module_on || !$yatra_ai_chat_flag) { return; } if (!isset($trip)) { if (defined('WP_DEBUG') && WP_DEBUG) { echo ''; } return; } // Accept either the Trip object (with getId/getName) or a raw post-id // integer or stdClass with ID field — the widget is rendered from // multiple branches in content-sidebar and the calling shape isn't // perfectly uniform. $yatra_chat_trip_id = 0; $yatra_chat_trip_name = ''; if (\is_object($trip)) { if (\method_exists($trip, 'getId')) { $yatra_chat_trip_id = (int) $trip->getId(); } elseif (isset($trip->id)) { $yatra_chat_trip_id = (int) $trip->id; } elseif (isset($trip->ID)) { $yatra_chat_trip_id = (int) $trip->ID; } // The Yatra Trip class exposes the display title via getTitle(); // older snippets used getName(). Try both, then fall through to // raw stdClass / WP_Post property names. if (\method_exists($trip, 'getTitle')) { $yatra_chat_trip_name = (string) $trip->getTitle(); } elseif (\method_exists($trip, 'getName')) { $yatra_chat_trip_name = (string) $trip->getName(); } elseif (isset($trip->title)) { $yatra_chat_trip_name = (string) $trip->title; } elseif (isset($trip->name)) { $yatra_chat_trip_name = (string) $trip->name; } elseif (isset($trip->post_title)) { $yatra_chat_trip_name = (string) $trip->post_title; } } elseif (\is_numeric($trip)) { $yatra_chat_trip_id = (int) $trip; } if ($yatra_chat_trip_id <= 0) { if (defined('WP_DEBUG') && WP_DEBUG) { echo ''; } return; } if ($yatra_chat_trip_name === '') { $yatra_chat_trip_name = sprintf( /* translators: %d: trip post ID. */ __('Trip #%d', 'yatra'), $yatra_chat_trip_id ); } $yatra_chat_rest = esc_url_raw(rest_url('yatra/v1/ai/trip-chat/' . $yatra_chat_trip_id)); $yatra_chat_widget_id = 'yatra-ai-chat-' . $yatra_chat_trip_id; ?>