WC_Naguro_Editor_Manager

The WooCommerce Naguro Connect WC Naguro Editor Manager class.

Defined (1)

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

/includes/woocommerce/admin/class-wc-naguro-editor-manager.php  
  1. class WC_Naguro_Editor_Manager { 
  2. public function __construct() { 
  3. add_action( 'save_post', array( $this, 'save_post' ), 11, 1 ); 
  4. add_action( 'post_submitbox_misc_actions', array( $this, 'product_data_visibility' ) ); 
  5.  
  6. public function save_post( $post_id ) { 
  7. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 
  8. return; 
  9.  
  10. if ( 'product' != get_post_type($post_id ) ) { 
  11. return; 
  12.  
  13. $design_areas = get_post_meta( $post_id, 'naguro_design_area' ); 
  14.  
  15. $use_overlay_module = false; 
  16.  
  17. foreach ( $design_areas as $design_area ) { 
  18. if ( ! empty( $design_area['product_overlay_id'] ) && 0 != $design_area['product_overlay_id'] ) { 
  19. $use_overlay_module = true; 
  20. break; 
  21.  
  22. if ( $use_overlay_module ) { 
  23. $params['modules'] = 'main, overlay'; 
  24. } else { 
  25. $params['modules'] = 'main'; 
  26.  
  27. $params['version'] = '1.1'; 
  28. $params['theme'] = 'standard'; 
  29. $params['language'] = 'en_GB'; 
  30. $params['callback'] = home_url('naguro-editor/download'); 
  31. $hash = $this->generate_editor_hash($params); 
  32.  
  33. if ( ! $this->does_editor_exist($hash)) { 
  34. $request = new Naguro_Editor_Request($params); 
  35. $request->get('editor/request'); 
  36.  
  37. update_post_meta( $post_id, 'naguro_editor_hash', $hash ); 
  38.  
  39. private function generate_editor_hash( $params ) { 
  40. return md5(implode(', ', $params)); 
  41.  
  42. private function does_editor_exist( $hash ) { 
  43. $editor_option = get_option( 'naguro_editor_' . $hash, false ); 
  44. return ( false === $editor_option ) ? false : true; 
  45.  
  46. public function product_data_visibility() { 
  47. global $post; 
  48.  
  49. if ( 'product' != $post->post_type ) { 
  50. return; 
  51.  
  52. $editor_hash = get_post_meta( $post->ID, 'naguro_editor_hash', true); 
  53.  
  54. if ( false == $editor_hash || empty( $editor_hash ) ) { 
  55. return; 
  56.  
  57. echo '<div class="misc-pub-section" id="naguro-editor-availability">'; 
  58.  
  59. if ( $this->does_editor_exist( $editor_hash ) ) { 
  60. echo '<p>Naguro editor is available</p>'; 
  61. } else { 
  62. echo '<p>Naguro editor is not available yet</p>'; 
  63.  
  64. echo '</div>';