WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Ben Huson
    Member
    Posted 4 years 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 4 years 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. Lee Willis
    Member
    Posted 4 years ago #

    What about:

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

    Would that work?

  4. arnee
    Member
    Posted 4 years 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. Lee Willis
    Member
    Posted 4 years 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. Lee Willis
    Member
    Posted 4 years 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 years ago #

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

  8. Lee Willis
    Member
    Posted 4 years ago #

    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?

  9. Lee Willis
    Member
    Posted 4 years ago #

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

  10. arnee
    Member
    Posted 4 years ago #

    Hi,

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

    Thanks,

    Arne

  11. Lee Willis
    Member
    Posted 4 years ago #

    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?

  12. arnee
    Member
    Posted 4 years ago #

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

  13. arnee
    Member
    Posted 4 years ago #

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

  14. Lee Willis
    Member
    Posted 4 years ago #

    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
            )
    
    )
  15. arnee
    Member
    Posted 4 years ago #

    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.

  16. Lee Willis
    Member
    Posted 4 years ago #

    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?

  17. arnee
    Member
    Posted 4 years ago #

    Hi,

    I found more places without the references. Could you try (in about 15 minutes) the current svn version?

    http://downloads.wordpress.org/plugin/google-sitemap-generator.zip

    That fixed the problems in my tests :)

  18. Lee Willis
    Member
    Posted 4 years ago #

    Thanks Arnee. I've asked the user to give it a test (She'd made the files writeable so I could edit them inline, but I don't have the right permissions to install a whole new version).

    I'll let you know whether it's successful!

  19. Lee Willis
    Member
    Posted 4 years ago #

    Arnee, looks like it's all working fine now (With the dev version) - thanks for all your help!

Topic Closed

This topic has been closed to new replies.

About this Topic