gglstmp_sitemapcreate

The Google Sitemap by BestWebSoft gglstmp sitemapcreate function.

Description

gglstmp_sitemapcreate(); 

Usage

  1. if ( !function_exists( 'gglstmp_sitemapcreate' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-sitemap-by-bestwebsoft/google-sitemap-plugin.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = gglstmp_sitemapcreate(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/google-sitemap-plugin.php  
  1. function gglstmp_sitemapcreate() { 
  2. global $wpdb, $gglstmp_settings; 
  3.  
  4. $str_post_type = ""; 
  5. foreach ( $gglstmp_settings['post_type'] as $val ) { 
  6. if ( $str_post_type != "" ) 
  7. $str_post_type .= ", "; 
  8. $str_post_type .= "'" . $val . "'"; 
  9.  
  10. $taxonomies = array(); 
  11. foreach ( $gglstmp_settings['taxonomy'] as $val ) { 
  12. $taxonomies[] = $val; 
  13.  
  14. $xml = new DomDocument( '1.0', 'utf-8' ); 
  15. $home_url = site_url( '/' ); 
  16. $xml_stylesheet_path = ( defined( 'WP_CONTENT_DIR' ) )? $home_url . basename( WP_CONTENT_DIR ) : $home_url . 'wp-content'; 
  17. $xml_stylesheet_path .= ( defined( 'WP_PLUGIN_DIR' ) ) ? '/' . basename( WP_PLUGIN_DIR ) . '/google-sitemap-plugin/sitemap.xsl' : '/plugins/google-sitemap-plugin/sitemap.xsl'; 
  18.  
  19. $xslt = $xml->createProcessingInstruction( 'xml-stylesheet', "type=\"text/xsl\" href=\"$xml_stylesheet_path\"" ); 
  20. $xml->appendChild( $xslt ); 
  21. $gglstmp_urlset = $xml->appendChild( $xml->createElementNS( 'http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset' ) ); 
  22.  
  23. /** add home page */ 
  24. $url = $gglstmp_urlset->appendChild( $xml->createElement( 'url' ) ); 
  25. $loc = $url->appendChild( $xml->createElement( 'loc' ) ); 
  26. $loc->appendChild( $xml->createTextNode( home_url( '/' ) ) ); 
  27. $lastmod = $url->appendChild( $xml->createElement( 'lastmod' ) ); 
  28. $lastmod->appendChild( $xml->createTextNode( date( 'Y-m-d\TH:i:sP', time() ) ) ); 
  29. $changefreq = $url->appendChild( $xml->createElement( 'changefreq' ) ); 
  30. $changefreq->appendChild( $xml->createTextNode( 'monthly' ) ); 
  31. $priority = $url->appendChild( $xml->createElement( 'priority' ) ); 
  32. $priority->appendChild( $xml->createTextNode( 1.0 ) ); 
  33.  
  34. if ( ! empty( $str_post_type ) ) { 
  35. $loc = $wpdb->get_results( "SELECT `ID`, `post_modified` FROM $wpdb->posts WHERE `post_status` = 'publish' AND `post_type` IN (" . $str_post_type . ")" ); 
  36.  
  37. if ( ! empty( $loc ) ) { 
  38. foreach ( $loc as $val ) { 
  39. $gglstmp_url = $gglstmp_urlset->appendChild( $xml->createElement( 'url' ) ); 
  40. $loc = $gglstmp_url->appendChild( $xml->createElement( 'loc' ) ); 
  41. $permalink = get_permalink( $val->ID ); 
  42. $loc->appendChild( $xml->createTextNode( $permalink ) ); 
  43. $lastmod = $gglstmp_url->appendChild( $xml->createElement( 'lastmod' ) ); 
  44. $now = $val->post_modified; 
  45. $date = date( 'Y-m-d\TH:i:sP', strtotime( $now ) ); 
  46. $lastmod->appendChild( $xml->createTextNode( $date ) ); 
  47. $changefreq = $gglstmp_url->appendChild( $xml->createElement( 'changefreq' ) ); 
  48. $changefreq->appendChild( $xml->createTextNode( 'monthly' ) ); 
  49. $priority = $gglstmp_url->appendChild( $xml->createElement( 'priority' ) ); 
  50. $priority->appendChild( $xml->createTextNode( 1.0 ) ); 
  51. if ( ! empty( $taxonomies ) ) { 
  52. foreach ( $taxonomies as $value ) { 
  53.  
  54. $terms = get_terms( $value, 'hide_empty=1' ); 
  55.  
  56. if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { 
  57. foreach ( $terms as $term_value ) { 
  58. $gglstmp_url = $gglstmp_urlset->appendChild( $xml->createElement( 'url' ) ); 
  59. $loc = $gglstmp_url->appendChild( $xml->createElement( 'loc' ) ); 
  60. $permalink = get_term_link( (int)$term_value->term_id, $value ); 
  61. $loc->appendChild( $xml->createTextNode( $permalink ) ); 
  62. $lastmod = $gglstmp_url->appendChild( $xml->createElement( 'lastmod' ) ); 
  63.  
  64. $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" ); 
  65. $date = date( 'Y-m-d\TH:i:sP', strtotime( $now ) ); 
  66. $lastmod->appendChild( $xml->createTextNode( $date ) ); 
  67. $changefreq = $gglstmp_url -> appendChild( $xml->createElement( 'changefreq' ) ); 
  68. $changefreq->appendChild( $xml->createTextNode( 'monthly' ) ); 
  69. $priority = $gglstmp_url->appendChild( $xml->createElement( 'priority' ) ); 
  70. $priority->appendChild( $xml->createTextNode( 1.0 ) ); 
  71.  
  72. $xml->formatOutput = true; 
  73.  
  74. if ( ! is_writable( ABSPATH ) ) 
  75. @chmod( ABSPATH, 0755 ); 
  76.  
  77. if ( is_multisite() ) { 
  78. $home_url = preg_replace( "/[^a-zA-Z*-**-*0-9\s]/", "_", str_replace( 'http://', '', str_replace( 'https://', '', site_url() ) ) ); 
  79. $xml->save( ABSPATH . 'sitemap_' . $home_url . '.xml' ); 
  80. } else { 
  81. $xml->save( ABSPATH . 'sitemap.xml' );