From 179ae77ca0aa093a8d9f3c39941875c16db6060a Mon Sep 17 00:00:00 2001 From: Michael Bissett Date: Mon, 20 Jul 2020 12:54:36 -0500 Subject: [PATCH] Ensure images/files are only downloaded when they're set to be imported https://github.com/soflyy/wp-all-import-rapid-addon/issues/34 --- rapid-addon.php | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/rapid-addon.php b/rapid-addon.php index dd782b1..f62fccd 100644 --- a/rapid-addon.php +++ b/rapid-addon.php @@ -323,6 +323,9 @@ function import($importData, $parsedData) { $import_options = $importData['import']['options'][$this->slug]; + // Contains all of the import options, not just add-on specific ones + $all_import_options = $importData['import']; + // echo "
";
 	//		print_r($import_options);
 	//		echo "
"; @@ -340,36 +343,44 @@ function import($importData, $parsedData) { switch ($field_params['type']) { case 'image': + + if ( $this->can_update_meta( $field_params['slug'], $all_import_options ) ) { - // import the specified image, then set the value of the field to the image ID in the media library + // import the specified image, then set the value of the field to the image ID in the media library - $image_url_or_path = $parsedData[$field_slug][$index]; + $image_url_or_path = $parsedData[$field_slug][$index]; - $download = $import_options['download_image'][$field_slug]; + $download = $import_options['download_image'][$field_slug]; - $uploaded_image = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "images", true, $importData['articleData']); + $uploaded_image = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "images", true, $importData['articleData']); - $data[$field_slug] = array( - "attachment_id" => $uploaded_image, - "image_url_or_path" => $image_url_or_path, - "download" => $download - ); + $data[$field_slug] = array( + "attachment_id" => $uploaded_image, + "image_url_or_path" => $image_url_or_path, + "download" => $download + ); + + } break; case 'file': - $image_url_or_path = $parsedData[$field_slug][$index]; + if ( $this->can_update_meta( $field_params['slug'], $all_import_options ) ) { - $download = $import_options['download_image'][$field_slug]; + $image_url_or_path = $parsedData[$field_slug][$index]; - $uploaded_file = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "files", true, $importData['articleData']); + $download = $import_options['download_image'][$field_slug]; - $data[$field_slug] = array( - "attachment_id" => $uploaded_file, - "image_url_or_path" => $image_url_or_path, - "download" => $download - ); + $uploaded_file = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "files", true, $importData['articleData']); + + $data[$field_slug] = array( + "attachment_id" => $uploaded_file, + "image_url_or_path" => $image_url_or_path, + "download" => $download + ); + + } break;