vc-youtube.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /*------------------------------------------------------*/
  3. /* taskereasy Youtube
  4. /*------------------------------------------------------*/
  5. vc_map(array(
  6. "name" => esc_html__("Video", 'taskereasy'),
  7. "base" => "taskereasy_youtube",
  8. 'icon' => get_template_directory_uri() . '/assets/images/favicon-icon/shortcode-icon.png',
  9. "class" => "",
  10. "description" => esc_html__("Add taskereasy youtube", 'taskereasy'),
  11. "category" => esc_html__('Taskereasy Shortcodes', 'taskereasy'),
  12. "params" => array(
  13. array(
  14. "type" => "dropdown",
  15. "heading" => esc_html__("Style", 'taskereasy'),
  16. "param_name" => "style",
  17. "value" => array('Style 1' => 'style_1', 'Style 2' => 'style_2', 'Style 3' => 'style_3'),
  18. ),
  19. array(
  20. "type" => "textfield",
  21. "heading" => esc_html__("Link", 'taskereasy'),
  22. "param_name" => "youtube_link",
  23. "description" => 'Add Youtube link.'
  24. ),
  25. array(
  26. "type" => "textfield",
  27. "heading" => esc_html__("Title", 'taskereasy'),
  28. "param_name" => "title",
  29. 'dependency' => array(
  30. 'element' => 'style',
  31. 'value' => array('style_2', 'style_3')
  32. ),
  33. ),
  34. array(
  35. "type" => "textarea_safe",
  36. "heading" => esc_html__("Subtitle", 'taskereasy'),
  37. "param_name" => "subtext",
  38. 'dependency' => array(
  39. 'element' => 'style',
  40. 'value' => array('style_2', 'style_3')
  41. ),
  42. ),
  43. array(
  44. "type" => "textarea_safe",
  45. "heading" => esc_html__("Description", 'taskereasy'),
  46. "param_name" => "description",
  47. 'dependency' => array(
  48. 'element' => 'style',
  49. 'value' => array('style_2', 'style_3')
  50. ),
  51. ),
  52. array(
  53. "type" => "vc_link",
  54. "heading" => esc_html__("Button", 'taskereasy'),
  55. "param_name" => "button",
  56. "value" => '',
  57. 'dependency' => array(
  58. 'element' => 'style',
  59. 'value' => array('style_2', 'style_3')
  60. ),
  61. ),
  62. array(
  63. "type" => "attach_image",
  64. "heading" => esc_html__("Image Thumbnail", 'taskereasy'),
  65. "param_name" => "image",
  66. 'dependency' => array(
  67. 'element' => 'style',
  68. 'value' => array('style_2', 'style_3')
  69. ),
  70. ),
  71. array(
  72. 'type' => 'css_editor',
  73. 'heading' => esc_html__( 'CSS', 'taskereasy' ),
  74. 'param_name' => 'custom_design',
  75. 'group' => esc_html__( 'Design options', 'taskereasy' ),
  76. )
  77. )
  78. ));
  79. add_shortcode( 'taskereasy_youtube', function($atts, $content = null) {
  80. extract(shortcode_atts(array(
  81. 'youtube_link' => '',
  82. 'style' => 'style_1',
  83. 'title' => '',
  84. 'subtext' => '',
  85. 'description' => '',
  86. 'button' => '',
  87. 'image' => '',
  88. 'custom_design' => '',
  89. ), $atts));
  90. $custom_design = vc_shortcode_custom_css_class( $custom_design, ' ' );
  91. $youtube_url = html_entity_decode(vc_value_from_safe($youtube_link, true));
  92. $output = '';
  93. $output.='<div class="ta-video '.$custom_design . $style.'">';
  94. if($style == 'style_1'){
  95. $output .=
  96. '<div class="video_wrap">
  97. <div class="play-btn"> <a class="popup-youtube" href="'.$youtube_url.'"><i class="fa fa-play"></i></a> <span class="ripple"></span> <span class="ripple"></span> </div>
  98. </div>';
  99. }elseif($style == 'style_2'){
  100. $btnlink = vc_build_link( $button );
  101. $btn_link = !empty($btnlink['url']) ? $btnlink['url'] : '#';
  102. $btn_title = $btnlink['title'];
  103. $btn_target = !empty($btnlink['target']) ? $btnlink['target'] : '_self';
  104. $image_url = wp_get_attachment_image_src( $image, 'full' );
  105. $output.=
  106. '<div class="video-4-title video-3-title">'.$subtext.'</div>
  107. <div class="video-wrpr">
  108. <div class="video-container">';
  109. if($image_url[0]){
  110. $output .=
  111. '<div class="play-btn"> <a class="popup-youtube" href="'.$youtube_url.'"><i class="fa fa-play"></i></a> <span class="ripple"></span> <span class="ripple"></span> </div>
  112. <img src="'.$image_url[0].'" alt="Thumbnail">';
  113. }
  114. $output.='
  115. </div>
  116. <div class="video-content">
  117. <h2>'.$title.'</h2>
  118. <p>'.$description.'</p>
  119. ';
  120. if(!empty($btn_title)){
  121. $output.='<a href="'.$btn_link.'" target="'.$btn_target.'" class="btn">'.$btn_title.'</a>';
  122. }
  123. $output.='
  124. </div>
  125. </div>';
  126. }else{
  127. $btnlink = vc_build_link( $button );
  128. $btn_link = !empty($btnlink['url']) ? $btnlink['url'] : '#';
  129. $btn_title = $btnlink['title'];
  130. $btn_target = !empty($btnlink['target']) ? $btnlink['target'] : '_self';
  131. $image_url = wp_get_attachment_image_src( $image, 'full' );
  132. $output.=
  133. '<div class="video-4-title video-3-title">'.$subtext.'</div>
  134. <div class="video-wrpr">
  135. <div class="video-container">';
  136. if($image_url[0]){
  137. $output .=
  138. '<div class="play-btn"> <a class="popup-youtube" href="'.$youtube_url.'"><i class="fa fa-play"></i></a> <span class="ripple"></span> <span class="ripple"></span> </div>
  139. <img src="'.$image_url[0].'" alt="Thumbnail">';
  140. }
  141. $output.='
  142. </div>
  143. <div class="video-content">
  144. <h2>'.$title.'</h2>
  145. <p>'.$description.'</p>';
  146. if(!empty($btn_title)){
  147. $output.='<a href="'.$btn_link.'" target="'.$btn_target.'" class="btn">'.$btn_title.'</a>';
  148. }
  149. $output.='
  150. </div>
  151. </div>';
  152. }
  153. $output.='</div>';
  154. return $output;
  155. });