function gglstmp_sitemapcreate()
 {
     global $wpdb, $gglstmp_settings;
     $str_post_type = "";
     foreach ($gglstmp_settings['post_type'] as $val) {
         if ($str_post_type != "") {
             $str_post_type .= ", ";
         }
         $str_post_type .= "'" . $val . "'";
     }
     $taxonomies = array();
     foreach ($gglstmp_settings['taxonomy'] as $val) {
         $taxonomies[] = $val;
     }
     $xml = new DomDocument('1.0', 'utf-8');
     $xml_stylesheet_path = defined('WP_CONTENT_DIR') ? home_url('/') . basename(WP_CONTENT_DIR) : home_url('/') . 'wp-content';
     $xml_stylesheet_path .= defined('WP_PLUGIN_DIR') ? '/' . basename(WP_PLUGIN_DIR) . '/google-sitemap-plugin/sitemap.xsl' : '/plugins/google-sitemap-plugin/sitemap.xsl';
     $xslt = $xml->createProcessingInstruction('xml-stylesheet', "type=\"text/xsl\" href=\"{$xml_stylesheet_path}\"");
     $xml->appendChild($xslt);
     $gglstmppr_urlset = $xml->appendChild($xml->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset'));
     if (!empty($str_post_type)) {
         $loc = $wpdb->get_results("SELECT `ID`, `post_modified` FROM {$wpdb->posts} WHERE `post_status` = 'publish' AND `post_type` IN (" . $str_post_type . ")");
         if (!empty($loc)) {
             foreach ($loc as $val) {
                 $gglstmppr_url = $gglstmppr_urlset->appendChild($xml->createElement('url'));
                 $loc = $gglstmppr_url->appendChild($xml->createElement('loc'));
                 $permalink = get_permalink($val->ID);
                 $loc->appendChild($xml->createTextNode($permalink));
                 $lastmod = $gglstmppr_url->appendChild($xml->createElement('lastmod'));
                 $now = $val->post_modified;
                 $date = date('Y-m-d\\TH:i:sP', strtotime($now));
                 $lastmod->appendChild($xml->createTextNode($date));
                 $changefreq = $gglstmppr_url->appendChild($xml->createElement('changefreq'));
                 $changefreq->appendChild($xml->createTextNode('monthly'));
                 $priority = $gglstmppr_url->appendChild($xml->createElement('priority'));
                 $priority->appendChild($xml->createTextNode(1.0));
             }
         }
     }
     if (!empty($taxonomies)) {
         foreach ($taxonomies as $value) {
             $terms = get_terms($value, 'hide_empty=1');
             if (!empty($terms) && !is_wp_error($terms)) {
                 foreach ($terms as $term_value) {
                     $gglstmppr_url = $gglstmppr_urlset->appendChild($xml->createElement('url'));
                     $loc = $gglstmppr_url->appendChild($xml->createElement('loc'));
                     $permalink = get_term_link((int) $term_value->term_id, $value);
                     $loc->appendChild($xml->createTextNode($permalink));
                     $lastmod = $gglstmppr_url->appendChild($xml->createElement('lastmod'));
                     $now = $wpdb->get_var("SELECT `post_modified` FROM {$wpdb->posts}, {$wpdb->term_relationships} WHERE `post_status` = 'publish' AND `term_taxonomy_id` = " . $term_value->term_taxonomy_id . " AND {$wpdb->posts}.ID= {$wpdb->term_relationships}.object_id ORDER BY `post_modified` DESC");
                     $date = date('Y-m-d\\TH:i:sP', strtotime($now));
                     $lastmod->appendChild($xml->createTextNode($date));
                     $changefreq = $gglstmppr_url->appendChild($xml->createElement('changefreq'));
                     $changefreq->appendChild($xml->createTextNode('monthly'));
                     $priority = $gglstmppr_url->appendChild($xml->createElement('priority'));
                     $priority->appendChild($xml->createTextNode(1.0));
                 }
             }
         }
     }
     $xml->formatOutput = true;
     if (is_multisite()) {
         $home_url = preg_replace("/[^a-zA-ZА-Яа-я0-9\\s]/", "_", str_replace('http://', '', str_replace('https://', '', home_url())));
         $xml->save(ABSPATH . 'sitemap_' . $home_url . '.xml');
     } else {
         $xml->save(ABSPATH . 'sitemap.xml');
     }
     gglstmp_sitemap_info();
 }
 function gglstmp_sitemapcreate()
 {
     global $wpdb;
     if (isset($_POST['gglstmp_settings'])) {
         $gglstmp_settings['post_type'] = $_POST['gglstmp_settings'];
     } else {
         global $gglstmp_settings;
     }
     $str = "";
     foreach ($gglstmp_settings['post_type'] as $val) {
         if ($str != "") {
             $str .= ", ";
         }
         $str .= "'" . $val . "'";
     }
     $xml = new DomDocument('1.0', 'utf-8');
     if (defined('WP_CONTENT_DIR')) {
         $xml_stylesheet_path = home_url('/') . basename(WP_CONTENT_DIR);
     } else {
         $xml_stylesheet_path = home_url('/') . "wp-content";
     }
     if (defined('WP_PLUGIN_DIR')) {
         $xml_stylesheet_path .= '/' . basename(WP_PLUGIN_DIR) . "/google-sitemap-plugin/sitemap.xsl";
     } else {
         $xml_stylesheet_path .= "/plugins/google-sitemap-plugin/sitemap.xsl";
     }
     $xslt = $xml->createProcessingInstruction('xml-stylesheet', "type=\"text/xsl\" href=\"{$xml_stylesheet_path}\"");
     $xml->appendChild($xslt);
     $urlset = $xml->appendChild($xml->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset'));
     if (!empty($str)) {
         $loc = $wpdb->get_results("SELECT ID, post_modified, post_status, post_type, ping_status FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_type IN (" . $str . ")");
         foreach ($loc as $val) {
             $url = $urlset->appendChild($xml->createElement('url'));
             $loc = $url->appendChild($xml->createElement('loc'));
             $permalink = get_permalink($val->ID);
             $loc->appendChild($xml->createTextNode($permalink));
             $lastmod = $url->appendChild($xml->createElement('lastmod'));
             $now = $val->post_modified;
             $date = date('Y-m-d\\TH:i:sP', strtotime($now));
             $lastmod->appendChild($xml->createTextNode($date));
             $changefreq = $url->appendChild($xml->createElement('changefreq'));
             $changefreq->appendChild($xml->createTextNode('monthly'));
             $priority = $url->appendChild($xml->createElement('priority'));
             $priority->appendChild($xml->createTextNode(1.0));
         }
         $xml->formatOutput = true;
     }
     if (is_multisite()) {
         $home_url = preg_replace("/[^a-zA-ZА-Яа-я0-9\\s]/", "_", str_replace('http://', '', str_replace('https://', '', home_url())));
         $xml->save(ABSPATH . 'sitemap_' . $home_url . '.xml');
     } else {
         $xml->save(ABSPATH . 'sitemap.xml');
     }
     gglstmp_sitemap_info();
 }