WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Thorsten Ott
    Member
    Posted 5 months 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'] );

    with

    // 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.

    https://wordpress.org/plugins/wordpress-importer/

  2. Ronald Huereca
    Member
    Posted 5 months 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
    Member
    Posted 4 months ago #

    Hi,
    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?

    Thanks

  4. gresakg
    Member
    Posted 4 months ago #

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

  5. Kurt Payne
    Member
    Posted 1 month ago #

    +1

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.