From e352fe485f028a57cc6370c8c1b8656e1736c768 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Sat, 23 Jun 2018 11:57:48 -0700 Subject: [PATCH 1/2] Add ability to prevent remote file fetches This can be useful if the attachments from the source site already exist within the destination site -- say, by way of FTP or rsync -- and you just need the attachment records added to the database. --- src/wordpress-importer.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/wordpress-importer.php b/src/wordpress-importer.php index e52cf9c..69a3a20 100755 --- a/src/wordpress-importer.php +++ b/src/wordpress-importer.php @@ -991,6 +991,28 @@ function fetch_remote_file( $url, $post ) { // extract the file name and extension from the url $file_name = basename( $url ); + // don't fetch files, if requested + $prevent = defined( 'IMPORT_PREVENT_REMOTE_FETCH' ) && IMPORT_PREVENT_REMOTE_FETCH; + if ( apply_filters( 'import_prevent_remote_fetch', $prevent, $url, $post )) { + printf( __( "Skipping fetch of '%s'\n", 'wordpress-importer' ), $url ); + $upload_dir = wp_upload_dir( $post['upload_date'] ); + $attachment_url = sprintf( '%s/%s', $upload_dir['url'], $file_name ); + $attachment_filename = sprintf( '%s/%s', $upload_dir['path'], $file_name ); + $attachment_type = wp_check_filetype( $attachment_filename ); + $upload = array( + 'url' => $attachment_url, + 'file' => $attachment_filename, + 'type' => $attachment_type['type'], + 'error' => false, + ); + + // keep track of the old and new urls so we can substitute them later + $this->url_remap[$url] = $upload['url']; + $this->url_remap[$post['guid']] = $upload['url']; // r13735, really needed? + + return $upload; + } + // get placeholder file in the upload dir with a unique, sanitized filename $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] ); if ( $upload['error'] ) From f0a62211cffb16ad53494c9ea9e832d446e321cf Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Sat, 23 Jun 2018 13:10:35 -0700 Subject: [PATCH 2/2] Add `
` after notice of skipping fetch --- src/wordpress-importer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wordpress-importer.php b/src/wordpress-importer.php index 69a3a20..73e908c 100755 --- a/src/wordpress-importer.php +++ b/src/wordpress-importer.php @@ -994,7 +994,7 @@ function fetch_remote_file( $url, $post ) { // don't fetch files, if requested $prevent = defined( 'IMPORT_PREVENT_REMOTE_FETCH' ) && IMPORT_PREVENT_REMOTE_FETCH; if ( apply_filters( 'import_prevent_remote_fetch', $prevent, $url, $post )) { - printf( __( "Skipping fetch of '%s'\n", 'wordpress-importer' ), $url ); + printf( __( "Skipping fetch of '%s'
\n", 'wordpress-importer' ), $url ); $upload_dir = wp_upload_dir( $post['upload_date'] ); $attachment_url = sprintf( '%s/%s', $upload_dir['url'], $file_name ); $attachment_filename = sprintf( '%s/%s', $upload_dir['path'], $file_name );