Is it possible to trigger the sitemap to be rebuild via another plugin?
My own plugin creates some custom pages that are outside of the main WordPress table structure. I have successfully hooking into XML Google Sitemaps to add these pages to the xml sitemap that is outputted.
Is there a way for me to trigger the sitemap to be rebuilt automatically when content has been changed in my plugin? I haven't tested this but I'm guessing something like this should work but just want to check this is the best way?
if ( class_exists('GoogleSitemapGenerator') ) {
$gs = GoogleSitemapGenerator::GetInstance();
$gs->BuildSitemap();
}
Hi,
uuhm unfortunately that won't work anymore since the GoogleSitemapGenerator class is "lazy loaded" by the GoogleSitemapGeneratorLoader class to avoid loading the whole generator on every page load.
I think the easiest way would be if you just call the "sm_build_cron" hook.
do_action("sm_build_cron");
If the plugin is active, the building will start on this hook. If not, nothing will happen :-)
Best regards,
Arne
leewillis77
Member
Posted 1 month ago #
What about:
` if(GoogleSitemapGeneratorLoader::LoadPlugin()) {
$gs = GoogleSitemapGenerator::GetInstance();
$gs->CheckForAutoBuild();
}
Would that work?
Yes, that works too (at the moment ;-))
However the user will receive a fatal error in case the plugin is not active, sou you would at least have to add a check if the "GoogleSitemapGeneratorLoader" class exists...
leewillis77
Member
Posted 1 month ago #
> at the moment ;-)
Being able to trigger a sitemap rebuild from other plugins is a great feature - whatever you do please make this functionality still be available :)
leewillis77
Member
Posted 5 days ago #
Hey arnee - just saw the latest update, and I'm now do_action('sm_rebuild')-ing quite happily - thanks!
You're welcome :-) Let me know if you have any other ideas or suggestions.