wccs_file_uploader_data_meta_box

The WooCommerce Checkout Manager wccs file uploader data meta box function.

Description

wccs_file_uploader_data_meta_box( $post ); 

Parameters (1)

0. $post
The post.

Usage

  1. if ( !function_exists( 'wccs_file_uploader_data_meta_box' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-checkout-manager/includes/classes/file_upload/main_upload.php'; 
  3.  
  4. // The post. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wccs_file_uploader_data_meta_box($post); 
  9.  

Defined (1)

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

/includes/classes/file_upload/main_upload.php  
  1. function wccs_file_uploader_data_meta_box($post) { 
  2. global $wpdb, $thepostid, $theorder, $woocommerce, $post; 
  3.  
  4. $options = get_option( 'wccs_settings' ); 
  5. $upload_dir = wp_upload_dir(); 
  6. $args = array( 
  7. 'post_type' => 'attachment',  
  8. 'numberposts' => -1,  
  9. 'post_status' => null,  
  10. 'post_parent' => $post->ID 
  11. ); 
  12. ?>  
  13.  
  14. <script type="text/javascript" > 
  15. jQuery(document).ready(function($) { 
  16.  
  17. $('#wccm_save_order_submit').click(function() { 
  18.  
  19. $(".wccm_results").html("Saving, please wait...."); 
  20.  
  21. var data = { 
  22. action: 'update_attachment_wccm',  
  23. post_id : '<?php echo $post->ID; ?>',  
  24. product_image_gallery : $('#product_image_gallery').val(),  
  25. wccm_default_keys_load : $('#wccm_default_keys_load').val() 
  26. }; 
  27.  
  28. // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php 
  29. $.post(ajaxurl, data, function(response) { 
  30.  
  31. $(".wccm_results").html(response); 
  32. }); 
  33. }); });  
  34. </script> 
  35.  
  36. <?php wp_enqueue_style( 'wccm_upload_file_style', plugins_url('/woocommerce-checkout-manager/includes/classes/file_upload/file_editing_table.css') ); ?> 
  37.  
  38. <div class="woocommerce_order_items_wrapper"> 
  39. <table class="woocommerce_order_items back_end"> 
  40. <thead> 
  41. <tr> 
  42. <th style="width:12%;text-align: center;"><?php _e('File Image', 'woocommerce-checkout-manager'); ?></th> 
  43. <th style="width:10%;text-align: center;"><?php _e('Action', 'woocommerce-checkout-manager'); ?></th> 
  44. <th style="width:12%;text-align: center;"><?php _e('Width x Height', 'woocommerce-checkout-manager'); ?></th> 
  45. <th style="width:8%;text-align: center;"><?php _e('Extension', 'woocommerce-checkout-manager'); ?></th> 
  46. <th style="width:15%;text-align: center;"><?php _e('ID #', 'woocommerce-checkout-manager'); ?></th> 
  47. <th style="width:4%"><?php _e('Link', 'woocommerce-checkout-manager'); ?></th> 
  48. <th style="width:30%;text-align: center;"><?php _e('Name', 'woocommerce-checkout-manager'); ?></th> 
  49. </tr> 
  50. </thead> 
  51.  
  52. <tbody class="product_images"> 
  53. <?php 
  54.  
  55.  
  56. $attachment_args = get_posts( $args );  
  57.  
  58. if ($attachment_args) { 
  59. foreach($attachment_args as $attachment) { 
  60. $array[] = $attachment->ID; 
  61.  
  62. $default_wccm_values = implode(', ', $array); 
  63. $product_image_gallery = implode(', ', $array); 
  64.  
  65. if ( empty($product_image_gallery)) { 
  66. $product_image_gallery = ''; 
  67. $attachments = array_filter( explode( ', ', $product_image_gallery ) ); 
  68.  
  69.  
  70. if ( $attachments ) { 
  71. foreach ( $attachments as $attachment_id ) { 
  72.  
  73. $image_attributes = wp_get_attachment_url( $attachment_id ); 
  74. $image_attributes2 = wp_get_attachment_image_src( $attachment_id ); 
  75. $filename = basename($image_attributes); 
  76. $wp_filetype = wp_check_filetype($filename); 
  77.  
  78. $value_declear = array_diff(explode( ', ', $default_wccm_values), explode( ', ', $attachment_id)); 
  79.  
  80. echo '<tr class="image wccm_filesli wccmv_' . esc_attr( $attachment_id ) . '"> 
  81.  
  82. <span style="display:none;"><script type="text/javascript"> 
  83. jQuery(document).ready(function() { 
  84.  
  85. jQuery(".wccmx_' . esc_attr( $attachment_id ) . '").click(function() { 
  86. jQuery(".wccmv_' . esc_attr( $attachment_id ) . '").hide(); 
  87. jQuery("#product_image_gallery").val(jQuery("#product_image_gallery").val().replace("'.esc_attr( $attachment_id ).'", "")); 
  88.  
  89. }); 
  90. }); 
  91. </script> 
  92. </td> 
  93.  
  94. <td> 
  95. '.wp_get_attachment_image( $attachment_id, array(75, 75), true ).' 
  96. </td> 
  97.  
  98. <td> 
  99. <a class="delete tips wccm_delete wccmx_' . esc_attr( $attachment_id ) . '" data-tip="' . __( 'Delete image', 'woocommerce' ) . '">' . __( 'Delete', 'woocommerce' ) . '</a> 
  100. </td> 
  101.  
  102. <td>'; 
  103. if($image_attributes2[1] == '') { echo '-';}else{ echo $image_attributes2[1].' x '.$image_attributes2[2];}  
  104. echo '</td> 
  105.  
  106. <td> 
  107. '.$wp_filetype['ext'].' 
  108. </td> 
  109.  
  110. <td> 
  111. '.$attachment_id.' 
  112. </td> 
  113.  
  114. <td> 
  115. '.wp_get_attachment_link( $attachment_id, '' , false, false, 'Link' ).' 
  116. </td> 
  117.  
  118. <td> 
  119. '.preg_replace( '/\.[^.]+$/', '', $filename).' 
  120. </td> 
  121. </tr>'; 
  122. }} 
  123. ?> 
  124. </tbody> 
  125.  
  126. <input type="hidden" class="wccm_add_to_list" id="product_image_gallery" name="product_image_gallery" value="<?php echo esc_attr( $product_image_gallery ); ?>" /> 
  127.  
  128. <input type="hidden" id="wccm_default_keys_load" name="wccm_default_keys_load" value="<?php echo esc_attr($default_wccm_values); ?>" /> 
  129.  
  130. </table> 
  131.  
  132. <p class="add_product_images hide-if-no-js"> 
  133.  
  134.  
  135. <form method="POST" action="myurl"> <span class="btn button-primary wccm_add_order_link fileinput-button"> 
  136. <span>Add Order Files</span> 
  137.  
  138. <input type="file" name="files_wccm" id="files_wccm" multiple /> 
  139. <button type="button" id="files_button_wccm">Upload Files!</button> 
  140.  
  141.  
  142. </span> 
  143. </form> 
  144.  
  145. </p> 
  146.  
  147.  
  148. <script type="text/javascript"> 
  149. jQuery(document).ready(function($) { 
  150. (function post_image_content() { 
  151. var input = document.getElementById("files_wccm"),  
  152. formdata = false;  
  153.  
  154. if (window.FormData) { 
  155. formdata = new FormData(); 
  156. document.getElementById("files_button_wccm").style.display = "none"; 
  157.  
  158.  
  159. input.addEventListener("change", function (evt) { 
  160.  
  161. $(".wccm_results").html("Uploading, please wait...."); 
  162.  
  163. var i = 0, len = this.files.length, img, reader, file; 
  164.  
  165. for ( ; i < len; i++ ) { 
  166. file = this.files[i]; 
  167.  
  168. if (formdata) { 
  169. formdata.append("files_wccm[]", file);  
  170.  
  171. if (formdata) { 
  172. $.ajax({ 
  173. url: "<?php echo admin_url('/admin-ajax.php?action=wccs_upload_file_func&order_id='.$post->ID.''); ?>",  
  174. type: "POST",  
  175. data: formdata,  
  176. processData: false,  
  177. contentType: false,  
  178. success: function (res) { 
  179. $('#files_wccm').show(); 
  180.  
  181. $(".wccm_results").html("Files Uploaded Successfully."); 
  182.  
  183. $.ajax({ 
  184. url: '<?php echo admin_url('/post.php?post='.$post->ID.'&action=edit'); ?>',  
  185. data: {},  
  186. success: function (data) { 
  187. $("div#product_images_container").html($(data).find("div#product_images_container")); 
  188. $(".wccm_results").html("Files Uploaded Successfully."); 
  189. },  
  190. dataType: 'html' 
  191. }); 
  192.  
  193. }); 
  194. }, false); 
  195. }()); 
  196.  
  197. }); 
  198. </script> 
  199.  
  200.  
  201.  
  202.  
  203. <input type="button" id="wccm_save_order_submit" class="button button-primary" value="Save Changes"> 
  204. <div class="wccm_results"></div>  
  205.  
  206. <div class="clear"></div></div> 
  207. <?php 
  208.