Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:[email protected]

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

like image 702
Billy Avatar asked Nov 26 '25 20:11

Billy


1 Answers

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 );
}
like image 197
Billy Avatar answered Nov 28 '25 13:11

Billy