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; 
  3.  
  4. $gglstmp_options = get_option( 'gglstmp_options' ); 
  5.  
  6. $taxonomies = array(); 
  7. foreach ( $gglstmp_options['taxonomy'] as $val ) { 
  8. $taxonomies[] = $val; 
  9.  
  10. $xml = new DomDocument( '1.0', 'utf-8' ); 
  11. $home_url = site_url( '/' ); 
  12. $xml_stylesheet_path = ( defined( 'WP_CONTENT_DIR' ) )? $home_url . basename( WP_CONTENT_DIR ) : $home_url . 'wp-content'; 
  13. $xml_stylesheet_path .= ( defined( 'WP_PLUGIN_DIR' ) ) ? '/' . basename( WP_PLUGIN_DIR ) . '/google-sitemap-plugin/sitemap.xsl' : '/plugins/google-sitemap-plugin/sitemap.xsl'; 
  14.  
  15. $xslt = $xml->createProcessingInstruction( 'xml-stylesheet', "type=\"text/xsl\" href=\"$xml_stylesheet_path\"" ); 
  16. $xml->appendChild( $xslt ); 
  17. $gglstmp_urlset = $xml->appendChild( $xml->createElementNS( 'http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset' ) ); 
  18.  
  19. /** add home page */ 
  20. $url = $gglstmp_urlset->appendChild( $xml->createElement( 'url' ) ); 
  21. $loc = $url->appendChild( $xml->createElement( 'loc' ) ); 
  22. $loc->appendChild( $xml->createTextNode( home_url( '/' ) ) ); 
  23. $lastmod = $url->appendChild( $xml->createElement( 'lastmod' ) ); 
  24. $lastmod->appendChild( $xml->createTextNode( date( 'Y-m-d\TH:i:sP', time() ) ) ); 
  25. $changefreq = $url->appendChild( $xml->createElement( 'changefreq' ) ); 
  26. $changefreq->appendChild( $xml->createTextNode( 'monthly' ) ); 
  27. $priority = $url->appendChild( $xml->createElement( 'priority' ) ); 
  28. $priority->appendChild( $xml->createTextNode( 1.0 ) ); 
  29. /** getting an array of the excluded post ids of 'forum', 'topic' and 'reply' post types (hidden and private bbPress forum posts) */ 
  30. $excluded_posts_array = $wpdb->get_col( "SELECT `ID` FROM $wpdb->posts WHERE `post_status` IN ('hidden', 'private') AND `post_type` IN ('forum', 'topic', 'reply')" ); 
  31. if ( ! empty( $excluded_posts_array ) ) { 
  32. $excluded_posts_string = implode( ', ', $excluded_posts_array ); 
  33. while ( true ) { 
  34. $hidden_child_array = $wpdb->get_col( "SELECT `ID` FROM $wpdb->posts WHERE `post_status` NOT IN ('hidden', 'private') AND `post_type` IN ('forum', 'topic', 'reply') AND `post_parent` IN ($excluded_posts_string)" ); 
  35. if ( ! empty( $hidden_child_array ) ) { 
  36. $excluded_posts_array = array_merge( $excluded_posts_array, $hidden_child_array ); 
  37. $excluded_posts_string = implode( ', ', $hidden_child_array ); 
  38. } else { 
  39. break 1; 
  40.  
  41. if ( ! empty( $gglstmp_options['post_type'] ) ) { 
  42. $args = array( 
  43. 'posts_per_page' => -1,  
  44. 'exclude' => $excluded_posts_array,  
  45. 'post_type' => $gglstmp_options['post_type'],  
  46. 'post_status' => 'publish' 
  47. );  
  48. $loc = get_posts( $args ); 
  49. if ( ! empty( $loc ) ) { 
  50. foreach ( $loc as $val ) { 
  51. $gglstmp_url = $gglstmp_urlset->appendChild( $xml->createElement( 'url' ) ); 
  52. $loc = $gglstmp_url->appendChild( $xml->createElement( 'loc' ) ); 
  53. $permalink = get_permalink( $val->ID ); 
  54. $loc->appendChild( $xml->createTextNode( $permalink ) ); 
  55. $lastmod = $gglstmp_url->appendChild( $xml->createElement( 'lastmod' ) ); 
  56. $now = $val->post_modified; 
  57. $date = date( 'Y-m-d\TH:i:sP', strtotime( $now ) ); 
  58. $lastmod->appendChild( $xml->createTextNode( $date ) ); 
  59. $changefreq = $gglstmp_url->appendChild( $xml->createElement( 'changefreq' ) ); 
  60. $changefreq->appendChild( $xml->createTextNode( 'monthly' ) ); 
  61. $priority = $gglstmp_url->appendChild( $xml->createElement( 'priority' ) ); 
  62. $priority->appendChild( $xml->createTextNode( 1.0 ) ); 
  63. if ( ! empty( $taxonomies ) ) { 
  64. foreach ( $taxonomies as $value ) { 
  65.  
  66. $terms = get_terms( $value, 'hide_empty=1' ); 
  67.  
  68. if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { 
  69. foreach ( $terms as $term_value ) { 
  70. $gglstmp_url = $gglstmp_urlset->appendChild( $xml->createElement( 'url' ) ); 
  71. $loc = $gglstmp_url->appendChild( $xml->createElement( 'loc' ) ); 
  72. $permalink = get_term_link( (int)$term_value->term_id, $value ); 
  73. $loc->appendChild( $xml->createTextNode( $permalink ) ); 
  74. $lastmod = $gglstmp_url->appendChild( $xml->createElement( 'lastmod' ) ); 
  75.  
  76. $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" ); 
  77. $date = date( 'Y-m-d\TH:i:sP', strtotime( $now ) ); 
  78. $lastmod->appendChild( $xml->createTextNode( $date ) ); 
  79. $changefreq = $gglstmp_url -> appendChild( $xml->createElement( 'changefreq' ) ); 
  80. $changefreq->appendChild( $xml->createTextNode( 'monthly' ) ); 
  81. $priority = $gglstmp_url->appendChild( $xml->createElement( 'priority' ) ); 
  82. $priority->appendChild( $xml->createTextNode( 1.0 ) ); 
  83.  
  84. $xml->formatOutput = true; 
  85.  
  86. if ( ! is_writable( ABSPATH ) ) 
  87. @chmod( ABSPATH, 0755 ); 
  88.  
  89. if ( is_multisite() ) { 
  90. $home_url = preg_replace( "/[^a-zA-Z*-**-*0-9\s]/", "_", str_replace( 'http://', '', str_replace( 'https://', '', site_url() ) ) ); 
  91. $xml->save( ABSPATH . 'sitemap_' . $home_url . '.xml' ); 
  92. } else { 
  93. $xml->save( ABSPATH . 'sitemap.xml' ); 
  94.  
  95. if ( is_multisite() ) { 
  96. $home_url = preg_replace( "/[^a-zA-Z*-**-*0-9\s]/", "_", str_replace( 'http://', '', str_replace( 'https://', '', site_url() ) ) ); 
  97. $xml_file = 'sitemap_' . $home_url . '.xml'; 
  98. } else { 
  99. $xml_file = 'sitemap.xml'; 
  100.  
  101. $xml_path = ABSPATH . $xml_file; 
  102. $xml_url = site_url( '/' ) . $xml_file; 
  103. if ( file_exists( $xml_path ) ) { 
  104. $gglstmp_options['sitemap'] = array( 
  105. 'file' => $xml_file,  
  106. 'path' => $xml_path,  
  107. 'loc' => $xml_url,  
  108. 'lastmod' => date( 'Y-m-d\TH:i:sP', filemtime( $xml_path ) ) 
  109. ); 
  110. update_option( 'gglstmp_options', $gglstmp_options );