function steam_video_shortcode($atts) { $atts = shortcode_atts(array( 'url' => '' ), $atts); if (empty($atts['url'])) return "Thiếu link Steam"; preg_match('/app\/(\d+)/', $atts['url'], $matches); if (!isset($matches[1])) return "Link không hợp lệ"; $appid = $matches[1]; $api = "https://store.steampowered.com/api/appdetails?appids=$appid&l=english"; $response = wp_remote_get($api, array( 'timeout' => 15, 'headers' => array( 'User-Agent' => 'Mozilla/5.0' ) )); if (is_wp_error($response)) { return "Lỗi kết nối Steam"; } $body = json_decode(wp_remote_retrieve_body($response), true); if (!isset($body[$appid]['success']) || !$body[$appid]['success']) { return "Không có dữ liệu game"; } $data = $body[$appid]['data']; $video = ''; if (!empty($data['movies'])) { foreach ($data['movies'] as $movie) { if (!empty($movie['mp4']['max'])) { $video = esc_url($movie['mp4']['max']); break; } if (!empty($movie['mp4']['480'])) { $video = esc_url($movie['mp4']['480']); break; } if (!empty($movie['webm']['max'])) { $video = esc_url($movie['webm']['max']); break; } } } // ✅ Có video if (!empty($video)) { return ''; } // ✅ Fallback iframe (QUAN TRỌNG) return ''; } add_shortcode('steam_video', 'steam_video_shortcode');