WC_GZD_Trusted_Shops_Shortcodes

The WooCommerce Germanized WC GZD Trusted Shops Shortcodes class.

Defined (1)

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

/includes/trusted-shops/class-wc-gzd-trusted-shops-shortcodes.php  
  1. class WC_GZD_Trusted_Shops_Shortcodes { 
  2.  
  3. protected static $_instance = null; 
  4.  
  5. public $base = null; 
  6.  
  7. public static function instance( $base ) { 
  8. if ( is_null( self::$_instance ) ) 
  9. self::$_instance = new self( $base ); 
  10. return self::$_instance; 
  11.  
  12. private function __construct( $base ) { 
  13. $this->base = $base; 
  14.  
  15. add_action( 'init', array( $this, 'init' ), 3 ); 
  16.  
  17. public function init() { 
  18.  
  19. // Define shortcodes 
  20. $shortcodes = array( 
  21. 'trusted_shops_rich_snippets'=> array( $this, 'trusted_shops_rich_snippets' ),  
  22. 'trusted_shops_reviews' => array( $this, 'trusted_shops_reviews' ),  
  23. 'trusted_shops_badge' => array( $this, 'trusted_shops_badge' ),  
  24. ); 
  25.  
  26. foreach ( $shortcodes as $shortcode => $function ) { 
  27. add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function ); 
  28.  
  29.  
  30. public function get_trusted_shops_rich_snippets_image() { 
  31.  
  32. $image_url = ''; 
  33. $custom_logo_id = get_theme_mod( 'custom_logo' ); 
  34.  
  35. if ( ! empty( $custom_logo_id ) ) { 
  36.  
  37. $image = wp_get_attachment_image_src( $custom_logo_id , 'full' ); 
  38.  
  39. if ( ! empty( $image ) ) 
  40. $image_url = $image[0]; 
  41.  
  42. // Use WooCommerce E-Mail Header Image 
  43. if ( empty( $image_url ) ) { 
  44. $image_url = get_option( 'woocommerce_email_header_image' ); 
  45.  
  46. // Use Header Image 
  47. if ( empty( $image_url ) && function_exists( 'get_header_image' ) ) { 
  48. $image_url = get_header_image(); 
  49.  
  50. return apply_filters( 'woocommerce_gzd_trusted_shops_rich_snippets_image', $image_url ); 
  51.  
  52. /** 
  53. * Returns Trusted Shops rich snippet review html 
  54. *  
  55. * @param array $atts  
  56. * @return string  
  57. */ 
  58. public function trusted_shops_rich_snippets( $atts ) { 
  59.  
  60. ob_start(); 
  61. wc_get_template( 'trusted-shops/rich-snippets.php', array(  
  62. 'rating' => $this->base->get_average_rating(),  
  63. 'rating_link' => $this->base->get_rating_link(),  
  64. 'image' => $this->get_trusted_shops_rich_snippets_image() 
  65. ) ); 
  66. $html = ob_get_clean(); 
  67. return $this->base->is_enabled() ? '<div class="woocommerce woocommerce-gzd">' . $html . '</div>' : ''; 
  68.  
  69.  
  70. /** 
  71. * Returns Trusted Shops reviews graphic 
  72. *  
  73. * @param array $atts  
  74. * @return string  
  75. */ 
  76. public function trusted_shops_reviews( $atts ) { 
  77.  
  78. ob_start(); 
  79. wc_get_template( 'trusted-shops/reviews.php', array( 'rating_link' => $this->base->get_rating_link(), 'widget_attachment' => $this->base->get_review_widget_attachment() ) ); 
  80. $html = ob_get_clean(); 
  81. return $this->base->is_enabled() ? '<div class="woocommerce woocommerce-gzd">' . $html . '</div>' : ''; 
  82.  
  83.  
  84. /** 
  85. * Returns Trusted Shops Badge html 
  86. *  
  87. * @param array $atts  
  88. * @return string  
  89. */ 
  90. public function trusted_shops_badge( $atts ) { 
  91.  
  92. extract( shortcode_atts( array('width' => ''), $atts ) ); 
  93. return $this->base->is_enabled() ? '<a class="trusted-shops-badge" style="' . ( $width ? 'background-size:' . ( $width - 1 ) . 'px auto; width: ' . $width . 'px; height: ' . $width . 'px;' : '' ) . '" href="' . $this->base->get_certificate_link() . '" target="_blank"></a>' : ''; 
  94.  
  95.