XML Sitemap & Google News feeds - Version 4.7.5

Version Description

  • FIX: On cache_flush purge also the respective time_key cache entry, props @e2robert https://wordpress.org/support/topic/object-cache-issue-results-in-outdated-last-modified-values-on-index-sitemap/
  • FIX: Variable variable php 7 compat
  • Detect if headers are already sent and print warning in source
Download this release

Release Info

Developer deployer
Plugin Icon 128x128 XML Sitemap & Google News feeds
Version 4.7.5
Comparing to
See all releases

Code changes from version 4.7.3 to 4.7.5

.gitignore ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.log
2
+ .htaccess
3
+ sitemap.xml
4
+ sitemap.xml.gz
5
+ wp-config.php
6
+ wp-content/advanced-cache.php
7
+ wp-content/backup-db/
8
+ wp-content/backups/
9
+ wp-content/blogs.dir/
10
+ wp-content/cache/
11
+ wp-content/upgrade/
12
+ wp-content/uploads/
13
+ wp-content/wp-cache-config.php
14
+ wp-content/plugins/hello.php
15
+
16
+ /readme.html
17
+ /license.txt
18
+
hacks.php CHANGED
@@ -37,17 +37,16 @@ if( !function_exists('get_firstdate') ) {
37
  */
38
  if( !function_exists('get_lastdate') ) {
39
  function get_lastdate($timezone = 'server', $post_types = 'any', $m = false) {
 
 
40
 
41
- if (!is_array($post_types))
42
- $post_types = array($post_types);
43
-
44
- $lastmodified = array();
45
- foreach ($post_types as $post_type)
46
- $lastmodified[] = _get_time( $timezone, 'date', $post_type, 'last', $m );
47
 
48
- sort($lastmodified);
49
- $lastmodified = array_filter($lastmodified);
50
- return apply_filters( 'get_lastdate', end($lastmodified), $timezone );
51
  }
52
  }
53
 
@@ -87,10 +86,10 @@ if( !function_exists('_get_time') ) {
87
  return false;
88
 
89
  $timezone = strtolower( $timezone );
90
-
91
  $order = ( $which == 'last' ) ? 'DESC' : 'ASC';
92
 
93
- $key = ( $post_type == 'any' ) ? "{$which}post{$field}{$m}:$timezone" : "{$which}posttype{$post_type}{$field}{$m}:$timezone";
94
 
95
  $date = wp_cache_get( $key, 'timeinfo' );
96
 
@@ -114,8 +113,8 @@ if( !function_exists('_get_time') ) {
114
  $post_types = "'" . addslashes($post_type) . "'";
115
  }
116
 
117
- $where = "$wpdb->posts.post_status='publish' AND $wpdb->posts.post_type IN ({$post_types}) AND $wpdb->posts.post_date_gmt ";
118
- // If a month is specified in the querystring, load that month
119
  $m = preg_replace('|[^0-9]|', '', $m);
120
  if ( !empty($m) ) {
121
  $where .= " AND YEAR($wpdb->posts.post_date)=" . substr($m, 0, 4);
@@ -143,3 +142,26 @@ if( !function_exists('_get_time') ) {
143
  return $date;
144
  }
145
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  */
38
  if( !function_exists('get_lastdate') ) {
39
  function get_lastdate($timezone = 'server', $post_types = 'any', $m = false) {
40
+ if (!is_array($post_types))
41
+ $post_types = array($post_types);
42
 
43
+ $lastmodified = array();
44
+ foreach ($post_types as $post_type)
45
+ $lastmodified[] = _get_time( $timezone, 'date', $post_type, 'last', $m );
 
 
 
46
 
47
+ sort($lastmodified);
48
+ $lastmodified = array_filter($lastmodified);
49
+ return apply_filters( 'get_lastdate', end($lastmodified), $timezone );
50
  }
51
  }
52
 
86
  return false;
87
 
88
  $timezone = strtolower( $timezone );
89
+
90
  $order = ( $which == 'last' ) ? 'DESC' : 'ASC';
91
 
92
+ $key = _get_time_key( $timezone, $field, $post_type, $which, $m );
93
 
94
  $date = wp_cache_get( $key, 'timeinfo' );
95
 
113
  $post_types = "'" . addslashes($post_type) . "'";
114
  }
115
 
116
+ $where = "$wpdb->posts.post_status='publish' AND $wpdb->posts.post_type IN ({$post_types}) AND $wpdb->posts.post_date_gmt ";
117
+ // If a month is specified in the querystring, load that month
118
  $m = preg_replace('|[^0-9]|', '', $m);
119
  if ( !empty($m) ) {
120
  $where .= " AND YEAR($wpdb->posts.post_date)=" . substr($m, 0, 4);
142
  return $date;
143
  }
144
  }
145
+
146
+ /**
147
+ * Build transient key based on input parameters.
148
+ * Contributed by https://github.com/shaula https://wordpress.org/support/users/e2robert/
149
+ *
150
+ * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
151
+ * @param string $field Field to check. Can be 'date' or 'modified'.
152
+ * @param string $post_type Post type to check. Defaults to 'any'.
153
+ * @param string $which Which to check. Can be 'first' or 'last'. Defaults to 'last'.
154
+ * @param string $m month to check.
155
+ * @return string.
156
+ */
157
+ if( !function_exists('_get_time_key') ) {
158
+ function _get_time_key( $timezone, $field, $post_type = 'any', $which = 'last', $m = 0 ) {
159
+ $timezone = strtolower( $timezone );
160
+
161
+ if ( $post_type == 'any' ) {
162
+ return "{$which}post{$field}{$m}:$timezone";
163
+ }
164
+
165
+ return "{$which}posttype{$post_type}{$field}{$m}:$timezone";
166
+ }
167
+ }
includes/class-xmlsitemapfeed.php CHANGED
@@ -431,6 +431,46 @@ class XMLSitemapFeed {
431
  * TEMPLATE FUNCTIONS
432
  */
433
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
434
  public function modified( $sitemap = 'post_type', $term = '' )
435
  {
436
  if ('post_type' == $sitemap) :
@@ -809,7 +849,7 @@ class XMLSitemapFeed {
809
  if (pathinfo($request, PATHINFO_EXTENSION)) {
810
  return untrailingslashit($request);
811
  }
812
- return $request; // trailingslashit($request);
813
  }
814
 
815
  /**
@@ -849,6 +889,17 @@ class XMLSitemapFeed {
849
  $wp_rewrite->rules = $xmlsf_rules + $wp_rewrite->rules;
850
  }
851
 
 
 
 
 
 
 
 
 
 
 
 
852
  /**
853
  * REQUEST FILTER
854
  */
@@ -866,14 +917,11 @@ class XMLSitemapFeed {
866
  // Polylang compat
867
  $request['lang'] = '';
868
  // WPML compat
869
- global $wpml_query_filter,$wpml_url_filters;
870
- if ( isset($wpml_query_filter) && isset($wpml_url_filters) && is_object($wpml_query_filter) && is_object($wpml_url_filters) ) {
871
  remove_filter( 'posts_join', array( $wpml_query_filter, 'posts_join_filter' ) );
872
  remove_filter( 'posts_where', array( $wpml_query_filter, 'posts_where_filter' ) );
873
- remove_filter( 'post_link', array( $wpml_url_filters, 'permalink_filter' ), 1 );
874
- remove_filter( 'post_type_link', array( $wpml_url_filters, 'permalink_filter' ), 1 );
875
- remove_filter( 'page_link', array( $wpml_url_filters, 'permalink_filter_root' ), 1 );
876
- remove_filter( 'page_link', array( $wpml_url_filters, 'permalink_filter' ), 1 );
877
  }
878
 
879
  if ( $request['feed'] == 'sitemap-news' ) {
@@ -926,13 +974,12 @@ class XMLSitemapFeed {
926
  $request['taxonomy'] = $taxonomy;
927
 
928
  // WPML compat
929
- global $sitepress,$wpml_url_converter;
930
- if ( isset($sitepress) && isset($wpml_url_converter) && is_object($sitepress) && is_object($wpml_url_converter) ) {
931
  remove_filter( 'get_terms_args', array($sitepress, 'get_terms_args_filter') );
932
  remove_filter( 'get_term', array($sitepress,'get_term_adjust_id'), 1 );
933
  remove_filter( 'terms_clauses', array($sitepress,'terms_clauses') );
934
- remove_filter( 'category_link', array($sitepress, 'category_link_adjust_id'), 1 );
935
- remove_filter( 'term_link', array($wpml_url_converter, 'tax_permalink_filter'), 1 );
936
  }
937
 
938
  return $request;
@@ -1111,15 +1158,37 @@ class XMLSitemapFeed {
1111
  }
1112
  }
1113
 
1114
- function cache_flush( $new_status, $old_status )
1115
  {
1116
  // are we moving the post in or out of published status?
1117
  if ( $new_status == 'publish' || $old_status == 'publish' ) {
1118
  // Use cache_delete to remove single key instead of complete cache_flush. Thanks Jeremy Clarke!
1119
  wp_cache_delete('xmlsf_get_archives', 'general');
 
 
 
1120
  }
1121
  }
1122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1123
  public function nginx_helper_purge_urls( $urls = array(), $redis = false )
1124
  {
1125
  // are permalinks set, blog public and $urls an array?
@@ -1398,14 +1467,14 @@ class XMLSitemapFeed {
1398
  // REQUEST main filtering function
1399
  add_filter('request', array($this, 'filter_request'), 1 );
1400
 
1401
- // TEXT DOMAIN, UPGRADE PROCESS ...
1402
  add_action('plugins_loaded', array($this,'plugins_loaded'), 11 );
1403
 
1404
  // REWRITES
1405
  add_action('generate_rewrite_rules', array($this, 'rewrite_rules') );
1406
  add_filter('user_trailingslashit', array($this, 'trailingslash') );
1407
 
1408
- // TAXONOMY
1409
  add_action('init', array($this,'init'), 0 );
1410
 
1411
  // REGISTER SETTINGS, SETTINGS FIELDS...
@@ -1419,7 +1488,7 @@ class XMLSitemapFeed {
1419
  add_action('transition_post_status', array($this, 'do_pings'), 10, 3);
1420
 
1421
  // CLEAR OBJECT CACHE
1422
- add_action('transition_post_status', array($this, 'cache_flush'), 99, 2);
1423
 
1424
  // NGINX HELPER PURGE URLS
1425
  add_filter('rt_nginx_helper_purge_urls', array($this, 'nginx_helper_purge_urls'), 10, 2);
431
  * TEMPLATE FUNCTIONS
432
  */
433
 
434
+ public function headers( $style = '' )
435
+ {
436
+ // maybe output buffering is on, then just make sure we start with a clean buffer
437
+ if ( ob_get_level() ) ob_clean();
438
+
439
+ // check if headers are already sent (bad) and set up a warning in admin (how?)
440
+ if ( !headers_sent($filename, $linenum) ) {
441
+ status_header('200'); // force header('HTTP/1.1 200 OK') for sites without posts
442
+ header('Content-Type: text/xml; charset=' . get_bloginfo('charset'), true);
443
+ header('X-Robots-Tag: noindex, follow', true);
444
+ $output = '';
445
+ } else {
446
+ // output warning in sitemap for now, TODO admin message
447
+ $output = "<!-- WARNING: Headers already sent by $filename on line $linenum. Please fix! -->\n";
448
+ }
449
+
450
+ // which style sheet
451
+ switch ($style) {
452
+ case 'index':
453
+ $style_sheet = plugins_url('xsl/sitemap-index.xsl',__FILE__);
454
+ break;
455
+ case 'news':
456
+ $style_sheet = plugins_url('xsl/sitemap-news.xsl',__FILE__);
457
+ break;
458
+ default:
459
+ $style_sheet = plugins_url('xsl/sitemap.xsl',__FILE__);
460
+ break;
461
+ }
462
+
463
+ $output .= '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?>'.PHP_EOL;
464
+ $output .= '<?xml-stylesheet type="text/xsl" href="' . $style_sheet . '?ver=' . XMLSF_VERSION .'"?>'.PHP_EOL;
465
+ $output .= '<!-- generated-on="'.date('Y-m-d\TH:i:s+00:00').'" -->'.PHP_EOL;
466
+ $output .= '<!-- generator="XML & Google News Sitemap Feed plugin for WordPress" -->'.PHP_EOL;
467
+ $output .= '<!-- generator-url="http://status301.net/wordpress-plugins/xml-sitemap-feed/" -->'.PHP_EOL;
468
+ $output .= '<!-- generator-version="'.XMLSF_VERSION.'" -->'.PHP_EOL;
469
+
470
+ // return output
471
+ return $output;
472
+ }
473
+
474
  public function modified( $sitemap = 'post_type', $term = '' )
475
  {
476
  if ('post_type' == $sitemap) :
849
  if (pathinfo($request, PATHINFO_EXTENSION)) {
850
  return untrailingslashit($request);
851
  }
852
+ return $request;
853
  }
854
 
855
  /**
889
  $wp_rewrite->rules = $xmlsf_rules + $wp_rewrite->rules;
890
  }
891
 
892
+ public function wpml_language_switcher() {
893
+ // WPML: switch language
894
+ // @see https://wpml.org/wpml-hook/wpml_post_language_details/
895
+ global $sitepress,$post;
896
+ if( isset($sitepress) ) {
897
+ $post_language = apply_filters( 'wpml_post_language_details', NULL, $post->ID );
898
+ $sitepress->switch_lang($post_language['language_code']);
899
+ }
900
+
901
+ }
902
+
903
  /**
904
  * REQUEST FILTER
905
  */
917
  // Polylang compat
918
  $request['lang'] = '';
919
  // WPML compat
920
+ global $wpml_query_filter;
921
+ if ( isset($wpml_query_filter) && is_object($wpml_query_filter) ) {
922
  remove_filter( 'posts_join', array( $wpml_query_filter, 'posts_join_filter' ) );
923
  remove_filter( 'posts_where', array( $wpml_query_filter, 'posts_where_filter' ) );
924
+ add_action( 'the_post', array( $this, 'wpml_language_switcher' ) );
 
 
 
925
  }
926
 
927
  if ( $request['feed'] == 'sitemap-news' ) {
974
  $request['taxonomy'] = $taxonomy;
975
 
976
  // WPML compat
977
+ global $sitepress;
978
+ if ( isset($sitepress) && is_object($sitepress) ) {
979
  remove_filter( 'get_terms_args', array($sitepress, 'get_terms_args_filter') );
980
  remove_filter( 'get_term', array($sitepress,'get_term_adjust_id'), 1 );
981
  remove_filter( 'terms_clauses', array($sitepress,'terms_clauses') );
982
+ $sitepress->switch_lang('all');
 
983
  }
984
 
985
  return $request;
1158
  }
1159
  }
1160
 
1161
+ function cache_flush( $new_status, $old_status, $post )
1162
  {
1163
  // are we moving the post in or out of published status?
1164
  if ( $new_status == 'publish' || $old_status == 'publish' ) {
1165
  // Use cache_delete to remove single key instead of complete cache_flush. Thanks Jeremy Clarke!
1166
  wp_cache_delete('xmlsf_get_archives', 'general');
1167
+
1168
+ // we cannot delete by cache-group 'timeinfo', therefore we have to re-calculate the cache-key
1169
+ wp_cache_delete($this->get_time_key($post), 'timeinfo');
1170
  }
1171
  }
1172
 
1173
+ /**
1174
+ * This method mimics triggers the cache-key calculation used within _get_time().
1175
+ * The passed parameters mimic the behavior of get_lastmodified.
1176
+ *
1177
+ * Contributed by https://github.com/shaula https://wordpress.org/support/users/e2robert/
1178
+ *
1179
+ * @param \WP_Post $post
1180
+ * @return string
1181
+ */
1182
+ private function get_time_key($post)
1183
+ {
1184
+ $timezone = 'gmt';
1185
+ $which = 'last';
1186
+ $field = 'modified';
1187
+ $m = 0;
1188
+
1189
+ return _get_time_key($timezone, $field, $post->post_type, $which, $m);
1190
+ }
1191
+
1192
  public function nginx_helper_purge_urls( $urls = array(), $redis = false )
1193
  {
1194
  // are permalinks set, blog public and $urls an array?
1467
  // REQUEST main filtering function
1468
  add_filter('request', array($this, 'filter_request'), 1 );
1469
 
1470
+ // TEXT DOMAIN...
1471
  add_action('plugins_loaded', array($this,'plugins_loaded'), 11 );
1472
 
1473
  // REWRITES
1474
  add_action('generate_rewrite_rules', array($this, 'rewrite_rules') );
1475
  add_filter('user_trailingslashit', array($this, 'trailingslash') );
1476
 
1477
+ // TAXONOMIES, ACTIONS, UPGRADE...
1478
  add_action('init', array($this,'init'), 0 );
1479
 
1480
  // REGISTER SETTINGS, SETTINGS FIELDS...
1488
  add_action('transition_post_status', array($this, 'do_pings'), 10, 3);
1489
 
1490
  // CLEAR OBJECT CACHE
1491
+ add_action('transition_post_status', array($this, 'cache_flush'), 99, 3);
1492
 
1493
  // NGINX HELPER PURGE URLS
1494
  add_filter('rt_nginx_helper_purge_urls', array($this, 'nginx_helper_purge_urls'), 10, 2);
includes/feed-sitemap-custom.php CHANGED
@@ -7,24 +7,18 @@
7
 
8
  if ( ! defined( 'WPINC' ) ) die;
9
 
10
- status_header('200'); // force header('HTTP/1.1 200 OK') even for sites without posts
11
- header('Content-Type: text/xml; charset=' . get_bloginfo('charset'), true);
12
- header('X-Robots-Tag: noindex, follow', true);
13
 
14
- echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?>
15
- <?xml-stylesheet type="text/xsl" href="' . plugins_url('/xsl/sitemap.xsl',__FILE__) . '?ver=' . XMLSF_VERSION . '"?>
16
- <!-- generated-on="' . date('Y-m-d\TH:i:s+00:00') . '" -->
17
- <!-- generator="XML & Google News Sitemap Feed plugin for WordPress" -->
18
- <!-- generator-url="http://status301.net/wordpress-plugins/xml-sitemap-feed/" -->
19
- <!-- generator-version="' . XMLSF_VERSION . '" -->
20
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
21
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
23
  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
24
- ';
25
 
26
  // get our custom urls array
27
- global $xmlsf;
28
  $urls = $xmlsf->get_urls();
29
 
30
  // and loop away!
7
 
8
  if ( ! defined( 'WPINC' ) ) die;
9
 
10
+ global $xmlsf;
 
 
11
 
12
+ // start output
13
+ echo $xmlsf->headers();
14
+ ?>
 
 
 
15
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
16
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
18
  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
19
+ <?php
20
 
21
  // get our custom urls array
 
22
  $urls = $xmlsf->get_urls();
23
 
24
  // and loop away!
includes/feed-sitemap-home.php CHANGED
@@ -7,23 +7,17 @@
7
 
8
  if ( ! defined( 'WPINC' ) ) die;
9
 
10
- status_header('200'); // force header('HTTP/1.1 200 OK') even for sites without posts
11
- header('Content-Type: text/xml; charset=' . get_bloginfo('charset'), true);
12
- header('X-Robots-Tag: noindex, follow', true);
13
 
14
- echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?>
15
- <?xml-stylesheet type="text/xsl" href="' . plugins_url('/xsl/sitemap.xsl',__FILE__) . '?ver=' . XMLSF_VERSION . '"?>
16
- <!-- generated-on="' . date('Y-m-d\TH:i:s+00:00') . '" -->
17
- <!-- generator="XML & Google News Sitemap Feed plugin for WordPress" -->
18
- <!-- generator-url="http://status301.net/wordpress-plugins/xml-sitemap-feed/" -->
19
- <!-- generator-version="' . XMLSF_VERSION . '" -->
20
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
21
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
23
  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
24
- ';
25
 
26
- global $xmlsf;
27
  $lastmodified = get_lastdate( 'gmt' ); // TODO take language into account !! Dont't use get_lastdate but pull one post for each language instead?
28
  $lastactivityage = ( gmdate('U') - mysql2date( 'U', $lastmodified ) );
29
  foreach ( $xmlsf->get_home_urls() as $url ) {
7
 
8
  if ( ! defined( 'WPINC' ) ) die;
9
 
10
+ global $xmlsf;
 
 
11
 
12
+ // start output
13
+ echo $xmlsf->headers();
14
+ ?>
 
 
 
15
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
16
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
18
  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
19
+ <?php
20
 
 
21
  $lastmodified = get_lastdate( 'gmt' ); // TODO take language into account !! Dont't use get_lastdate but pull one post for each language instead?
22
  $lastactivityage = ( gmdate('U') - mysql2date( 'U', $lastmodified ) );
23
  foreach ( $xmlsf->get_home_urls() as $url ) {
includes/feed-sitemap-news.php CHANGED
@@ -8,34 +8,31 @@
8
  if ( ! defined( 'WPINC' ) ) die;
9
 
10
  global $xmlsf;
11
- $options = $xmlsf->get_option('news_tags');
12
 
13
- status_header('200'); // force header('HTTP/1.1 200 OK') for sites without posts
14
- header('Content-Type: text/xml; charset=' . get_bloginfo('charset'), true);
15
- header('X-Robots-Tag: noindex, follow', true);
16
 
17
- echo '<?xml version="1.0" encoding="'.get_bloginfo('charset').'"?>
18
- <?xml-stylesheet type="text/xsl" href="' . plugins_url('/xsl/sitemap-news.xsl',__FILE__) . '?ver=' . XMLSF_VERSION . '"?>
19
- <!-- generated-on="'.date('Y-m-d\TH:i:s+00:00').'" -->
20
- <!-- generator="XML & Google News Sitemap Feed plugin for WordPress" -->
21
- <!-- generator-url="http://status301.net/wordpress-plugins/xml-sitemap-feed/" -->
22
- <!-- generator-version="'.XMLSF_VERSION.'" -->
 
 
 
 
 
 
 
23
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
24
- xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" ';
25
-
26
- echo !empty($options['image']) ? '
27
- xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" ' : '';
28
- echo '
29
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
30
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
31
  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd
32
  http://www.google.com/schemas/sitemap-news/0.9
33
- http://www.google.com/schemas/sitemap-news/0.9/sitemap-news.xsd' ;
34
- echo !empty($options['image']) ? '
35
- http://www.google.com/schemas/sitemap-image/1.1
36
- http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd' : '';
37
- echo '">
38
- ';
39
 
40
  // set empty news sitemap flag
41
  $have_posts = false;
8
  if ( ! defined( 'WPINC' ) ) die;
9
 
10
  global $xmlsf;
 
11
 
12
+ $options = $xmlsf->get_option('news_tags');
 
 
13
 
14
+ if ( !empty($options['image']) ) {
15
+ $image_xmlns = ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"'.PHP_EOL;
16
+ $image_schema = '
17
+ http://www.google.com/schemas/sitemap-image/1.1
18
+ http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd';
19
+ } else {
20
+ $image_xmlns = '';
21
+ $image_schema = '';
22
+ }
23
+
24
+ // start output
25
+ echo $xmlsf->headers('news');
26
+ ?>
27
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
28
+ xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
29
+ <?php echo $image_xmlns; ?>
 
 
 
30
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
31
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
32
  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd
33
  http://www.google.com/schemas/sitemap-news/0.9
34
+ http://www.google.com/schemas/sitemap-news/0.9/sitemap-news.xsd<?php echo $image_schema; ?>">
35
+ <?php
 
 
 
 
36
 
37
  // set empty news sitemap flag
38
  $have_posts = false;
includes/feed-sitemap-post_type.php CHANGED
@@ -7,34 +7,30 @@
7
 
8
  if ( ! defined( 'WPINC' ) ) die;
9
 
10
- status_header('200'); // force header('HTTP/1.1 200 OK') even for sites without posts
11
- header('Content-Type: text/xml; charset=' . get_bloginfo('charset'), true);
12
- header('X-Robots-Tag: noindex, follow', true);
13
-
14
- echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?>
15
- <?xml-stylesheet type="text/xsl" href="' . plugins_url('/xsl/sitemap.xsl',__FILE__) . '?ver=' . XMLSF_VERSION . '"?>
16
- <!-- generated-on="' . date('Y-m-d\TH:i:s+00:00') . '" -->
17
- <!-- generator="XML & Google News Sitemap Feed plugin for WordPress" -->
18
- <!-- generator-url="http://status301.net/wordpress-plugins/xml-sitemap-feed/" -->
19
- <!-- generator-version="' . XMLSF_VERSION . '" -->
20
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" ';
21
-
22
  global $xmlsf;
23
 
24
  foreach ( $xmlsf->do_tags( get_query_var('post_type') ) as $tag => $setting )
25
- $$tag = $setting;
 
 
 
 
 
 
 
 
 
 
26
 
27
- echo !empty($image) ? '
28
- xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" ' : '';
29
- echo '
 
 
30
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
31
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
32
- http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd';
33
- echo !empty($image) ? '
34
- http://www.google.com/schemas/sitemap-image/1.1
35
- http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd' : '';
36
- echo '">
37
- ';
38
 
39
  // set empty sitemap flag
40
  $have_posts = false;
7
 
8
  if ( ! defined( 'WPINC' ) ) die;
9
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  global $xmlsf;
11
 
12
  foreach ( $xmlsf->do_tags( get_query_var('post_type') ) as $tag => $setting )
13
+ ${$tag} = $setting;
14
+
15
+ if ( !empty($image) ) {
16
+ $image_xmlns = ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"'.PHP_EOL;
17
+ $image_schema = '
18
+ http://www.google.com/schemas/sitemap-image/1.1
19
+ http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd';
20
+ } else {
21
+ $image_xmlns = '';
22
+ $image_schema = '';
23
+ }
24
 
25
+ // start output
26
+ echo $xmlsf->headers();
27
+ ?>
28
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
29
+ <?php echo $image_xmlns; ?>
30
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
31
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
32
+ http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd<?php echo $image_schema; ?>">
33
+ <?php
 
 
 
 
34
 
35
  // set empty sitemap flag
36
  $have_posts = false;
includes/feed-sitemap-taxonomy.php CHANGED
@@ -7,24 +7,16 @@
7
 
8
  if ( ! defined( 'WPINC' ) ) die;
9
 
10
- status_header('200'); // force header('HTTP/1.1 200 OK') for sites without posts
11
- header('Content-Type: text/xml; charset=' . get_bloginfo('charset', 'UTF-8'), true);
12
- header('X-Robots-Tag: noindex, follow', true);
13
 
14
- echo '<?xml version="1.0" encoding="'.get_bloginfo('charset', 'UTF-8').'"?>
15
- <?xml-stylesheet type="text/xsl" href="' . plugins_url('/xsl/sitemap.xsl',__FILE__) . '?ver=' . XMLSF_VERSION . '"?>
16
- <!-- generated-on="'.date('Y-m-d\TH:i:s+00:00').'" -->
17
- <!-- generator="XML & Google News Sitemap Feed plugin for WordPress" -->
18
- <!-- generator-url="http://status310.net/wordpress-plugins/xml-sitemap-feed/" -->
19
- <!-- generator-version="'.XMLSF_VERSION.'" -->
20
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
21
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
23
  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
24
- ';
25
-
26
- global $xmlsf;
27
-
28
  $taxonomy = get_query_var('taxonomy');
29
 
30
  $terms = get_terms( $taxonomy, array(
@@ -36,9 +28,7 @@ $terms = get_terms( $taxonomy, array(
36
  'number' => 50000 ) );
37
 
38
  if ( $terms ) :
39
-
40
  foreach ( $terms as $term ) :
41
-
42
  ?>
43
  <url>
44
  <loc><?php echo get_term_link( $term ); ?></loc>
7
 
8
  if ( ! defined( 'WPINC' ) ) die;
9
 
10
+ global $xmlsf;
 
 
11
 
12
+ // start output
13
+ echo $xmlsf->headers();
14
+ ?>
 
 
 
15
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
16
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
18
  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
19
+ <?php
 
 
 
20
  $taxonomy = get_query_var('taxonomy');
21
 
22
  $terms = get_terms( $taxonomy, array(
28
  'number' => 50000 ) );
29
 
30
  if ( $terms ) :
 
31
  foreach ( $terms as $term ) :
 
32
  ?>
33
  <url>
34
  <loc><?php echo get_term_link( $term ); ?></loc>
includes/feed-sitemap.php CHANGED
@@ -7,24 +7,15 @@
7
 
8
  if ( ! defined( 'WPINC' ) ) die;
9
 
10
- status_header('200'); // force header('HTTP/1.1 200 OK') for sites without posts
11
- header('Content-Type: text/xml; charset=' . get_bloginfo('charset'), true);
12
- header('X-Robots-Tag: noindex, follow', true);
13
 
14
- echo '<?xml version="1.0" encoding="'.get_bloginfo('charset').'"?>
15
- <?xml-stylesheet type="text/xsl" href="' . plugins_url('xsl/sitemap-index.xsl',__FILE__) . '?ver=' . XMLSF_VERSION . '"?>
16
- <!-- generated-on="'.date('Y-m-d\TH:i:s+00:00').'" -->
17
- <!-- generator="XML & Google News Sitemap Feed plugin for WordPress" -->
18
- <!-- generator-url="http://status301.net/wordpress-plugins/xml-sitemap-feed/" -->
19
- <!-- generator-version="'.XMLSF_VERSION.'" -->
20
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
21
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
23
  http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd">
24
- ';
25
-
26
- global $xmlsf;
27
- ?>
28
  <sitemap>
29
  <loc><?php echo $xmlsf->get_index_url('home'); ?></loc>
30
  <lastmod><?php echo mysql2date('Y-m-d\TH:i:s+00:00', get_lastdate( 'gmt' ), false); ?></lastmod>
7
 
8
  if ( ! defined( 'WPINC' ) ) die;
9
 
10
+ global $xmlsf;
 
 
11
 
12
+ // start output
13
+ echo $xmlsf->headers('index');
14
+ ?>
 
 
 
15
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
16
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
18
  http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd">
 
 
 
 
19
  <sitemap>
20
  <loc><?php echo $xmlsf->get_index_url('home'); ?></loc>
21
  <lastmod><?php echo mysql2date('Y-m-d\TH:i:s+00:00', get_lastdate( 'gmt' ), false); ?></lastmod>
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: RavanH
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap%20Feed
4
  Tags: sitemap, xml sitemap, news sitemap, sitemap.xml, robots.txt, Google, Google News, Yahoo, Bing, , Yandex, Baidu, seo, feed, Polylang, WPML, image sitemap
5
  Requires at least: 3.2
6
- Tested up to: 4.5
7
- Stable tag: 4.7.3
8
 
9
  XML and Google News Sitemaps to feed the hungry spiders. Multisite, WP Super Cache, Polylang and WPML compatible.
10
 
@@ -56,18 +56,12 @@ Please read the FAQ's for info on how to get your articles listed on Google News
56
  * Option to add new robots.txt rules. These can be used to further control (read: limit) the indexation of various parts of your site and subsequent spread of pagerank accross your sites pages.
57
  * Includes XLS stylesheets for human readable sitemaps.
58
 
59
- = Translations =
60
 
61
- - **Dutch** * R.A. van Hagen http://status301.net (version 4.4)
62
- - **French** * R.A. van Hagen http://status301.net (version 4.2) (improved translation or suggestions needed!)
63
- - **Indonesian** * Nasrulhaq Muiz http://al-badar.net/ (version 4.2)
64
- - **Italian** * Raffaello Tesi http://www.raffaellotesi.com (version 4.3.2)
65
- - **Japanese** * gblsm https://profiles.wordpress.org/gblsm/ (version 4.6)
66
- - **Serbian** * WPdiscounts http://wpdiscounts.com/ (version 4.1)
67
- - **Spanish** * Andrew Kurtis - WebHostingHub Support http://www.webhostinghub.com/ (version 4.3.2)
68
- - **Ukrainian** * Cmd Software http://www.cmd-soft.com/ (version 4.0)
69
 
70
- New transtations will be accepted and listed here. See translation instructions under [Other Notes](http://wordpress.org/plugins/xml-sitemap-feed/other_notes/).
71
 
72
  = Credits =
73
 
@@ -269,23 +263,6 @@ Read more on [Increasing memory allocated to PHP](http://codex.wordpress.org/Edi
269
  Yes. In fact, it has been designed for it. Tested on WPMU 2.9.2 and WPMS 3+ both with normal activation and with Network Activate / Site Wide Activate.
270
 
271
 
272
- == Translation ==
273
-
274
- 1. Install PoEdit on your computer.
275
- 1. Go to this plugins /languages/ directory.
276
- 1. If there is no .po file that corresponds with your language yet, rename the template translation database xml-sitemap-feed-xx_XX.po by replacing the xx with your language code and XX with your country code.
277
- 1. Open the .po file of your language with PoEdit.
278
- 1. Go to Edit > Preferences and on the tab Editor check the option to compile a .mo database on save automatically. Close with OK.
279
- 1. Go to Catalog > Settings and set your name, e-mail address, language and country. Close with OK.
280
- 1. Go to Catalog > Update from POT-file and select the main xml-sitemap-feed.pot file. Then accept all new and removed translation strings with OK.
281
- 1. Now go ahead and start translating all the texts listed in PoEdit.
282
- 1. When done, go to File > Save to Save.
283
- 1. Upload the automatically created xml-sitemap-feed-xx_XX.mo database file (where xx_XX should now be your language and country code) to the plugins /languages/ directory on your WordPress site.
284
- 1. After verifying the translations work on your site, send the .mo file and, if you're willing to share it, your original .po file to ravanhagen@gmail.com and don't forget to tell me how and with what link you would like to be mentioned in the credits!
285
-
286
- Thanks for sharing your translation :)
287
-
288
-
289
  == Screenshots ==
290
 
291
  1. XML Sitemap feed viewed in a normal browser. For your eyes only ;)
@@ -294,11 +271,31 @@ Thanks for sharing your translation :)
294
 
295
  == Upgrade Notice ==
296
 
297
- = 4.7.3 =
298
- Improved Polylang and WPML compatibility. Various bug fixes.
299
 
300
  == Changelog ==
301
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  = 4.7.3 =
303
  * NEW: xmlsf_excluded filter
304
  * IMPROVEMENT: Polylang and WPML compatibility issues
@@ -335,7 +332,7 @@ Improved Polylang and WPML compatibility. Various bug fixes.
335
  * Set Google News access tag per post
336
  * Exclude posts from Google News sitemap
337
  * News Sitemap stylesheet text/links update
338
- * FIX: delete cached key as suggested by Jeremy Clarke https://wordpress.org/support/topic/please-stop-running-wp_cache_flush-whenever-posts-are-edited
339
  * NEW: Nginx Helper compatibility to purge cache sitemap URLs from FastCGI Cache or Redis
340
 
341
  = 4.4.1 =
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap%20Feed
4
  Tags: sitemap, xml sitemap, news sitemap, sitemap.xml, robots.txt, Google, Google News, Yahoo, Bing, , Yandex, Baidu, seo, feed, Polylang, WPML, image sitemap
5
  Requires at least: 3.2
6
+ Tested up to: 4.8
7
+ Stable tag: 4.7.5
8
 
9
  XML and Google News Sitemaps to feed the hungry spiders. Multisite, WP Super Cache, Polylang and WPML compatible.
10
 
56
  * Option to add new robots.txt rules. These can be used to further control (read: limit) the indexation of various parts of your site and subsequent spread of pagerank accross your sites pages.
57
  * Includes XLS stylesheets for human readable sitemaps.
58
 
59
+ = Contribute =
60
 
61
+ If you're happy with this plugin as it is, please consider writing a quick [rating](https://wordpress.org/support/plugin/xml-sitemap-feed/reviews/#new-post) or helping other users out on the [support forum](https://wordpress.org/support/plugin/easy-fancybox).
62
+
63
+ If you wish to help build this plugin, you're very welcome to [translate Easy FancyBox into your language](https://translate.wordpress.org/projects/wp-plugins/xml-sitemap-feed/) or contribute code on [Github](https://github.com/RavanH/xml-sitemap-feed/).
 
 
 
 
 
64
 
 
65
 
66
  = Credits =
67
 
263
  Yes. In fact, it has been designed for it. Tested on WPMU 2.9.2 and WPMS 3+ both with normal activation and with Network Activate / Site Wide Activate.
264
 
265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  == Screenshots ==
267
 
268
  1. XML Sitemap feed viewed in a normal browser. For your eyes only ;)
271
 
272
  == Upgrade Notice ==
273
 
274
+ = 4.8 =
275
+ ... and several bug fixes.
276
 
277
  == Changelog ==
278
 
279
+ = 4.8 =
280
+ * NEW: Conditional functions is_sitemap() and is_news()
281
+ * code cleanup and annotation
282
+ * new google ping URL
283
+ * revisit get first/last date/modified functions and cache key set/delete
284
+ * FIX: cache key missing timezone
285
+ * FIX: wp_rewrite init before flush_rules
286
+
287
+ = 4.7.6 =
288
+ * FIX Open_BaseDir issue on IIS server
289
+
290
+ = 4.7.5 =
291
+ * FIX: On cache_flush purge also the respective time_key cache entry,
292
+ props @e2robert https://wordpress.org/support/topic/object-cache-issue-results-in-outdated-last-modified-values-on-index-sitemap/
293
+ * FIX: Variable variable php 7 compat
294
+ * Detect if headers are already sent and print warning in source
295
+
296
+ = 4.7.4 =
297
+ * Another WPML compat issue fixed, special thanks to hermes3por3
298
+
299
  = 4.7.3 =
300
  * NEW: xmlsf_excluded filter
301
  * IMPROVEMENT: Polylang and WPML compatibility issues
332
  * Set Google News access tag per post
333
  * Exclude posts from Google News sitemap
334
  * News Sitemap stylesheet text/links update
335
+ * FIX: cache_delete cached key instead of cache_flush as suggested by Jeremy Clarke https://wordpress.org/support/topic/please-stop-running-wp_cache_flush-whenever-posts-are-edited
336
  * NEW: Nginx Helper compatibility to purge cache sitemap URLs from FastCGI Cache or Redis
337
 
338
  = 4.4.1 =
xml-sitemap.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: XML Sitemap & Google News feeds
4
  Plugin URI: http://status301.net/wordpress-plugins/xml-sitemap-feed/
5
  Description: Feed the hungry spiders in compliance with the XML Sitemap and Google News protocols. Happy with the results? Please leave me a <strong><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap%20Feed&item_number=4%2e0&no_shipping=0&tax=0&bn=PP%2dDonationsBF&charset=UTF%2d8&lc=us">tip</a></strong> for continued development and support. Thanks :)
6
  Text Domain: xml-sitemap-feed
7
- Version: 4.7.3
8
  Author: RavanH
9
  Author URI: http://status301.net/
10
  */
@@ -28,22 +28,22 @@ Author URI: http://status301.net/
28
  * --------------------
29
  *
30
  * FILTERS
31
- * xmlsf_defaults -> Filters the default array values for different option groups.
32
- * xmlsf_allowed_domain -> Filters the response when checking the url against allowed domains.
33
  * Passes variable $url; must return true or false.
34
- * xmlsf_excluded -> Filters the response when checking the post for exclusion flags.
35
  * Passes variable $post_id; must return true or false.
36
- * the_title_xmlsitemap -> Filters the Google News publication name, title and keywords
37
  * plus the Image title and caption tags
38
- * xmlsf_custom_urls -> Filters the custom urls array
39
- * xmlsf_custom_sitemaps -> Filters the custom sitemaps array
40
  *
41
  * ACTIONS
42
- * xmlsf_news_tags_after -> Fired inside the Google News Sitemap loop at the end of the news
43
  * tags, just before each closing </news:news> is generated. Can be used to
44
  * echo custom tags or trigger another action in the background.
45
  *
46
- * feel free to request, suggest or submit more :)
47
  */
48
 
49
  if ( ! defined( 'WPINC' ) ) die;
@@ -52,7 +52,7 @@ if ( ! defined( 'WPINC' ) ) die;
52
  * CONSTANTS
53
  * -------------------- */
54
 
55
- define('XMLSF_VERSION', '4.7.3');
56
 
57
  define('XMLSF_PLUGIN_BASENAME', plugin_basename(__FILE__));
58
 
4
  Plugin URI: http://status301.net/wordpress-plugins/xml-sitemap-feed/
5
  Description: Feed the hungry spiders in compliance with the XML Sitemap and Google News protocols. Happy with the results? Please leave me a <strong><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap%20Feed&item_number=4%2e0&no_shipping=0&tax=0&bn=PP%2dDonationsBF&charset=UTF%2d8&lc=us">tip</a></strong> for continued development and support. Thanks :)
6
  Text Domain: xml-sitemap-feed
7
+ Version: 4.7.5
8
  Author: RavanH
9
  Author URI: http://status301.net/
10
  */
28
  * --------------------
29
  *
30
  * FILTERS
31
+ * xmlsf_defaults -> Filters the default array values for different option groups.
32
+ * xmlsf_allowed_domain -> Filters the response when checking the url against allowed domains.
33
  * Passes variable $url; must return true or false.
34
+ * xmlsf_excluded -> Filters the response when checking the post for exclusion flags.
35
  * Passes variable $post_id; must return true or false.
36
+ * the_title_xmlsitemap -> Filters the Google News publication name, title and keywords
37
  * plus the Image title and caption tags
38
+ * xmlsf_custom_urls -> Filters the custom urls array
39
+ * xmlsf_custom_sitemaps -> Filters the custom sitemaps array
40
  *
41
  * ACTIONS
42
+ * xmlsf_news_tags_after -> Fired inside the Google News Sitemap loop at the end of the news
43
  * tags, just before each closing </news:news> is generated. Can be used to
44
  * echo custom tags or trigger another action in the background.
45
  *
46
+ * Feel free to request, suggest or submit more :)
47
  */
48
 
49
  if ( ! defined( 'WPINC' ) ) die;
52
  * CONSTANTS
53
  * -------------------- */
54
 
55
+ define('XMLSF_VERSION', '4.7.5');
56
 
57
  define('XMLSF_PLUGIN_BASENAME', plugin_basename(__FILE__));
58