Forums

[Plugin: Google XML Sitemaps] Rebuilding sitemap via another plugin (7 posts)

  1. husobj
    Member
    Posted 1 month ago #

    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();
    }
  2. arnee
    Member
    Posted 1 month ago #

    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

  3. leewillis77
    Member
    Posted 1 month ago #

    What about:

    ` if(GoogleSitemapGeneratorLoader::LoadPlugin()) {
    $gs = GoogleSitemapGenerator::GetInstance();
    $gs->CheckForAutoBuild();
    }

    Would that work?

  4. arnee
    Member
    Posted 1 month ago #

    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...

  5. 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 :)

  6. 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!

  7. arnee
    Member
    Posted 4 days ago #

    You're welcome :-) Let me know if you have any other ideas or suggestions.

Reply

You must log in to post.

About this Topic