Code Duplication    Length = 11-11 lines in 2 locations

includes/wc-rest-functions.php 1 location

@@ 74-84 (lines=11) @@
71
	}
72
73
	// Ensure we have a file name and type.
74
	if ( ! $wp_filetype['type'] ) {
75
		$headers = wp_remote_retrieve_headers( $response );
76
		if ( isset( $headers['content-disposition'] ) && strstr( $headers['content-disposition'], 'filename=' ) ) {
77
			$disposition = end( explode( 'filename=', $headers['content-disposition'] ) );
78
			$disposition = sanitize_file_name( $disposition );
79
			$file_name   = $disposition;
80
		} elseif ( isset( $headers['content-type'] ) && strstr( $headers['content-type'], 'image/' ) ) {
81
			$file_name = 'image.' . str_replace( 'image/', '', $headers['content-type'] );
82
		}
83
		unset( $headers );
84
	}
85
86
	// Upload the file.
87
	$upload = wp_upload_bits( $file_name, '', wp_remote_retrieve_body( $response ) );

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

@@ 2024-2034 (lines=11) @@
2021
		}
2022
2023
		// Ensure we have a file name and type
2024
		if ( ! $wp_filetype['type'] ) {
2025
			$headers = wp_remote_retrieve_headers( $response );
2026
			if ( isset( $headers['content-disposition'] ) && strstr( $headers['content-disposition'], 'filename=' ) ) {
2027
				$disposition = end( explode( 'filename=', $headers['content-disposition'] ) );
2028
				$disposition = sanitize_file_name( $disposition );
2029
				$file_name   = $disposition;
2030
			} elseif ( isset( $headers['content-type'] ) && strstr( $headers['content-type'], 'image/' ) ) {
2031
				$file_name = 'image.' . str_replace( 'image/', '', $headers['content-type'] );
2032
			}
2033
			unset( $headers );
2034
		}
2035
2036
		// Upload the file.
2037
		$upload = wp_upload_bits( $file_name, '', wp_remote_retrieve_body( $response ) );