WC_Dynamic_Gallery_Meta_Boxes

WooCommerce Dynamic Gallery Meta_Boxes Class.

Defined (1)

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

/classes/class-wc-dynamic-gallery-metaboxes.php  
  1. class WC_Dynamic_Gallery_Meta_Boxes 
  2.  
  3. public function __construct() { 
  4. $current_db_version = get_option( 'woocommerce_db_version', null ); 
  5.  
  6. if ( version_compare( $current_db_version, '2.3.0', '>=' ) ) { 
  7. add_filter( 'woocommerce_product_data_tabs', array( $this, 'dynamic_gallery_tab' ), 100 ); 
  8. add_action( 'woocommerce_product_data_panels', array( $this, 'dynamic_gallery_panel' ), 100 ); 
  9. } else { 
  10. add_action( 'add_meta_boxes', array( $this, 'woocommerce_meta_boxes_image' ), 9 ); 
  11.  
  12. add_action( 'save_post', array( $this, 'save_actived_d_gallery' ), 11 ); 
  13.  
  14. public function dynamic_gallery_tab( $product_data_tabs ) { 
  15. $product_data_tabs['dgallery'] = array( 
  16. 'label' => __( 'Dynamic Gallery', 'woo_dgallery' ),  
  17. 'target' => 'wc-dgallery-product-images',  
  18. 'class' => array( 'product_dgallery_tab' ),  
  19. ); 
  20.  
  21. return $product_data_tabs; 
  22.  
  23. public function dynamic_gallery_panel() { 
  24. global $post; 
  25.  
  26. $global_wc_dgallery_activate = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'activate' ); 
  27. $actived_d_gallery = get_post_meta( $post->ID, '_actived_d_gallery', true ); 
  28.  
  29. if ($actived_d_gallery == '' && $global_wc_dgallery_activate != 'no') { 
  30. $actived_d_gallery = 1; 
  31.  
  32. $default_enable_gallery_thumb = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'enable_gallery_thumb' ); 
  33. $enable_gallery_thumb = get_post_meta($post->ID, '_wc_dgallery_enable_gallery_thumb', true); 
  34. if ( $enable_gallery_thumb == '' ) { 
  35. $enable_gallery_thumb = $default_enable_gallery_thumb; 
  36. if ( $enable_gallery_thumb == 1 || $enable_gallery_thumb == 'yes' ) { 
  37. $enable_gallery_thumb = 1 ; 
  38.  
  39. $default_auto_feature_image = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'auto_feature_image' ); 
  40. $auto_feature_image = get_post_meta($post->ID, '_wc_dgallery_auto_feature_image', true); 
  41. if ( $auto_feature_image == '' ) { 
  42. $auto_feature_image = $default_auto_feature_image; 
  43. if ( $auto_feature_image == 1 || $auto_feature_image == 'yes' ) { 
  44. $auto_feature_image = 1 ; 
  45.  
  46. wp_enqueue_style( 'a3-dynamic-metabox-admin-style' ); 
  47. if ( is_rtl() ) { 
  48. wp_enqueue_style( 'a3-dynamic-metabox-admin-style-rtl' ); 
  49. wp_enqueue_script( 'a3-dynamic-metabox-admin-script' ); 
  50. wp_localize_script( 'a3-dynamic-metabox-admin-script', 'a3_dgallery_metabox', array( 'ajax_url' => admin_url( 'admin-ajax.php', 'relative' ) ) ); 
  51. wp_enqueue_media(); 
  52.  
  53. ?> 
  54. <div id="wc-dgallery-product-images" class="panel woocommerce_options_panel"> 
  55.  
  56. <script type="text/javascript"> 
  57. jQuery(document).ready(function() { 
  58. var dynamic_gallery_title_text = '<?php echo __( 'Dynamic Product Gallery', 'woo_dgallery' ); ?>'; 
  59. var dynamic_gallery_link_add_text = '<?php echo __( 'Add dynamic gallery images', 'woo_dgallery' ); ?>'; 
  60. var woo_gallery_title = jQuery('#woocommerce-product-images').find('.hndle span'); 
  61. var woo_gallery_link_add = jQuery('#woocommerce-product-images').find('.add_product_images a'); 
  62. var woo_gallery_title_text = woo_gallery_title.html(); 
  63. var woo_gallery_link_add_text = woo_gallery_link_add.html(); 
  64.  
  65. if( jQuery('input.actived_d_gallery').is(":checked") ) { 
  66. woo_gallery_title.html(dynamic_gallery_title_text); 
  67. woo_gallery_link_add.html(dynamic_gallery_link_add_text); 
  68.  
  69. jQuery('input.actived_d_gallery').change(function() { 
  70. if( jQuery(this).is(":checked") ) { 
  71. woo_gallery_title.html(dynamic_gallery_title_text); 
  72. woo_gallery_link_add.html(dynamic_gallery_link_add_text); 
  73. } else { 
  74. woo_gallery_title.html(woo_gallery_title_text); 
  75. woo_gallery_link_add.html(woo_gallery_link_add_text); 
  76. }); 
  77. }); 
  78. </script> 
  79.  
  80. <div class="options_group"> 
  81.  
  82. <p class="form-field"> 
  83. <label for="actived_d_gallery"><?php _e( 'a3 Dynamic Gallery', 'woo_dgallery' ); ?></label> 
  84. <input type="checkbox" <?php checked( 1, $actived_d_gallery, true ); ?> value="1" id="actived_d_gallery" name="actived_d_gallery" class="checkbox actived_d_gallery" /> 
  85. <span class="description"><?php _e( 'Activate a3 Dynamic Image Gallery', 'woo_dgallery' ); ?></span> 
  86. <br /> 
  87. <?php echo __( 'Dynamic Gallery function is applied to all images in the WooCommerce Default Product Gallery. Use the Product Gallery Meta box in the right sidebar of this product edit page to Add, Move or Delete images.', 'woo_dgallery' ); ?> 
  88. <br /> 
  89. <?php echo __( '<strong>Important!</strong> If you do not see the Product Gallery meta box in the sidebar go to the Screen Options Tab at the top right corner of this page and check the [ ] Product Gallery box so it will show.', 'woo_dgallery' ); ?> 
  90. <br /> 
  91. <?php echo __( '<strong>Tip!</strong> When a3 Dynamic Gallery is activated for this product the meta box name auto changes from Product Gallery to Dynamic Product Gallery.', 'woo_dgallery' ); ?> 
  92. </p> 
  93. </div> 
  94.  
  95. <div id="main_dgallery_panel" class="options_group a3_dgallery_is_variable_product" style="<?php if ( 1 != $actived_d_gallery ) { echo 'display: none;'; } ?>"> 
  96.  
  97. <p class="form-field"> 
  98. <label for="wc_dgallery_enable_gallery_thumb"><?php _e( 'Gallery Thumbnails', 'woo_dgallery' ); ?></label> 
  99. <input type="checkbox" <?php checked( 1, $enable_gallery_thumb, true ); ?> value="1" id="wc_dgallery_enable_gallery_thumb" name="wc_dgallery_enable_gallery_thumb" class="checkbox wc_dgallery_enable_gallery_thumb" /> 
  100. <span class="description"><?php _e( 'Check to show Thumbnails with this Gallery', 'woo_dgallery' ); ?></span> 
  101. </p> 
  102.  
  103. <p class="form-field"> 
  104. <label for="wc_dgallery_auto_feature_image"><?php _e( 'Include Feature Image', 'woo_dgallery' ); ?></label> 
  105. <input type="checkbox" <?php checked( 1, $auto_feature_image, true ); ?> value="1" id="wc_dgallery_auto_feature_image" name="wc_dgallery_auto_feature_image" class="checkbox wc_dgallery_auto_feature_image" /> 
  106. <span class="description"><?php _e( 'Check and Product Image (Feature Image) will show as the first image in the Gallery.', 'woo_dgallery' ); ?></span> 
  107. <br /> 
  108. <?php echo __( 'Unchecked and Product Image is not used in the gallery unless it is uploaded to the Dynamic Product Gallery', 'woo_dgallery' ); ?> 
  109. </p> 
  110. </div> 
  111.  
  112. <?php 
  113. // Add an nonce field so we can check for it later. 
  114. wp_nonce_field( 'a3_dynamic_metabox_action', 'a3_dynamic_metabox_nonce_field' ); 
  115. ?> 
  116. <div style="clear: both;"></div> 
  117.  
  118. </div> 
  119. <?php 
  120.  
  121. public function woocommerce_meta_boxes_image() { 
  122. add_meta_box( 'wc-dgallery-product-images', __( 'A3 Dynamic Image Gallery', 'woo_dgallery' ), array( $this, 'woocommerce_product_image_box' ), 'product', 'normal', 'high' ); 
  123.  
  124. public function woocommerce_product_image_box() { 
  125. global $post; 
  126.  
  127. $global_wc_dgallery_activate = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'activate' ); 
  128. $actived_d_gallery = get_post_meta( $post->ID, '_actived_d_gallery', true ); 
  129.  
  130. if ($actived_d_gallery == '' && $global_wc_dgallery_activate != 'no') { 
  131. $actived_d_gallery = 1; 
  132.  
  133. $default_enable_gallery_thumb = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'enable_gallery_thumb' ); 
  134. $enable_gallery_thumb = get_post_meta($post->ID, '_wc_dgallery_enable_gallery_thumb', true); 
  135. if ( $enable_gallery_thumb == '' ) { 
  136. $enable_gallery_thumb = $default_enable_gallery_thumb; 
  137. if ( $enable_gallery_thumb == 1 || $enable_gallery_thumb == 'yes' ) { 
  138. $enable_gallery_thumb = 1 ; 
  139.  
  140. $default_auto_feature_image = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'auto_feature_image' ); 
  141. $auto_feature_image = get_post_meta($post->ID, '_wc_dgallery_auto_feature_image', true); 
  142. if ( $auto_feature_image == '' ) { 
  143. $auto_feature_image = $default_auto_feature_image; 
  144. if ( $auto_feature_image == 1 || $auto_feature_image == 'yes' ) { 
  145. $auto_feature_image = 1 ; 
  146.  
  147. wp_enqueue_style( 'a3-dynamic-metabox-admin-style' ); 
  148. if ( is_rtl() ) { 
  149. wp_enqueue_style( 'a3-dynamic-metabox-admin-style-rtl' ); 
  150. wp_enqueue_script( 'a3-dynamic-metabox-admin-script' ); 
  151. wp_localize_script( 'a3-dynamic-metabox-admin-script', 'a3_dgallery_metabox', array( 'ajax_url' => admin_url( 'admin-ajax.php', 'relative' ) ) ); 
  152. wp_enqueue_media(); 
  153.  
  154. ob_start(); 
  155.  
  156. ?> 
  157. <div class="a3rev_panel_container a3-metabox-panel-wrap a3-dynamic-metabox-panel-wrap" style="padding-left: 0px;"> 
  158.  
  159. <div style="margin-bottom:10px;"> 
  160. <label class="a3_actived_d_gallery" style="margin-right: 50px;"> 
  161. <input type="checkbox" <?php checked( 1, $actived_d_gallery, true ); ?> value="1" name="actived_d_gallery" class="actived_d_gallery" />  
  162. <?php echo __( 'A3 Dynamic Image Gallery activated', 'woo_dgallery' ); ?> 
  163. </label> 
  164. <br /> 
  165. <?php echo __( 'Dynamic Gallery function is applied to all images in the WooCommerce Default Product Gallery. Use the Product Gallery Meta box in the right sidebar of this product edit page to Add, Move or Delete images.', 'woo_dgallery' ); ?> 
  166. <br /> 
  167. <?php echo __( '<strong>Important!</strong> If you do not see the Product Gallery meta box in the sidebar go to the Screen Options Tab at the top right corner of this page and check the [ ] Product Gallery box so it will show.', 'woo_dgallery' ); ?> 
  168. <br /> 
  169. <?php echo __( '<strong>Tip!</strong> When a3 Dynamic Gallery is activated for this product the meta box name auto changes from Product Gallery to Dynamic Product Gallery.', 'woo_dgallery' ); ?> 
  170. </div> 
  171.  
  172. <div id="main_dgallery_panel" class="dgallery_images_container a3-metabox-panel a3-metabox-options-panel" style="<?php if ( 1 != $actived_d_gallery ) { echo 'display: none;'; } ?>"> 
  173.  
  174. <p class="a3_dgallery_is_variable_product"> 
  175. <label class="a3_wc_dgallery_enable_gallery_thumb"> 
  176. <input type="checkbox" <?php checked( 1, $enable_gallery_thumb, true ); ?> value="1" name="wc_dgallery_enable_gallery_thumb" class="wc_dgallery_enable_gallery_thumb" /> 
  177. <?php echo __( 'Check to show Thumbnails with this Gallery', 'woo_dgallery' ); ?> 
  178. </label> 
  179. </p> 
  180.  
  181. <p class="a3_dgallery_is_variable_product"> 
  182. <label class="a3_wc_dgallery_auto_feature_image"> 
  183. <input type="checkbox" <?php checked( 1, $auto_feature_image, true ); ?> value="1" name="wc_dgallery_auto_feature_image" class="wc_dgallery_auto_feature_image" /> 
  184. <?php echo __( 'Check to auto include Feature Image to Gallery on frontend', 'woo_dgallery' ); ?> 
  185. </label> 
  186. </p> 
  187.  
  188. </div> 
  189.  
  190. <?php 
  191. // Add an nonce field so we can check for it later. 
  192. wp_nonce_field( 'a3_dynamic_metabox_action', 'a3_dynamic_metabox_nonce_field' ); 
  193. ?> 
  194. <div style="clear: both;"></div> 
  195.  
  196. </div> 
  197. <div style="clear: both;"></div> 
  198.  
  199. <script type="text/javascript"> 
  200. jQuery(document).ready(function() { 
  201. var dynamic_gallery_title_text = '<?php echo __( 'Dynamic Product Gallery', 'woo_dgallery' ); ?>'; 
  202. var dynamic_gallery_link_add_text = '<?php echo __( 'Add dynamic gallery images', 'woo_dgallery' ); ?>'; 
  203. var woo_gallery_title = jQuery('#woocommerce-product-images').find('.hndle span'); 
  204. var woo_gallery_link_add = jQuery('#woocommerce-product-images').find('.add_product_images a'); 
  205. var woo_gallery_title_text = woo_gallery_title.html(); 
  206. var woo_gallery_link_add_text = woo_gallery_link_add.html(); 
  207.  
  208. if( jQuery('input.actived_d_gallery').is(":checked") ) { 
  209. woo_gallery_title.html(dynamic_gallery_title_text); 
  210. woo_gallery_link_add.html(dynamic_gallery_link_add_text); 
  211.  
  212. jQuery('input.actived_d_gallery').change(function() { 
  213. if( jQuery(this).is(":checked") ) { 
  214. woo_gallery_title.html(dynamic_gallery_title_text); 
  215. woo_gallery_link_add.html(dynamic_gallery_link_add_text); 
  216. } else { 
  217. woo_gallery_title.html(woo_gallery_title_text); 
  218. woo_gallery_link_add.html(woo_gallery_link_add_text); 
  219. }); 
  220. }); 
  221. </script> 
  222. <?php 
  223. $output = ob_get_clean(); 
  224. echo $output; 
  225.  
  226. public function save_actived_d_gallery( $post_id = 0 ) { 
  227.  
  228. if ( $post_id < 1 ) { 
  229. global $post; 
  230. $post_id = $post->ID; 
  231.  
  232. // Check if our nonce is set. 
  233. if ( ! isset( $_POST['a3_dynamic_metabox_nonce_field'] ) || ! check_admin_referer( 'a3_dynamic_metabox_action', 'a3_dynamic_metabox_nonce_field' ) ) 
  234. return $post_id; 
  235.  
  236. // If this is an autosave, our form has not been submitted,  
  237. // so we don't want to do anything. 
  238. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
  239. return $post_id; 
  240.  
  241. if ( ! current_user_can( 'edit_post', $post_id ) ) 
  242. return $post_id; 
  243.  
  244. if ( 'product' != get_post_type( $post_id ) ) return $post_id; 
  245.  
  246. if ( isset( $_REQUEST['actived_d_gallery'] ) ) { 
  247. update_post_meta( $post_id, '_actived_d_gallery', 1 ); 
  248. } else { 
  249. update_post_meta( $post_id, '_actived_d_gallery', 0 ); 
  250.  
  251. if ( isset( $_REQUEST['wc_dgallery_enable_gallery_thumb'] ) ) { 
  252. update_post_meta( $post_id, '_wc_dgallery_enable_gallery_thumb', 1 ); 
  253. } else { 
  254. update_post_meta( $post_id, '_wc_dgallery_enable_gallery_thumb', 0 ); 
  255.  
  256. if ( isset( $_REQUEST['wc_dgallery_auto_feature_image'] ) ) { 
  257. update_post_meta( $post_id, '_wc_dgallery_auto_feature_image', 1 ); 
  258. } else { 
  259. update_post_meta( $post_id, '_wc_dgallery_auto_feature_image', 0 ); 
  260.