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