WC_Dynamic_Gallery_Functions

WC Dynamic Gallery Functions.

Defined (1)

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

/classes/class-wc-dynamic-gallery-functions.php  
  1. class WC_Dynamic_Gallery_Functions 
  2.  
  3. public static function reset_products_galleries_activate() { 
  4. global $wpdb; 
  5. $wpdb->query( "DELETE FROM ".$wpdb->postmeta." WHERE meta_key='_actived_d_gallery' " ); 
  6.  
  7. public static function reset_auto_feature_image_activate() { 
  8. global $wpdb; 
  9. $wpdb->query( "DELETE FROM ".$wpdb->postmeta." WHERE meta_key='_wc_dgallery_auto_feature_image' " ); 
  10.  
  11. public static function reset_thumbnails_activate() { 
  12. global $wpdb; 
  13. $wpdb->query( "DELETE FROM ".$wpdb->postmeta." WHERE meta_key='_wc_dgallery_enable_gallery_thumb' " ); 
  14.  
  15. public static function add_google_fonts() { 
  16. global $wc_dgallery_fonts_face; 
  17.  
  18. $caption_font = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'caption_font' ); 
  19.  
  20. $navbar_font = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'navbar_font' ); 
  21.  
  22. $google_fonts = array( $caption_font['face'], $navbar_font['face'] ); 
  23. $wc_dgallery_fonts_face->generate_google_webfonts( $google_fonts ); 
  24.  
  25. public static function get_no_image_uri() { 
  26. $no_image_uri = apply_filters( 'wc_dg_no_image_uri', WOO_DYNAMIC_GALLERY_JS_URL . '/mygallery/no-image.png' ); 
  27.  
  28. return $no_image_uri; 
  29.  
  30. public static function get_gallery_ids( $post_id = 0 ) { 
  31. $a3_dynamic_gallery_db_version = get_option( 'a3_dynamic_gallery_db_version', '1.0.0' ); 
  32. if ( $post_id < 1 ) return array(); 
  33.  
  34. $post_type = get_post_type( $post_id ); 
  35. if ( false === $post_type ) { 
  36. return array(); 
  37.  
  38. if ( 'product' != $post_type ) { 
  39. return array(); 
  40.  
  41. // Back Compatibility for DB version less than 2.1.0 
  42. if ( version_compare( $a3_dynamic_gallery_db_version, '2.1.0', '<' ) ) { 
  43. return self::get_gallery_ids_back_compatibility( $post_id ); 
  44.  
  45. $default_auto_feature_image = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'auto_feature_image', 'yes' ); 
  46. $auto_feature_image = get_post_meta( $post_id, '_wc_dgallery_auto_feature_image', true ); 
  47. if ( $auto_feature_image == '' ) { 
  48. $auto_feature_image = $default_auto_feature_image; 
  49. if ( $auto_feature_image == 1 || $auto_feature_image == 'yes' ) { 
  50. $auto_feature_image = 'yes'; 
  51.  
  52. $have_gallery_ids = false; 
  53. $have_featured_image = false; 
  54.  
  55. $featured_img_id = (int) get_post_meta( $post_id, '_thumbnail_id', true ); 
  56. if ( ! empty( $featured_img_id ) && $featured_img_id > 0 ) { 
  57. $have_featured_image = true; 
  58. $have_gallery_ids = true; 
  59.  
  60. // Use the WooCommerce Default Gallery 
  61. $dgallery_ids = get_post_meta( $post_id, '_product_image_gallery', true ); 
  62. if ( ! empty( $dgallery_ids ) && '' != trim( $dgallery_ids ) ) { 
  63. $dgallery_ids = explode( ', ', $dgallery_ids ); 
  64.  
  65. if ( count( $dgallery_ids ) > 0 ) { 
  66. $have_gallery_ids = true; 
  67.  
  68. if ( $have_gallery_ids && is_array( $dgallery_ids ) && count( $dgallery_ids ) > 0 ) { 
  69.  
  70. foreach ( $dgallery_ids as $img_id ) { 
  71. // Remove image id if it is not image 
  72. if ( ! wp_attachment_is_image( $img_id ) ) { 
  73. $dgallery_ids = array_diff( $dgallery_ids, array( $img_id ) ); 
  74.  
  75. if ( 'yes' == $auto_feature_image && $have_featured_image && ! in_array( $featured_img_id, $dgallery_ids ) ) { 
  76. $dgallery_ids = array_merge( array( $featured_img_id ), $dgallery_ids ); 
  77.  
  78. if ( count( $dgallery_ids ) > 0 ) { 
  79. return $dgallery_ids; 
  80.  
  81.  
  82. // set dgallery_ids to empty array if don't have Woo Default Gallery 
  83. $dgallery_ids = array(); 
  84.  
  85. if ( $have_featured_image ) { 
  86. $dgallery_ids[] = $featured_img_id; 
  87.  
  88. $attached_images = (array) get_posts( array( 
  89. 'post_type' => 'attachment',  
  90. 'post_mime_type' => 'image',  
  91. 'numberposts' => -1,  
  92. 'post_status' => null,  
  93. 'post_parent' => $post_id,  
  94. 'orderby' => 'menu_order',  
  95. 'order' => 'ASC',  
  96. 'exclude' => array( $featured_img_id ),  
  97. ) ); 
  98.  
  99. if ( is_array( $attached_images ) && count( $attached_images ) > 0 ) { 
  100. foreach ( $attached_images as $item_thumb ) { 
  101. $is_excluded = get_post_meta( $item_thumb->ID, '_woocommerce_exclude_image', true ); 
  102.  
  103. // Don't get if this image is excluded on main gallery 
  104. if ( 1 == $is_excluded ) continue; 
  105.  
  106. $dgallery_ids[] = $item_thumb->ID; 
  107.  
  108. return $dgallery_ids; 
  109.  
  110. public static function get_gallery_ids_back_compatibility( $post_id = 0 ) { 
  111.  
  112. if ( $post_id < 1 ) return array(); 
  113.  
  114. $have_gallery_ids = false; 
  115.  
  116. // 1.6.1: a3 gallery custom field for Product support for sort and new UI uploader 
  117. $dgallery_ids = get_post_meta( $post_id, '_a3_dgallery', true ); 
  118. if ( ! empty( $dgallery_ids ) && '' != trim( $dgallery_ids ) ) { 
  119. $dgallery_ids = explode( ', ', $dgallery_ids ); 
  120. if ( count( $dgallery_ids ) > 0 ) { 
  121. $have_gallery_ids = true; 
  122.  
  123. // Use the WooCommerce Default Gallery if don't have a3 dynamic gallery 
  124. if ( ! $have_gallery_ids ) { 
  125.  
  126. $dgallery_ids = get_post_meta( $post_id, '_product_image_gallery', true ); 
  127. if ( ! empty( $dgallery_ids ) && '' != trim( $dgallery_ids ) ) { 
  128. $dgallery_ids = explode( ', ', $dgallery_ids ); 
  129.  
  130. if ( count( $dgallery_ids ) > 0 ) { 
  131. $have_gallery_ids = true; 
  132.  
  133.  
  134. if ( $have_gallery_ids ) { 
  135.  
  136. foreach ( $dgallery_ids as $img_id ) { 
  137. // Remove image id if it is not image 
  138. if ( ! wp_attachment_is_image( $img_id ) ) { 
  139. $dgallery_ids = array_diff( $dgallery_ids, array( $img_id ) ); 
  140.  
  141. if ( count( $dgallery_ids ) > 0 ) { 
  142. return $dgallery_ids; 
  143.  
  144.  
  145. // set dgallery_ids to empty array if don't have gallery above 
  146. $dgallery_ids = array(); 
  147.  
  148. $featured_img_id = (int) get_post_meta( $post_id, '_thumbnail_id', true ); 
  149. if ( ! empty( $featured_img_id ) && $featured_img_id > 0 ) { 
  150. $dgallery_ids[] = $featured_img_id; 
  151.  
  152. $attached_images = (array) get_posts( array( 
  153. 'post_type' => 'attachment',  
  154. 'post_mime_type' => 'image',  
  155. 'numberposts' => -1,  
  156. 'post_status' => null,  
  157. 'post_parent' => $post_id,  
  158. 'orderby' => 'menu_order',  
  159. 'order' => 'ASC',  
  160. 'exclude' => array( $featured_img_id ),  
  161. ) ); 
  162.  
  163. if ( is_array( $attached_images ) && count( $attached_images ) > 0 ) { 
  164. foreach ( $attached_images as $item_thumb ) { 
  165. $is_excluded = get_post_meta( $item_thumb->ID, '_woocommerce_exclude_image', true ); 
  166.  
  167. // Don't get if this image is excluded on main gallery 
  168. if ( 1 == $is_excluded ) continue; 
  169.  
  170. $dgallery_ids[] = $item_thumb->ID; 
  171.  
  172. return $dgallery_ids; 
  173.  
  174. public static function a3_wp_admin() { 
  175. wp_enqueue_style( 'a3rev-wp-admin-style', WOO_DYNAMIC_GALLERY_CSS_URL . '/a3_wp_admin.css' ); 
  176.  
  177. public static function plugin_extra_links($links, $plugin_name) { 
  178. if ( $plugin_name != WOO_DYNAMIC_GALLERY_NAME) { 
  179. return $links; 
  180. $links[] = '<a href="http://docs.a3rev.com/user-guides/woocommerce/woo-dynamic-gallery/" target="_blank">'.__('Documentation', 'woo_dgallery').'</a>'; 
  181. $links[] = '<a href="http://wordpress.org/support/plugin/woocommerce-dynamic-gallery/" target="_blank">'.__('Support', 'woo_dgallery').'</a>'; 
  182. return $links; 
  183.  
  184. public static function settings_plugin_links($actions) { 
  185. $actions = array_merge( array( 'settings' => '<a href="admin.php?page=woo-dynamic-gallery">' . __( 'Settings', 'woo_dgallery' ) . '</a>' ), $actions ); 
  186.  
  187. return $actions; 
  188.  
  189. public static function plugin_extension_box( $boxes = array() ) { 
  190. global $wc_dgallery_admin_init; 
  191.  
  192. $support_box = '<a href="'.$wc_dgallery_admin_init->support_url.'" target="_blank" alt="'.__('Go to Support Forum', 'woo_dgallery').'"><img src="'.WOO_DYNAMIC_GALLERY_IMAGES_URL.'/go-to-support-forum.png" /></a>'; 
  193.  
  194. $boxes[] = array( 
  195. 'content' => $support_box,  
  196. 'css' => 'border: none; padding: 0; background: none;' 
  197. ); 
  198.  
  199. $review_box = '<div style="margin-bottom: 5px; font-size: 12px;"><strong>' . __('Is this plugin is just what you needed? If so', 'woo_dgallery') . '</strong></div>'; 
  200. $review_box .= '<a href="https://wordpress.org/support/view/plugin-reviews/woocommerce-dynamic-gallery#postform" target="_blank" alt="'.__('Submit Review for Plugin on WordPress', 'woo_dgallery').'"><img src="'.WOO_DYNAMIC_GALLERY_IMAGES_URL.'/a-5-star-rating-would-be-appreciated.png" /></a>'; 
  201.  
  202. $boxes[] = array( 
  203. 'content' => $review_box,  
  204. 'css' => 'border: none; padding: 0; background: none;' 
  205. ); 
  206.  
  207. $pro_box = '<a href="'.$wc_dgallery_admin_init->pro_plugin_page_url.'" target="_blank" alt="'.__('Product Dynamic Gallery Pro', 'woo_dgallery').'"><img src="'.WOO_DYNAMIC_GALLERY_IMAGES_URL.'/pro-version.jpg" /></a>'; 
  208.  
  209. $boxes[] = array( 
  210. 'content' => $pro_box,  
  211. 'css' => 'border: none; padding: 0; background: none;' 
  212. ); 
  213.  
  214. $free_woocommerce_box = '<a href="https://profiles.wordpress.org/a3rev/#content-plugins" target="_blank" alt="'.__('Free WooCommerce Plugins', 'woo_dgallery').'"><img src="'.WOO_DYNAMIC_GALLERY_IMAGES_URL.'/free-woocommerce-plugins.png" /></a>'; 
  215.  
  216. $boxes[] = array( 
  217. 'content' => $free_woocommerce_box,  
  218. 'css' => 'border: none; padding: 0; background: none;' 
  219. ); 
  220.  
  221. $free_wordpress_box = '<a href="https://profiles.wordpress.org/a3rev/#content-plugins" target="_blank" alt="'.__('Free WordPress Plugins', 'woo_dgallery').'"><img src="'.WOO_DYNAMIC_GALLERY_IMAGES_URL.'/free-wordpress-plugins.png" /></a>'; 
  222.  
  223. $boxes[] = array( 
  224. 'content' => $free_wordpress_box,  
  225. 'css' => 'border: none; padding: 0; background: none;' 
  226. ); 
  227.  
  228. $connect_box = '<div style="margin-bottom: 5px;">' . __('Connect with us via', 'woo_dgallery') . '</div>'; 
  229. $connect_box .= '<a href="https://www.facebook.com/a3rev" target="_blank" alt="'.__('a3rev Facebook', 'woo_dgallery').'" style="margin-right: 5px;"><img src="'.WOO_DYNAMIC_GALLERY_IMAGES_URL.'/follow-facebook.png" /></a> '; 
  230. $connect_box .= '<a href="https://twitter.com/a3rev" target="_blank" alt="'.__('a3rev Twitter', 'woo_dgallery').'"><img src="'.WOO_DYNAMIC_GALLERY_IMAGES_URL.'/follow-twitter.png" /></a>'; 
  231.  
  232. $boxes[] = array( 
  233. 'content' => $connect_box,  
  234. 'css' => 'border-color: #3a5795;' 
  235. ); 
  236.  
  237. return $boxes;