XML Sitemap & Google News feeds - Version 4.9.4

Version Description

Bugfixes: double content type filtering and missing featured images (thanks @flyerua)

=

Download this release

Release Info

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

Code changes from version 4.9.2 to 4.9.4

.gitignore DELETED
@@ -1,18 +0,0 @@
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
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md DELETED
@@ -1,6 +0,0 @@
1
- # XML Sitemap & Google News feeds
2
-
3
- XML and Google News Sitemaps for WordPress to feed the hungry spiders. Multisite, WP Super Cache, Polylang and WPML compatible.
4
-
5
- [https://wordpress.org/plugins/xml-sitemap-feed/](https://wordpress.org/plugins/xml-sitemap-feed/)
6
-
 
 
 
 
 
 
includes/class-xmlsitemapfeed.php CHANGED
@@ -609,12 +609,12 @@ class XMLSitemapFeed {
609
  /**
610
  * Is home?
611
  *
612
- * @param $id
613
  *
614
  * @return bool
615
  */
616
- private function is_home( $id ) {
617
- return in_array( $id, $this->get_blogpages() );
618
  }
619
 
620
  /**
@@ -809,7 +809,7 @@ class XMLSitemapFeed {
809
  }
810
  } elseif ( 'featured' == $which ) {
811
  if ( has_post_thumbnail( $post->ID ) ) {
812
- //$attachment = get_post( get_post_thumbnail_id( $post->ID ) );
813
  $url = wp_get_attachment_image_url( get_post_thumbnail_id( $post->ID ), 'full' );
814
  $url = $this->get_absolute_url( $url );
815
  if ( !empty($url) ) {
@@ -1032,44 +1032,75 @@ class XMLSitemapFeed {
1032
  }
1033
 
1034
  /**
1035
- * Get language
1036
- *
1037
- * @param $id
1038
  *
1039
- * @return null|string
1040
  */
1041
- public function get_language( $id ) {
1042
- $language = null;
1043
-
1044
  if ( empty($this->blog_language) ) {
1045
  // get site language for default language
1046
- $blog_language = convert_chars(strip_tags(get_bloginfo('language')));
1047
- $allowed = array('zh-cn','zh-tw');
1048
- if ( !in_array($blog_language,$allowed) ) {
1049
- // bloginfo_rss('language') returns improper format so
1050
- // we explode on hyphen and use only first part.
1051
- $expl = explode('-', $blog_language);
1052
- $blog_language = $expl[0];
1053
- }
1054
 
1055
  $this->blog_language = !empty($blog_language) ? $blog_language : 'en';
1056
  }
1057
 
1058
- // WPML compat
1059
- global $sitepress;
1060
- if ( isset($sitepress) && is_object($sitepress) && method_exists($sitepress, 'get_language_for_element') ) {
1061
- $post_type = get_query_var( 'post_type', 'post' ); // is $post_type always an array here??
1062
- $language = $sitepress->get_language_for_element( $id, 'post_'.$post_type[0] );
1063
- //apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $id, 'element_type' => $post_type ) );
 
 
 
 
 
 
 
 
 
 
 
1064
  }
1065
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1066
  // Polylang
1067
  if ( function_exists('pll_get_post_language') ) {
1068
- $lang = pll_get_post_language( $id, 'slug' );
1069
- $language = !empty($lang) ? $lang : $language;
 
1070
  }
1071
 
1072
- return !empty($language) ? $language : $this->blog_language;
 
 
 
 
 
 
 
 
 
 
1073
  }
1074
 
1075
 
@@ -1189,8 +1220,7 @@ class XMLSitemapFeed {
1189
  // set the normal sitemap conditional tag
1190
  $this->is_sitemap = true;
1191
 
1192
- // CONTENT_TYPE and REPSONSE HEADERS filtering function
1193
- add_filter( 'feed_content_type', array($this, 'content_type') );
1194
  add_filter( 'wp_headers', array($this, 'headers') );
1195
 
1196
  // modify request parameters
@@ -1214,21 +1244,29 @@ class XMLSitemapFeed {
1214
  if ( $request['feed'] == 'sitemap-news' ) {
1215
  $defaults = $this->defaults('news_tags');
1216
  $options = $this->get_option('news_tags');
1217
- $news_post_type = isset($options['post_type']) && !empty($options['post_type']) ? $options['post_type'] : $defaults['post_type'];
1218
- if (empty($news_post_type)) {
1219
- $news_post_type = 'post';
1220
- }
1221
 
1222
  // disable caching
1223
  define('DONOTCACHEPAGE', true);
1224
  define('DONOTCACHEDB', true);
1225
 
1226
  // set up query filters
1227
- add_filter('post_limits', array($this, 'filter_news_limits'));
1228
- add_filter('posts_where', array($this, 'filter_news_where'), 10, 1);
 
 
 
 
 
 
 
 
 
 
 
1229
 
1230
  // post type
1231
- $request['post_type'] = $news_post_type;
1232
 
1233
  // categories
1234
  if ( isset($options['categories']) && is_array($options['categories']) ) {
@@ -1294,21 +1332,6 @@ class XMLSitemapFeed {
1294
  return $request;
1295
  }
1296
 
1297
- /**
1298
- * XML Sitemap content type filter
1299
- *
1300
- * @param $content_type
1301
- * @param $type
1302
- *
1303
- * @return string
1304
- */
1305
- function content_type( $content_type, $type = 'sitemap' ) {
1306
- if ( strpos($type,'sitemap') === 0 )
1307
- $content_type = 'text/xml';
1308
-
1309
- return $content_type;
1310
- }
1311
-
1312
  /**
1313
  * Response headers filter
1314
  * Does not check if we are really in a sitemap feed.
@@ -1320,6 +1343,7 @@ class XMLSitemapFeed {
1320
  function headers( $headers ) {
1321
  // set noindex
1322
  $headers['X-Robots-Tag'] = 'noindex, follow';
 
1323
  return $headers;
1324
  }
1325
 
609
  /**
610
  * Is home?
611
  *
612
+ * @param $post_id
613
  *
614
  * @return bool
615
  */
616
+ private function is_home( $post_id ) {
617
+ return in_array( $post_id, $this->get_blogpages() );
618
  }
619
 
620
  /**
809
  }
810
  } elseif ( 'featured' == $which ) {
811
  if ( has_post_thumbnail( $post->ID ) ) {
812
+ $attachment = get_post( get_post_thumbnail_id( $post->ID ) );
813
  $url = wp_get_attachment_image_url( get_post_thumbnail_id( $post->ID ), 'full' );
814
  $url = $this->get_absolute_url( $url );
815
  if ( !empty($url) ) {
1032
  }
1033
 
1034
  /**
1035
+ * Get site language
 
 
1036
  *
1037
+ * @return string
1038
  */
1039
+ public function get_blog_language() {
 
 
1040
  if ( empty($this->blog_language) ) {
1041
  // get site language for default language
1042
+ $blog_language = $this->parse_language_string( get_bloginfo('language') );
 
 
 
 
 
 
 
1043
 
1044
  $this->blog_language = !empty($blog_language) ? $blog_language : 'en';
1045
  }
1046
 
1047
+ return $this->blog_language;
1048
+ }
1049
+
1050
+ /**
1051
+ * Get site language
1052
+ *
1053
+ * @param string $lang unformatted language string
1054
+ *
1055
+ * @return string
1056
+ */
1057
+ public function parse_language_string( $lang ) {
1058
+ $lang = convert_chars( strtolower( strip_tags( $lang ) ) );
1059
+
1060
+ // no underscores
1061
+ if ( strpos( $lang, '_' ) ) {
1062
+ $expl = explode('_', $lang);
1063
+ $lang = $expl[0];
1064
  }
1065
 
1066
+ // no hyphens except...
1067
+ if ( strpos( $lang, '-' ) && !in_array( $lang, array('zh-cn','zh-tw') ) ) {
1068
+ // explode on hyphen and use only first part
1069
+ $expl = explode('-', $lang);
1070
+ $lang = $expl[0];
1071
+ }
1072
+
1073
+ return $lang;
1074
+ }
1075
+
1076
+ /**
1077
+ * Get language
1078
+ *
1079
+ * @param $post_id
1080
+ *
1081
+ * @return null|string
1082
+ */
1083
+ public function get_language( $post_id ) {
1084
+ $language = $this->get_blog_language();
1085
+
1086
  // Polylang
1087
  if ( function_exists('pll_get_post_language') ) {
1088
+ $lang = pll_get_post_language( $post_id, 'slug' );
1089
+ if ( !empty($lang) )
1090
+ $language = $this->parse_language_string( $lang );
1091
  }
1092
 
1093
+ // WPML compat
1094
+ global $sitepress;
1095
+ if ( isset($sitepress) && is_object($sitepress) && method_exists($sitepress, 'get_language_for_element') ) {
1096
+ $post_type = (array) get_query_var( 'post_type', 'post' );
1097
+ $lang = $sitepress->get_language_for_element( $post_id, 'post_'.$post_type[0] );
1098
+ //apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $post_id, 'element_type' => $post_type ) );
1099
+ if ( !empty($lang) )
1100
+ $language = $this->parse_language_string( $lang );
1101
+ }
1102
+
1103
+ return apply_filters( 'xmlsf_post_language', $language, $post_id );
1104
  }
1105
 
1106
 
1220
  // set the normal sitemap conditional tag
1221
  $this->is_sitemap = true;
1222
 
1223
+ // REPSONSE HEADERS filtering
 
1224
  add_filter( 'wp_headers', array($this, 'headers') );
1225
 
1226
  // modify request parameters
1244
  if ( $request['feed'] == 'sitemap-news' ) {
1245
  $defaults = $this->defaults('news_tags');
1246
  $options = $this->get_option('news_tags');
1247
+ $news_post_types = isset($options['post_type']) && !empty($options['post_type']) ? (array)$options['post_type'] : $defaults['post_type'];
 
 
 
1248
 
1249
  // disable caching
1250
  define('DONOTCACHEPAGE', true);
1251
  define('DONOTCACHEDB', true);
1252
 
1253
  // set up query filters
1254
+ $live = false;
1255
+ foreach ($news_post_types as $news_post_type) {
1256
+ if ( get_lastpostdate('gmt', $news_post_type) > date('Y-m-d H:i:s', strtotime('-48 hours')) ) {
1257
+ $live = true;
1258
+ break;
1259
+ }
1260
+ }
1261
+ if ( $live ) {
1262
+ add_filter('post_limits', array($this, 'filter_news_limits'));
1263
+ add_filter('posts_where', array($this, 'filter_news_where'), 10, 1);
1264
+ } else {
1265
+ add_filter('post_limits', array($this, 'filter_no_news_limits'));
1266
+ }
1267
 
1268
  // post type
1269
+ $request['post_type'] = $news_post_types;
1270
 
1271
  // categories
1272
  if ( isset($options['categories']) && is_array($options['categories']) ) {
1332
  return $request;
1333
  }
1334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1335
  /**
1336
  * Response headers filter
1337
  * Does not check if we are really in a sitemap feed.
1343
  function headers( $headers ) {
1344
  // set noindex
1345
  $headers['X-Robots-Tag'] = 'noindex, follow';
1346
+ $headers['Content-Type'] = 'text/xml; charset=' . get_bloginfo('charset');
1347
  return $headers;
1348
  }
1349
 
includes/functions.php CHANGED
@@ -118,7 +118,7 @@ if( !function_exists('_get_post_time') ) {
118
  return $date;
119
  }
120
 
121
- if ( $post_type == 'any' ) {
122
  $post_types = get_post_types( array( 'public' => true ) );
123
  array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) );
124
  $post_types = "'" . implode( "', '", $post_types ) . "'";
118
  return $date;
119
  }
120
 
121
+ if ( $post_type === 'any' ) {
122
  $post_types = get_post_types( array( 'public' => true ) );
123
  array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) );
124
  $post_types = "'" . implode( "', '", $post_types ) . "'";
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravan
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.9
7
- Stable tag: 4.9.2
8
 
9
  XML and Google News Sitemaps to feed the hungry spiders. Multisite, WP Super Cache, Polylang and WPML compatible.
10
 
@@ -271,15 +271,23 @@ Yes. In fact, it has been designed for it. Tested on WPMU 2.9.2 and WPMS 3+ both
271
 
272
  == Upgrade Notice ==
273
 
274
- = 4.9.2 =
275
- Bugfix release.
276
 
277
 
278
  == Changelog ==
279
 
 
 
 
 
 
 
 
 
 
280
  = 4.9.2 =
281
  * FactCheck genre causes error in Search Console
282
- * HTTPS schema URLs
283
 
284
  = 4.9.1 =
285
  * FIX: double genre terms on upgrade from 4.4, thanks @mouhalves
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.9
7
+ Stable tag: 4.9.4
8
 
9
  XML and Google News Sitemaps to feed the hungry spiders. Multisite, WP Super Cache, Polylang and WPML compatible.
10
 
271
 
272
  == Upgrade Notice ==
273
 
274
+ = 4.9.4 =
275
+ Bugfixes: double content type filtering and missing featured images (thanks @flyerua)
276
 
277
 
278
  == Changelog ==
279
 
280
+ = 4.9.4 =
281
+ * FIX: missing featured images, thanks @flyerua
282
+ * FIX: double content type response header filtering
283
+
284
+ = 4.9.3 =
285
+ * Reinstate filter_no_news_limits, allowing post type array
286
+ * Improved language handling and new language filter xmlsf_post_language
287
+ * Force text/xml Content-Type response header
288
+
289
  = 4.9.2 =
290
  * FactCheck genre causes error in Search Console
 
291
 
292
  = 4.9.1 =
293
  * FIX: double genre terms on upgrade from 4.4, thanks @mouhalves
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">tip</a></strong> for continued development and support. Thanks :)
6
  Text Domain: xml-sitemap-feed
7
- Version: 4.9.2
8
  Requires PHP: 5.6
9
  Author: RavanH
10
  Author URI: http://status301.net/
@@ -38,6 +38,9 @@ Author URI: http://status301.net/
38
  * plus the Image title and caption tags
39
  * xmlsf_custom_urls -> Filters the custom urls array
40
  * xmlsf_custom_sitemaps -> Filters the custom sitemaps array
 
 
 
41
  *
42
  * ACTIONS
43
  * xmlsf_news_tags_after -> Fired inside the Google News Sitemap loop at the end of the news
@@ -59,7 +62,7 @@ if ( ! defined( 'WPINC' ) ) die;
59
  * CONSTANTS
60
  * -------------------- */
61
 
62
- define('XMLSF_VERSION', '4.9.2');
63
 
64
  /*
65
  * The following constants can be used to change plugin defaults
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">tip</a></strong> for continued development and support. Thanks :)
6
  Text Domain: xml-sitemap-feed
7
+ Version: 4.9.4
8
  Requires PHP: 5.6
9
  Author: RavanH
10
  Author URI: http://status301.net/
38
  * plus the Image title and caption tags
39
  * xmlsf_custom_urls -> Filters the custom urls array
40
  * xmlsf_custom_sitemaps -> Filters the custom sitemaps array
41
+ * xmlsf_post_language -> Filters the post language tag used in the news sitemap.
42
+ * Passes variable $post_id; must return a 2 or 3 letter
43
+ * language ISO 639 code with the exception of zh-cn and zh-tw.
44
  *
45
  * ACTIONS
46
  * xmlsf_news_tags_after -> Fired inside the Google News Sitemap loop at the end of the news
62
  * CONSTANTS
63
  * -------------------- */
64
 
65
+ define('XMLSF_VERSION', '4.9.4');
66
 
67
  /*
68
  * The following constants can be used to change plugin defaults