| @@ 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. |
|
| @@ 836-869 (lines=34) @@ | ||
| 833 | * @param array $downloads |
|
| 834 | * @param int $variation_id |
|
| 835 | */ |
|
| 836 | private function save_downloadable_files( $product, $downloads, $variation_id = 0 ) { |
|
| 837 | $files = array(); |
|
| 838 | ||
| 839 | // File paths will be stored in an array keyed off md5(file path). |
|
| 840 | foreach ( $downloads as $key => $file ) { |
|
| 841 | if ( isset( $file['url'] ) ) { |
|
| 842 | $file['file'] = $file['url']; |
|
| 843 | } |
|
| 844 | ||
| 845 | if ( ! isset( $file['file'] ) ) { |
|
| 846 | continue; |
|
| 847 | } |
|
| 848 | ||
| 849 | $file_name = isset( $file['name'] ) ? wc_clean( $file['name'] ) : ''; |
|
| 850 | ||
| 851 | if ( 0 === strpos( $file['file'], 'http' ) ) { |
|
| 852 | $file_url = esc_url_raw( $file['file'] ); |
|
| 853 | } else { |
|
| 854 | $file_url = wc_clean( $file['file'] ); |
|
| 855 | } |
|
| 856 | ||
| 857 | $files[ md5( $file_url ) ] = array( |
|
| 858 | 'name' => $file_name, |
|
| 859 | 'file' => $file_url, |
|
| 860 | ); |
|
| 861 | } |
|
| 862 | ||
| 863 | // Grant permission to any newly added files on any existing orders for this product prior to saving. |
|
| 864 | do_action( 'woocommerce_process_product_file_download_paths', $product->id, $variation_id, $files ); |
|
| 865 | ||
| 866 | $id = ( 0 === $variation_id ) ? $product->id : $variation_id; |
|
| 867 | ||
| 868 | update_post_meta( $id, '_downloadable_files', $files ); |
|
| 869 | } |
|
| 870 | ||
| 871 | /** |
|
| 872 | * Save taxonomy terms. |
|