Code Duplication    Length = 33-34 lines in 2 locations

includes/api/class-wc-rest-products-controller.php 1 location

@@ 799-832 (lines=34) @@
796
	 * @param array $downloads
797
	 * @param int $variation_id
798
	 */
799
	private function save_downloadable_files( $product, $downloads, $variation_id = 0 ) {
800
		$files = array();
801
802
		// File paths will be stored in an array keyed off md5(file path).
803
		foreach ( $downloads as $key => $file ) {
804
			if ( isset( $file['url'] ) ) {
805
				$file['file'] = $file['url'];
806
			}
807
808
			if ( ! isset( $file['file'] ) ) {
809
				continue;
810
			}
811
812
			$file_name = isset( $file['name'] ) ? wc_clean( $file['name'] ) : '';
813
814
			if ( 0 === strpos( $file['file'], 'http' ) ) {
815
				$file_url = esc_url_raw( $file['file'] );
816
			} else {
817
				$file_url = wc_clean( $file['file'] );
818
			}
819
820
			$files[ md5( $file_url ) ] = array(
821
				'name' => $file_name,
822
				'file' => $file_url,
823
			);
824
		}
825
826
		// Grant permission to any newly added files on any existing orders for this product prior to saving.
827
		do_action( 'woocommerce_process_product_file_download_paths', $product->id, $variation_id, $files );
828
829
		$id = ( 0 === $variation_id ) ? $product->id : $variation_id;
830
831
		update_post_meta( $id, '_downloadable_files', $files );
832
	}
833
834
	/**
835
	 * Save taxonomy terms.

includes/cli/class-wc-cli-product.php 1 location

@@ 1939-1971 (lines=33) @@
1936
	 * @param array $downloads
1937
	 * @param int $variation_id
1938
	 */
1939
	private function save_downloadable_files( $product_id, $downloads, $variation_id = 0 ) {
1940
		$files = array();
1941
1942
		// File paths will be stored in an array keyed off md5(file path)
1943
		foreach ( $downloads as $key => $file ) {
1944
			if ( isset( $file['url'] ) ) {
1945
				$file['file'] = $file['url'];
1946
			}
1947
1948
			if ( ! isset( $file['file'] ) ) {
1949
				continue;
1950
			}
1951
1952
			$file_name = isset( $file['name'] ) ? wc_clean( $file['name'] ) : '';
1953
1954
			if ( 0 === strpos( $file['file'], 'http' ) ) {
1955
				$file_url = esc_url_raw( $file['file'] );
1956
			} else {
1957
				$file_url = wc_clean( $file['file'] );
1958
			}
1959
1960
			$files[ md5( $file_url ) ] = array(
1961
				'name' => $file_name,
1962
				'file' => $file_url
1963
			);
1964
		}
1965
1966
		// Grant permission to any newly added files on any existing orders for this product prior to saving
1967
		do_action( 'woocommerce_process_product_file_download_paths', $product_id, $variation_id, $files );
1968
1969
		$id = ( 0 === $variation_id ) ? $product_id : $variation_id;
1970
		update_post_meta( $id, '_downloadable_files', $files );
1971
	}
1972
1973
	/**
1974
	 * Get attribute taxonomy by slug.