• None of the remote images would import – turning on the debug showed that the new server couldn’t access the remote server (when it blatantly could as I could access the same urls on the remote server) which suggested that for some reason the plugin was failing.

    I recoded the fetch_remote file and it now works. I’m not saying this will work for everyone but a lot of people seem to have reported this problem.

    function fetch_remote_file( $url, $post ) {
    		// extract the file name and extension from the url
    		$file_name = basename( $url );
    
    		// fetch the remote url and write it to the placeholder file
    		$returned_data = wp_remote_get( $url );
    		// request failed
    		if ( ! $returned_data ) {
    			return new WP_Error( 'import_file_error', __('Remote server did not respond', 'wordpress-importer') );
    		}
    		// make sure the fetch was successful
    		if ( $returned_data['response']['code'] != '200' ) {
    			return new WP_Error( 'import_file_error', sprintf( __('Remote server returned error response %1$d %2$s', 'wordpress-importer'), esc_html($returned_data['response']), get_status_header_desc($returned_data['response']) ) );
    		}
    		 $upload = wp_upload_bits( $file_name, 0, $returned_data['body'], $post['upload_date'] );
    		 if ( $upload['error'] ) return new WP_Error( 'upload_dir_error', $upload['error'] );
    		$filesize = filesize( $upload['file'] );
    
    		if ( 0 == $filesize ) {
    			@unlink( $upload['file'] );
    			return new WP_Error( 'import_file_error', __('Zero size file downloaded', 'wordpress-importer') );
    		}
    
    		$max_size = (int) $this->max_attachment_size();
    		if ( ! empty( $max_size ) && $filesize > $max_size ) {
    			@unlink( $upload['file'] );
    			return new WP_Error( 'import_file_error', sprintf(__('Remote file is too large, limit is %s', 'wordpress-importer'), size_format($max_size) ) );
    		}
    
    		// 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?
    		// keep track of the destination if the remote url is redirected somewhere else
    		if ( isset($headers['x-final-location']) && $headers['x-final-location'] != $url )
    			$this->url_remap[$headers['x-final-location']] = $upload['url'];
    
    		return $upload;
    	}

    Hope this helps someone

    https://www.ads-software.com/plugins/wordpress-importer/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi

    Nice work.

    If possible please post this on GitHub too, these plugins are on there also.

    HI,,
    Thanks for this. It’s working on my local server fine and I am getting images being imported but it’s not working when I do this on my live site. I am getting the following error.

    Fatal error: Cannot use object of type WP_Error as array in /home/username/public_html/one-click/wp-content/themes/Aspen-Clothing/radium-one-click-demo-install/importer/wordpress-importer.php on line 876

    Anyway to fix this? Thank you very much for your time and support

    Thanks

    +1 for OP Steve’s fix.

    I was going absolutely batty trying do import files on a local instance of a site over to a multisite implementation, but your fix did the trick.

    I’ll want to say that nothing else has worked to resolve this media import problem for me, so you really saved my bacon. ?? So thank you, thank you, thank you!

    WordPress Importer Devs: Please implement this fix, it works!

    Hmmm..didn’t work for me. Too bad. This is a really frustrating problem.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Media images not importing’ is closed to new replies.