• Resolved pietpompies

    (@pietpompies)


    How can we set the image import to replicate the existing site folder structure onto the destination site?

    We have a physical folder structure like ../siteimages/pages ; ..siteimages/products ; .. siteimages/products/category1 etc. on the source site.

    We DO NOT want all the imported images to just land in define( 'UPLOADS', 'siteimages' ); top folder, but need to match the relative structured that was used on the source.

    How can we set that during import? We can only find docs to support all sorts of ways to source the images, but not how to manipulate the destination.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @pietpompies,

    To set custom upload folders for the images, you’d need to write custom code that uses our ‘wp_all_import_single_image_uploads_dir’ hook. Here is an example snippet that you can modify as per your needs:

    add_filter( 'wp_all_import_single_image_uploads_dir', 'my_test_uploadsdir', 10, 6 );
    
    function my_test_uploadsdir( $uploads, $image, $articleData, $current_xml_node, $import_id, $post_id ) {
    	$img_path_data = parse_url( $image );
    	$img_path = trim( str_replace( basename( $img_path_data['path'] ), '', $img_path_data['path'] ), '/' );
    	
    	$uploads['path'] = preg_replace( '/wp-content.*/', $img_path, $uploads['path'] );
    
    	if ( ! is_dir( $uploads['path'] ) ) {
    		wp_mkdir_p( $uploads['path'] );
    	}
    	
    	return $uploads;
    }
    Thread Starter pietpompies

    (@pietpompies)

    Thanks Guys, that looks like it could work.
    The only thing is, it appears like it is still looking in the /wp-content folder. Is that correct?

    Preferably, it would be better if it was looking at the ‘UPLOADS’ value instead, config – Advance options , as the uploads are not in the WP directory itself.

    Did you perhaps have the correct syntax to use instead of '/wp-content.*/' in order for the function to look at the variable value instead?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Mirror image folder structure to destination site’ is closed to new replies.