以下是我找到的解决方案:在wordpress导入器插件函数process\\u帖子中:
// try to use _wp_attached file for upload folder placement to ensure the same location as the export site
// e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
$postdata[\'upload_date\'] = $post[\'post_date\'];
if ( isset( $post[\'postmeta\'] ) ) {
foreach( $post[\'postmeta\'] as $meta ) {
if ( $meta[\'key\'] == \'_wp_attached_file\' ) {
if ( preg_match( \'%^[0-9]{4}/[0-9]{2}%\', $meta[\'value\'], $matches) )
{
$postdata[\'upload_date\'] = $matches[0];
$postdata[\'woocommerce\'] = false;
}
else if ( preg_match( \'%^(woocommerce_uploads)/([0-9]{4}/[0-9]{2})%\', $meta[\'value\'], $matches ) ) {
$postdata[\'upload_date\'] = $matches[2];
$postdata[\'woocommerce\'] = true;
}
break;
}
}
}
(这是wordpress尝试使用目录名称获取上载日期的部分-使用woocommerce\\u uploads结构将失败)
在wordpress导入器插件函数fetch\\u remote\\u文件中:
function fetch_remote_file( $url, $post ) {
// extract the file name and extension from the url
$file_name = basename( $url );
global $wp_filter;
if ( isset($wp_filter[\'pre_option_upload_path\']) ) {
remove_filter( \'pre_option_upload_path\', \'woocommerce_path_upload\' );
}
if ( $post[\'woocommerce\'] == true ) {
add_filter( \'pre_option_upload_path\', \'woocommerce_path_upload\' );
}
$upload = wp_upload_bits( $file_name, 0, \'\', $post[\'upload_date\'] );
(这是上传文件之前的部分,如果是woocommerce文件,我们会在上传路径之前添加一个路径)
function woocommerce_path_upload () { return \'wp-content/uploads/woocommerce_uploads\'; }
(函数在过滤器中使用以更正路径)
最后,在wordpress核心中,wp包括/功能。php将$refresh\\u cache设置为true(默认值为false):
function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = true ) {
(如果你不修改wordpress,请将上传路径保存在缓存中,并且在我们的情况下不检查每个文件,我们需要每次都检查它)
请注意,这是您仅在迁移期间进行的修改,之后将其反转