wooccm_front_enduploadsave

The WooCommerce Checkout Manager wooccm front enduploadsave function.

Description

wooccm_front_enduploadsave(); 

Usage

  1. if ( !function_exists( 'wooccm_front_enduploadsave' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-checkout-manager/includes/classes/main.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wooccm_front_enduploadsave(); 
  7.  

Defined (1)

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

/includes/classes/main.php  
  1. function wooccm_front_enduploadsave() { 
  2. global $wpdb, $woocommerce, $post;  
  3.  
  4. require_once( ABSPATH . 'wp-admin/includes/file.php' );  
  5. require_once( ABSPATH . 'wp-admin/includes/media.php' ); 
  6.  
  7. $name = $_REQUEST["name"]; 
  8. $attachtoremove = $_REQUEST["remove"]; 
  9. $upload_overrides = array( 'test_form' => false ); 
  10.  
  11. wp_delete_attachment( $attachtoremove ); 
  12.  
  13. $file = array( 
  14. 'name' => $_FILES[''.$name.'']['name'],  
  15. 'type' => $_FILES[''.$name.'']['type'],  
  16. 'tmp_name' => $_FILES[''.$name.'']['tmp_name'],  
  17. error => $_FILES[''.$name.''][error],  
  18. 'size' => $_FILES[''.$name.'']['size'] 
  19. ); 
  20. $movefile = wp_handle_upload($file, $upload_overrides); 
  21.  
  22. $attachment = array( 
  23. 'guid' => $movefile['url'],  
  24. 'post_mime_type' => $movefile['type'],  
  25. 'post_title' => preg_replace( '/\.[^.]+$/', '', basename($movefile['file'])),  
  26. 'post_content' => '',  
  27. 'post_status' => 'inherit' 
  28. ); 
  29.  
  30. $attach_id = wp_insert_attachment( $attachment, $movefile['url'] ); 
  31. echo json_encode($attach_id); 
  32. die();