Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to prevent remote fetches #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/wordpress-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'<br />\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'] )
Expand Down