WordPress Importer
Check if attachment files already exists before fetching them remotely. (6 posts)

  1. Thorsten Ott
    Posted 2 years ago #

    I'd like to propose a small addition to fetch_remote_file() that allows a bypass so it will be possible to check for local existence of files instead of importing them via a remote GET request.

    Basically replace

    $headers = wp_get_http( $url, $upload['file'] );


    // fetch the remote url and write it to the placeholder
    		// Sometimes you already have all the files in place, so instead
    		// of downloading them again better see if you can reuse them
    		// put
    		// 		define( 'WP_IMPORTER_CHECK_LOCAL_FILES', true );
    		// in you wp-config.php to do so.
    		$existing_upload = wp_upload_dir( $post['upload_date'] );
    		$existing_upload['file'] = $existing_upload['path'] . "/$file_name";
    		$existing_upload['url'] = $existing_upload['url'] . "/$file_name";
    		if ( defined( 'WP_IMPORTER_CHECK_LOCAL_FILES' ) && true === WP_IMPORTER_CHECK_LOCAL_FILES && file_exists( $existing_upload['file'] ) && filesize( $existing_upload['file'] ) > 0 ) {
    			$headers = array(
    				'response' => 200,
    				'content-length' => filesize( $existing_upload['file'] ),
    				'x-final-location' => $url
    			$upload = $existing_upload;
    		} else {
    			$headers = wp_get_http( $url, $upload['file'] );

    Then define define( 'WP_IMPORTER_CHECK_LOCAL_FILES', true ); in your wp-config.php and existing files would be kept rather than re-fetched.


  2. Ronald Huereca
    Posted 2 years ago #

    +1 for this.

    It's not always possible to retrieve files from a remote location, so manually placing the files and have the importer work with them would be a huge win.

  3. basicint
    Posted 2 years ago #

    I run the command wget to download all media (images) from the remote url. From the remote server I want to export only last month and only posts, but I need to attach in the xml the Featured Image, this mod will work with my scenario? I don't have the option to export "Everything" as the remote server is updated by 100 of posts every day.
    Can you advise?


  4. gresakg
    Posted 2 years ago #

    This is an enhancement that needs to be merged in the official version!

  5. Kurt Payne
    Posted 2 years ago #


  6. Reza
    Posted 1 year ago #


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WordPress Importer
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.