wc_update_210_file_paths

The WooCommerce wc update 210 file paths function.

Description

wc_update_210_file_paths(); 

Usage

  1. if ( !function_exists( 'wc_update_210_file_paths' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-update-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wc_update_210_file_paths(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-update-functions.php  
  1. function wc_update_210_file_paths() { 
  2. global $wpdb; 
  3.  
  4. // Upgrade file paths to support multiple file paths + names etc 
  5. $existing_file_paths = $wpdb->get_results( "SELECT meta_value, meta_id FROM {$wpdb->postmeta} WHERE meta_key = '_file_paths' AND meta_value != '';" ); 
  6.  
  7. if ( $existing_file_paths ) { 
  8.  
  9. foreach ( $existing_file_paths as $existing_file_path ) { 
  10.  
  11. $needs_update = false; 
  12. $new_value = array(); 
  13. $value = maybe_unserialize( trim( $existing_file_path->meta_value ) ); 
  14.  
  15. if ( $value ) { 
  16. foreach ( $value as $key => $file ) { 
  17. if ( ! is_array( $file ) ) { 
  18. $needs_update = true; 
  19. $new_value[ $key ] = array( 
  20. 'file' => $file,  
  21. 'name' => wc_get_filename_from_url( $file ),  
  22. ); 
  23. } else { 
  24. $new_value[ $key ] = $file; 
  25. if ( $needs_update ) { 
  26. $new_value = serialize( $new_value ); 
  27.  
  28. $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_key = %s, meta_value = %s WHERE meta_id = %d", '_downloadable_files', $new_value, $existing_file_path->meta_id ) );