我试图使用wordpress-importer插件导入从另一个wordpress博客导出的xml文件,该博客恰好有HTTP身份验证。
按原样,当我运行导入时,媒体文件失败了:
Failed to import Media “Image replace”: Remote server returned error response 401 Unauthorized
如果我在URI上的XML文件中查找和替换
username:password@blogtoimportfrom.com
我得到了
Failed to import Media “Image replace”: Remote server did not respond
我的发现/替换应该更有选择性吗?或者是否有其他方式提供Auth凭证?
TIA, 比利
答案 0 :(得分:4)
我能够让它发挥作用。我使用用户名/密码版本查找并替换所有出现的URI。
然后我不得不修改一行Wordpress代码。在
wp-includes/http.php
我改变了这个方法:
function wp_safe_remote_request( $url, $args = array() ) {
$args['reject_unsafe_urls'] = true;
$http = _wp_http_get_object();
return $http->request( $url, $args );
}
阅读
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 );
}
答案 1 :(得分:0)
我必须使用标头进行身份验证,因为wp破坏了网址中的身份验证。
在wordpress-importer.php中...
$args_ = array(
'timeout' => 300,
'stream' => true,
'filename' => $upload['file'],
'headers' => array('Authorization' => 'Basic ' . base64_encode( 'user:pass'))
);
$remote_response = wp_safe_remote_get( $url, $args_);