RavanH / xml-sitemap-feed

XML Sitemap & Google News feeds
GNU General Public License v2.0
16 stars 21 forks source link

Function xmlsf_nginx_helper_purge_urls returns wrong URLs #43

Closed janvitos closed 1 year ago

janvitos commented 1 year ago

Hi,

I'm using the xmlsf_nginx_helper_purge_urls function to get the sitemap URLs and purge them through CloudFlare. Today, I discovered that some of the URLs returned by the function are wrong.

Here's what the function returns for my website:

[0] => https://www.example.com/sitemap-news.xml
[1] => https://www.example.com/sitemap.xml
[2] => https://www.example.com/sitemap-root.xml
[3] => https://www.example.com/sitemap-author.xml
[4] => https://www.example.com/sitemap-custom.xml
[5] => https://www.example.com56:25-04:00
[6] => https://www.example.com25:34-04:00
[7] => https://www.example.com12:51-04:00
[8] => https://www.example.com12:15-04:00
[9] => https://www.example.com05:10-04:00
[10] => https://www.example.com30:59-04:00
[11] => https://www.example.com17:46-04:00
[12] => https://www.example.com38:55-05:00
[13] => https://www.example.com02:14-05:00
[14] => https://www.example.com32:32-04:00
[15] => https://www.example.com/sitemap-taxonomy-category.xml

Here's what it should return:

[0] => https://www.example.com/sitemap-news.xml
[1] => https://www.example.com/sitemap.xml
[2] => https://www.example.com/sitemap-root.xml
[3] => https://www.example.com/sitemap-author.xml
[4] => https://www.example.com/sitemap-custom.xml
[5] => https://www.example.com/sitemap-posttype-post.2023.xml
[6] => https://www.example.com/sitemap-posttype-post.2022.xml
[7] => https://www.example.com/sitemap-posttype-post.2021.xml
[8] => https://www.example.com/sitemap-posttype-post.2020.xml
[9] => https://www.example.com/sitemap-posttype-post.2019.xml
[10] => https://www.example.com/sitemap-posttype-post.2018.xml
[11] => https://www.example.com/sitemap-posttype-post.2017.xml
[12] => https://www.example.com/sitemap-posttype-post.2016.xml
[13] => https://www.example.com/sitemap-posttype-post.2015.xml
[14] => https://www.example.com/sitemap-posttype-page.xml
[15] => https://www.example.com/sitemap-taxonomy-category.xml

As you can see, it seems like all of the public post types sitemaps URLs returned are wrong. It's also missing sitemap-posttype-page.xml.

I can help troubleshoot the issue if you want.

Thanks!

janvitos commented 1 year ago

Found it!

In file functions.shared.php, line 173:

foreach ( xmlsf_get_index_archive_data( $post_type, $archive ) as $url ) {

Replace with:

foreach ( xmlsf_get_index_archive_data( $post_type, $archive ) as $url => $value ) {

With that change, this is the output I'm getting:

[0] => https://www.example.com/sitemap-news.xml
[1] => https://www.example.com/sitemap.xml
[2] => https://www.example.com/sitemap-root.xml
[3] => https://www.example.com/sitemap-author.xml
[4] => https://www.example.com/sitemap-custom.xml
[5] => https://www.example.com/sitemap-posttype-post.2023.xml
[6] => https://www.example.com/sitemap-posttype-post.2022.xml
[7] => https://www.example.com/sitemap-posttype-post.2021.xml
[8] => https://www.example.com/sitemap-posttype-post.2020.xml
[9] => https://www.example.com/sitemap-posttype-post.2019.xml
[10] => https://www.example.com/sitemap-posttype-post.2018.xml
[11] => https://www.example.com/sitemap-posttype-post.2017.xml
[12] => https://www.example.com/sitemap-posttype-post.2016.xml
[13] => https://www.example.com/sitemap-posttype-post.2015.xml
[14] => https://www.example.com/sitemap-posttype-page.xml
[15] => https://www.example.com/sitemap-posttype-saswp.2020.xml
[16] => https://www.example.com/sitemap-posttype-saswp.2019.xml
[17] => https://www.example.com/sitemap-taxonomy-category.xml

Cheers!

RavanH commented 1 year ago

Hi @janvitos, the bug has already been fixed in the development version (5.4-beta9 on the main branch) so it will be coming with the major release. Still, great spot :) and thank you for your contribution!

janvitos commented 1 year ago

Awesome!