WC_Naguro_Overlay

The WooCommerce Naguro Connect WC Naguro Overlay class.

Defined (1)

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

/includes/naguro/modules/overlay/class-wc-naguro-overlay.php  
  1. class WC_Naguro_Overlay { 
  2. function __construct() { 
  3. add_action("naguro_woocommerce_before_printable_area_button", array($this, "add_design_area_overlay_upload"), 10, 2); 
  4. add_action("naguro_woocommerce_after_printable_area_image", array($this, "add_overlay_image")); 
  5.  
  6. add_filter("naguro_woocommerce_design_area_data", array($this, "handle_design_area_data")); 
  7. add_filter("naguro_woocommerce_save_keys", array($this, "add_overlays_to_keys")); 
  8. add_filter("naguro_woocommerce_file_keys", array($this, "add_overlay_to_keys")); 
  9. add_filter("naguro_woocommerce_filter_save_image", array($this, "save_image"), 10, 2 ); 
  10.  
  11. function add_design_area_overlay_upload($rand, $design_area) { 
  12. $name = WC_Naguro::$prefix . "designarea[overlay][" . $rand . "]"; 
  13. WC_Naguro_Product_Meta_Box::upload_field($name,  
  14. "Overlay image",  
  15. "Upload an image that will serve as the overlay image that will display on top of the designer",  
  16. ( isset( $design_area['product_overlay_id'] ) ? $design_area['product_overlay_id'] : "" ),  
  17. "naguro_designarea[product_overlay_id][]"); 
  18.  
  19. function add_overlay_image($design_area) { 
  20. if ( isset( $design_area['product_overlay_id'] ) ) { 
  21. $this->add_design_area_overlay_id($design_area['product_overlay_id']); 
  22. } else { 
  23. $this->add_design_area_overlay_id(0); 
  24.  
  25. if ( isset( $design_area['product_overlay'] ) ) { 
  26. echo '<img class="overlay-image" src="' . $design_area['product_overlay'] . '" />'; 
  27. } else { 
  28. echo '<img class="overlay-image" src="" />'; 
  29.  
  30. function add_design_area_overlay_id($id) { 
  31. $this->hidden_input( 
  32. WC_Naguro::$prefix . "designarea[product_overlay_id][]",  
  33. $id,  
  34. WC_Naguro::$prefix . "product_overlay_id" 
  35. ); 
  36.  
  37. function handle_design_area_data($design_area_data) { 
  38. if ( isset( $design_area_data['product_overlay_id'] ) ) { 
  39. $image_src = wp_get_attachment_image_src( $design_area_data['product_overlay_id'], 'full' ); 
  40. $design_area_data['product_overlay'] = $image_src[0]; 
  41.  
  42. return $design_area_data; 
  43.  
  44. function add_overlay_to_keys($keys) { 
  45. array_push($keys, "overlay"); 
  46. return $keys; 
  47.  
  48. function add_overlays_to_keys($keys) { 
  49. array_push($keys, "product_overlay_id"); 
  50. return $keys; 
  51.  
  52. function save_image($design_area, $image_ids) { 
  53. if ( isset( $image_ids['overlay'][ $design_area['upload_key'] ] ) ) { 
  54. $image_id = $image_ids['overlay'][ $design_area['upload_key']]; 
  55. } elseif ( isset( $design_area['product_overlay_id'] ) ) { 
  56. $image_id = $design_area['product_overlay_id']; 
  57. } else { 
  58. $image_id = 0; 
  59.  
  60. if ( 0 != $image_id ) { 
  61. $design_area['product_overlay_id'] = $image_id; 
  62.  
  63. return $design_area; 
  64.  
  65. public function hidden_input($name, $value, $class = "") { 
  66. echo '<input type="hidden" name="' . $name . '" value="' . $value . '" class="' . $class . '" />';