Search code examples
xmlwordpressimporthttp-authentication

Wordpress XML Media Import with HTTP Authentication


I'm trying to use the wordpress-importer plugin to import an xml file exported from another wordpress blog which happens to have HTTP authentication on it.

As is, when I run the import, media files are failing with:

Failed to import Media “Image replace”: Remote server returned error response 401 Unauthorized

If I do a find and replace in the XML file on the URI to be

username:password@blogtoimportfrom.com

I get

Failed to import Media “Image replace”: Remote server did not respond

Should I be more selective with my find / replace? Or is there some other way to provide the Auth credentials?

TIA, Billy


Solution

  • I was able to get this to work. I did a find and replace on all occurrences of the URI with the username / password version.

    I then had to modify one line of Wordpress code. In

    wp-includes/http.php
    

    I changed this method:

    function wp_safe_remote_request( $url, $args = array() ) {
            $args['reject_unsafe_urls'] = true;
            $http = _wp_http_get_object();
            return $http->request( $url, $args );
    }
    

    to read

    function wp_safe_remote_request( $url, $args = array() ) {
            $args['reject_unsafe_urls'] = false;   // <------- just this line
            $http = _wp_http_get_object();
            return $http->request( $url, $args );
    }