Ejemplo n.º 1
0
 /**
  * template_redirect()
  *
  * @return void
  **/
 function template_redirect()
 {
     $home_path = parse_url(get_option('home'));
     $home_path = isset($home_path['path']) ? rtrim($home_path['path'], '/') : '';
     if (in_array($_SERVER['REQUEST_URI'], array($home_path . '/sitemap.xml', $home_path . '/sitemap.xml.gz')) && strpos($_SERVER['HTTP_HOST'], '/') === false) {
         $dir = WP_CONTENT_DIR . '/sitemaps';
         if (defined('SUBDOMAIN_INSTALL') && SUBDOMAIN_INSTALL) {
             $dir .= '/' . $_SERVER['HTTP_HOST'];
         }
         $dir .= $home_path;
         if (!xml_sitemaps::clean($dir)) {
             return;
         }
         $sitemap = $dir . '/' . basename($_SERVER['REQUEST_URI']);
         if (xml_sitemaps_debug || !file_exists($sitemap)) {
             if (!xml_sitemaps::generate()) {
                 return;
             }
         }
         # Reset WP
         $levels = ob_get_level();
         for ($i = 0; $i < $levels; $i++) {
             ob_end_clean();
         }
         status_header(200);
         if (strpos($sitemap, '.gz') !== false) {
             header('Content-Type: application/x-gzip');
         } else {
             header('Content-Type:text/xml; charset=utf-8');
         }
         readfile($sitemap);
         die;
     }
 }