Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter wpseo_sitemaps_providers never executed #7561

Closed
edwinsiebel opened this issue Jul 30, 2017 · 6 comments
Closed

Filter wpseo_sitemaps_providers never executed #7561

edwinsiebel opened this issue Jul 30, 2017 · 6 comments
Milestone

Comments

@edwinsiebel
Copy link

Please give us a description of what happened.

I am trying to add a new sitemap provider through the wpseo_sitemaps_providers filter in class-sitemaps.php. However, for some reason, the filter is never executed and thus never altered.

Please describe what you expected to happen and why.

I've added the filter:

add_filter('wpseo_sitemaps_providers', function($providers) {
	$providers[] = new \Acme\Sitemap\CustomSitemapProvider();

	return $providers;
});

to my functions.php of my active theme, however, nothing is added to the $this-providers list of the WPSEO_Sitemaps class.
I know it has nothing to do with the filter, but I have implemented the \WPSEO_Sitemap_Provider interface for my CustomSitemapProvider class.

How can we reproduce this behavior?

  1. Enable WordPress SEO 5.1
  2. Add above custom filter in functions.php of my theme.

Technical info

  • WordPress version: 4.8
  • Yoast SEO version: 5.1
  • Relevant plugins in case of a bug: wordpress-seo
@stodorovic
Copy link
Contributor

Filter wpseo_sitemaps_providers is triggering in action plugins_loaded, so it's before executing functions.php. You can look:

https://github.com/Yoast/wordpress-seo/blob/trunk/wp-seo-main.php#L366
https://github.com/Yoast/wordpress-seo/blob/trunk/wp-seo-main.php#L271-L272

So, this filter can't be triggered by code in the theme. It's possible to move initialization of providers later. It could be solution.

@edwinsiebel
Copy link
Author

Hi stodorovic,

Your comment makes sense why I couldn't load it from the theme.
But that is very inconvenient as you have to create a plugin to add a provider.
Can you explain what you mean with 'move initialization of providers later'. I am interested in that solution.

@stodorovic
Copy link
Contributor

Hi @edwinsiebel

I just created PR #7574, so you can see what I mean. There are some errors (some tests are failed on older PHP versions), I'm not sure why, but I'll check it.

@andizer andizer self-assigned this Aug 2, 2017
@andizer andizer removed the acceptance label Aug 2, 2017
@andizer andizer added this to the 5.3 milestone Aug 2, 2017
@andizer andizer removed their assignment Aug 2, 2017
@thulshof
Copy link
Contributor

thulshof commented Aug 3, 2017

@stodorovic Thanks for writing this code! We've reviewed and tested your PR and merged it.
@edwinsiebel This change will be added to Yoast SEO and Yoast SEO Premium 5.3, which will is scheduled for next month.

@edwinsiebel
Copy link
Author

Hi @thulshof,

Thanks for integrating this feature. Will this be the new and recommended way to include external sitemaps to the main sitemap index?

@thulshof
Copy link
Contributor

thulshof commented Aug 3, 2017

@edwinsiebel You're welcome! Yes, this will be the new way to include external sitemaps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants