wc_update_200_file_paths

The WooCommerce wc update 200 file paths function.

Description

wc_update_200_file_paths(); 

Usage

  1. if ( !function_exists( 'wc_update_200_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_200_file_paths(); 
  7.  

Defined (1)

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

/includes/wc-update-functions.php  
  1. function wc_update_200_file_paths() { 
  2. global $wpdb; 
  3.  
  4. // Upgrade old style files paths to support multiple file paths 
  5. $existing_file_paths = $wpdb->get_results( "SELECT meta_value, meta_id, post_id FROM {$wpdb->postmeta} WHERE meta_key = '_file_path' AND meta_value != '';" ); 
  6.  
  7. if ( $existing_file_paths ) { 
  8.  
  9. foreach ( $existing_file_paths as $existing_file_path ) { 
  10.  
  11. $old_file_path = trim( $existing_file_path->meta_value ); 
  12.  
  13. if ( ! empty( $old_file_path ) ) { 
  14. $file_paths = serialize( array( md5( $old_file_path ) => $old_file_path ) ); 
  15.  
  16. $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_key = '_file_paths', meta_value = %s WHERE meta_id = %d", $file_paths, $existing_file_path->meta_id ) ); 
  17.  
  18. $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}woocommerce_downloadable_product_permissions SET download_id = %s WHERE product_id = %d", md5( $old_file_path ), $existing_file_path->post_id ) ); 
  19.