Support » Plugin: Google XML Sitemaps » [Plugin: Google XML Sitemaps] Generating sitemap from cli without wget/curl

  • There are reasons for not using an url to generate the sitemap.

    If you need to use it as a plain CLI call, you will need to use this:

        chdir(dirname(__FILE__)); // Change current call to the main folder
        define('DOING_AJAX', true);
        define('WP_USE_THEMES', false);
        $_SERVER = array(
            "HTTP_HOST" => "",
            "SERVER_NAME" => "",
            "REQUEST_URI" => "/",
            "REQUEST_METHOD" => "GET",
            'SCRIPT_FILENAME' => __FILE__,
            'SCRIPT_NAME' => array_pop( explode(DIRECTORY_SEPARATOR, __FILE__))

    Additionally, you will need to change GetHomePath() for the checks on the root of the wordpress to be detected correctly (or more correctly, i don’t think my hack is the most perfect one, but it works on our environment):

    if ( $home != '' && $home != get_option( 'url' ) ) {
      $home_path = parse_url( $home );
      if (isset($home_path['path'])) {
        $home_path = $home_path['path'];
      } else {
        $home_path = "";
        $root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] );
      } else {
        $root = str_replace( $_SERVER["SCRIPT_NAME"], '', $_SERVER["SCRIPT_FILENAME"] );

    Can we get this home / root of WP function fixed so that we don’t need hacks to be able to use it from CLI?

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]

  • The topic ‘[Plugin: Google XML Sitemaps] Generating sitemap from cli without wget/curl’ is closed to new replies.