• 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();
    }
Viewing 15 replies - 1 through 15 (of 18 total)
  • 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

    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…

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

    Lee Willis

    (@leewillis77)

    Hey arnee – just saw the latest update, and I’m now do_action(‘sm_rebuild’)-ing quite happily – thanks!

    Arne

    (@arnee)

    You’re welcome ?? Let me know if you have any other ideas or suggestions.

    Hey Arnee,

    Some users are having problems – I’m hooking into sm_buildmap, and my plugins is then (basically) doing:

    `$generatorObject = &GoogleSitemapGenerator::GetInstance();
    if($generatorObject!=null) {
    $generatorObject->AddUrl($prod_url, $product->dt, “weekly”, 0.25);
    }

    The code is getting inside the “if” so we’ve got the instance, but the URLs aren’t being added to the sitemap – any ideas why not?

    Just a bit of an update. I’ve got access to 2 blogs – one with this problem, and another where things work fine. After various bits of debugging I’ve found the following:

    On the site that works then the object returned by GoogleSitemapGenerator::GetInstance() is “fully populated”, e.g. has options etc. loaded

    On the site that doesn’t work, then the object returned looks like this:

    googlesitemapgenerator Object
    (
        [_svnVersion] => $Id: sitemap-core.php 175664 2009-11-20 21:21:09Z arnee $
        [_options] => Array
            (
            )
    
        [_pages] => Array
            (
            )
    
        [_freqNames] => Array
            (
            )
    
        [_prioProviders] => Array
            (
            )
    
        [_initiated] =>
        [_lastError] =>
        [_lastPostID] => 0
        [_isActive] =>
        [_isScheduled] =>
        [_fileHandle] =>
        [_fileZipHandle] =>
        [_ui] =>
    )

    IE although it’s an object of the right class – it doesn’t appear to have been initialised properly.

    I have access to working and non-working blogs and am happy to add debug code if you tell me what & where ??

    Hi,

    could you check which PHP version is installed on the not working one?

    Thanks,

    Arne

    It never occurred to me to check that …

    WordPress 2.8.5 with DB 11548 on PHP 4.4.9
    Plugin version: 3.2 ($Id: sitemap-core.php 175664 2009-11-20 21:21:09Z arnee $)

    Is that the problem then?

    Mhh, maybe its related with the references, since PHP4 returns a copy of the object by default (instead of a reference, as in PHP5). I will have a look ??

    Can you try to search for “GoogleSitemapGenerator::GetInstance()” in the sitemap.php and replace it with “&GoogleSitemapGenerator::GetInstance()”? Should be there 7 times.

    Hmm – still no products in the sitemap, and the generator now looks like this:

    googlesitemapgenerator Object
    (
        [_svnVersion] => $Id: sitemap-core.php 175664 2009-11-20 21:21:09Z arnee $
        [_options] => Array
            (
            )
    
        [_pages] => Array
            (
            )
    
        [_freqNames] => Array
            (
            )
    
        [_prioProviders] => Array
            (
            )
    
        [_initiated] =>
        [_lastError] =>
        [_lastPostID] => 0
        [_isActive] =>
        [_isScheduled] =>
        [_fileHandle] =>
        [_fileZipHandle] =>
        [_ui] => googlesitemapgeneratorui Object
            (
                [sg] => googlesitemapgenerator Object
                    (
                        [_svnVersion] => $Id: sitemap-core.php 175664 2009-11-20
    21:21:09Z arnee $
                        [_options] => Array
                            (
                            )
    
                        [_pages] => Array
                            (
                            )
    
                        [_freqNames] => Array
                            (
                            )
    
                        [_prioProviders] => Array
                            (
                            )
    
                        [_initiated] =>
                        [_lastError] =>
                        [_lastPostID] => 0
                        [_isActive] =>
                        [_isScheduled] =>
                        [_fileHandle] =>
                        [_fileZipHandle] =>
                        [_ui] =>
                    )
    
                [mode] => 27
            )
    
    )

    Interesting. So its definitely a reference php4 problem. I’m not at my pc anymore, but I guess at some point the sitemap generator object is not passed by reference.

    Can you try to add a & to the constructor argument of the UI class? The generator object should be passed there.

    I changed this:
    function GoogleSitemapGeneratorUI($sitemapBuilder) {
    to this:
    function GoogleSitemapGeneratorUI(&$sitemapBuilder) {

    Was that what you meant? If so, still no joy. If you want to email me and maybe we can swap MSN/GoogleTalk/Wave details to try and work through it?

    I can probably let you have the login to an affected site as well if that’s useful?

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘[Plugin: Google XML Sitemaps] Rebuilding sitemap via another plugin’ is closed to new replies.