Advertisement
Uranbold

hotsugar_core

Apr 12th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: Hotsugar Core
  4. * Plugin URI: http://www.themewaves.com/
  5. * Description: Themewaves Core Plugin
  6. * Version: 1.0.0
  7. * Author: Themewaves
  8. * Author URI: http://www.themewaves.com/
  9. * Text Domain: waves
  10. * License: GPL-2.0+
  11. * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
  12. * Domain Path: /languages
  13. *
  14. *
  15. * @package hotsugar-core
  16. * @author Themewaves
  17. * @license GPL-2.0+
  18. * @link themewaves.com
  19. * @copyright 2016 Themewaves
  20. */
  21.  
  22. // If this file is called directly, abort.
  23. if ( ! defined( 'WPINC' ) ) {
  24. die;
  25. }
  26. define('HOTSUGAR_CORE_DIR', trailingslashit(plugin_dir_url( __FILE__ )));
  27. add_action('admin_init', 'hotsugar_elements_include');
  28. function hotsugar_elements_include(){
  29. require_once 'waves-shortcode.php';
  30. }
  31.  
  32. add_action('init', 'hotsugar_core_init');
  33. function hotsugar_core_init(){
  34. add_shortcode( 'tw_posts','hotsugar_post_carousel' );
  35. add_shortcode( 'tw_btn', 'hotsugar_button' );
  36. }
  37. function hotsugar_post_carousel($atts){
  38. $atts = shortcode_atts( array(
  39. 'layout' => '',
  40. 'title' => '',
  41. 'cats' => '',
  42. 'posts_per_page' => '6',
  43. ), $atts, 'tw_carousel' );
  44. $class = !empty($atts['layout']) ? (' layout-'.$atts['layout']) : '';
  45.  
  46. global $post, $hotsugar_options;
  47.  
  48. $query = Array(
  49. 'post_type' => 'post',
  50. 'posts_per_page' => $atts['posts_per_page'],
  51. 'ignore_sticky_posts' => 1,
  52. );
  53. $cats = $atts['cats'];
  54. if (!empty($cats)) {
  55. $query['tax_query'] = Array(Array(
  56. 'taxonomy' => 'category',
  57. 'terms' => explode(',',$cats),
  58. 'field' => 'slug'
  59. )
  60. );
  61. }
  62.  
  63. if(!empty($hotsugar_options['post__not_in'])){
  64. $query['post__not_in'] = $hotsugar_options['post__not_in'];
  65. }
  66.  
  67. wp_enqueue_script('owl-carousel');
  68.  
  69. $output = '<div class="tw-post-carousel">';
  70. $output .= !empty($atts['title']) ? ('<h3 class="tw-element-title">'.esc_html($atts['title']).'</h3>') : '';
  71. $output .= '<div class="owl-carousel'.esc_attr($class).'">';
  72.  
  73. query_posts($query);
  74. if($atts['layout'] == '2'){
  75. while (have_posts()){the_post();
  76. $hotsugar_options['post__not_in'][]=$post->ID;
  77. $img = $data = '';
  78. if (has_post_thumbnail($post->ID)) {
  79. $img = hotsugar_image('hotsugar_carousel_2', true);
  80. if(hotsugar_metabox('parallax_post')){
  81. $img = hotsugar_image('hotsugar_carousel_3', true);
  82. wp_enqueue_script('jarallax');
  83. $data .= ' data-jarallax=\'{"speed": 0.4}\'';
  84. }
  85. if( !empty($img['url']) ){
  86. $data .= ' style=" background-image: url('.esc_url($img['url']).')"';
  87. }
  88. }
  89. $output .= '<div class="tw-owl-item">';
  90. $output .= '<div class="post-thumb tw-thumbnail" '. $data .'>';
  91. $cats = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "<span class='cat-item'>$2</span>", hotsugar_cats());
  92. $output .= '<div class="carousel-content"><div class="entry-cats">'.($cats).'</div>';
  93. $output .= '<h3 class="carousel-title">' . get_the_title() . '</h3>';
  94. $output .= '<div class="tw-meta"><span class="date">'.get_the_time(get_option('date_format')).'</span></div>';
  95. $output .= '</div>';
  96. if( !empty($img['url']) ){
  97. $output .= '<div class="image-overlay"></div>';
  98. }
  99. $output .= '</a></div>';
  100. $output .= "</div>";
  101. }
  102. }else{
  103. while (have_posts()){the_post();
  104. $hotsugar_options['post__not_in'][]=$post->ID;
  105. $img='';
  106. $format = get_post_format();
  107. if (has_post_thumbnail($post->ID)) {
  108. $img = '<a href="'.get_permalink().'">'.hotsugar_image('hotsugar_carousel_1').'</a>';
  109. if( $format == 'video' ){
  110. $img .= '<i class="video-format-icon ion-ios-play"></i>';
  111. }
  112. }
  113. $output .= '<div class="tw-owl-item">';
  114. $output .= '<div class="post-thumb tw-thumbnail">'.($img).'</div>';
  115. $output .= '<div class="carousel-content">';
  116. $output .= '<h3 class="carousel-title"><a href="'.esc_url(get_permalink()).'">' . get_the_title() . '</a></h3>';
  117. $output .= '<div class="tw-meta"><span class="date">'.get_the_time(get_option('date_format')).'</span></div>';
  118. $output .= '</div>';
  119. $output .= "</div>";
  120. }
  121. }
  122. wp_reset_query();
  123.  
  124. $output .= '</div>';
  125. $output .= '</div>';
  126. return $output;
  127. }
  128. function hotsugar_button( $atts , $content ){
  129. $atts = shortcode_atts( array(
  130. 'link' => '',
  131. 'size' => 'medium',
  132. 'style' => 'flat',
  133. 'color' => '',
  134. 'round' => ''
  135. ), $atts, 'tw_button' );
  136.  
  137. $class = $style = '';
  138. switch ($atts['size']) {
  139. case 'small':
  140. $class .= ' btn-s';
  141. break;
  142. case 'large':
  143. $class .= ' btn-l';
  144. break;
  145. }
  146. if($atts['style']=='border'){
  147. $class .= ' btn-border';
  148. $style .= 'style="color: '.esc_attr($atts['color']).'; border-color: '.esc_attr($atts['color']).';"';
  149. } else {
  150. $class .= ' btn-flat';
  151. $class .= $atts['color'] == '#fff' || $atts['color'] == '#ffffff' ? (' white-btn') : '';
  152. $style .= 'style="background-color: '.esc_attr($atts['color']).';border-color: '.esc_attr($atts['color']).';"';
  153. }
  154. if($atts['round']=='true'){
  155. $class .= ' btn-round';
  156. }
  157. $output = '<a href="'.esc_attr($atts['link']).'" class="btn'.esc_attr($class).'">'. $content .'</a>';
  158.  
  159. return $output;
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement