我使用wp cli从另一个站点导入媒体。wp import
总是抱怨Failed to import Media xxxx: Request failed due to an error: A valid URL was not provided. (http_request_failed)
没有导入任何内容。
我通过添加define( \'IMPORT_DEBUG\', true );
进入wp-config.php
并将导入调用跟踪到deep。结果如下:
#0 wp_validate_redirect / wp-includes/http.php:620
#1 allowed_http_request_hosts / wp-includes/class-wp-hook.php:294
#2 WP_Hook->apply_filters / wp-includes/plugin.php:212
#3 apply_filters / wp-includes/http.php:581
#4 wp_http_validate_url / wp-includes/class-http.php:270
#5 WP_Http->request / wp-includes/class-http.php:635
#6 WP_Http->get / wp-includes/http.php:68
#7 wp_safe_remote_get / wp-content/plugins/wordpress-importer/class-wp-import.php:1008
#8 WP_Import->fetch_remote_file / wp-content/plugins/wordpress-importer/class-wp-import.php:954
#9 WP_Import->process_attachment / wp-content/plugins/wordpress-importer/class-wp-import.php:697
#10 WP_Import->process_posts / wp-content/plugins/wordpress-importer/class-wp-import.php:88
#11 WP_Import->import / phar:.../Import_Command.php:179
#12 Import_Command->import_wxr / phar:.../Import_Command.php:81
Solution 1
在wp-content/themes/{your-theme}/functions中添加以下行。php:
add_filter("http_request_host_is_external", function($allow, $host, $url){
if (gethostbyname($host) == "your_hostname.com") {
$allow = true;
}
return $allow;
}, 10, 3);
它支持对原始站点的HTTP请求。
Solution 2
管理面板/设置/常规/站点地址(URL)-此处放置原始站点的URL。或使用wp cli:
wp option update home your_hostname.com