pointer to that file, for injecting * into an SEO plugin's sitemap index (Yoast, Rank Math). * * Pure string output — no I/O, no platform coupling. Every node is escaped. */ class SitemapRenderer { /** * A document. * * @param array $entries */ public function urlset(array $entries): string { $xml = '' . "\n"; $xml .= '' . "\n"; foreach ($entries as $entry) { $loc = (string) ($entry['loc'] ?? ''); if ($loc === '') { continue; } $xml .= "\t\n"; $xml .= "\t\t" . esc_url($loc) . "\n"; $lastmod = (string) ($entry['lastmod'] ?? ''); if ($lastmod !== '') { $xml .= "\t\t" . esc_html($lastmod) . "\n"; } $xml .= "\t\n"; } $xml .= '' . "\n"; return $xml; } /** * One or more inner nodes — for injecting into another plugin's * sitemap index (Yoast, Rank Math) without our document wrapper. * * @param array $sitemaps */ public function indexEntries(array $sitemaps): string { $xml = ''; foreach ($sitemaps as $sitemap) { $loc = (string) ($sitemap['loc'] ?? ''); if ($loc === '') { continue; } $xml .= "\t\n"; $xml .= "\t\t" . esc_url($loc) . "\n"; $lastmod = (string) ($sitemap['lastmod'] ?? ''); if ($lastmod !== '') { $xml .= "\t\t" . esc_html($lastmod) . "\n"; } $xml .= "\t\n"; } return $xml; } }