mh_custom_slider_widget

The MH Corporate basic mh custom slider widget class.

Defined (1)

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

/includes/widgets/mh-custom-slider.php  
  1. class mh_custom_slider_widget extends WP_Widget { 
  2. function __construct() { 
  3. parent::__construct( 
  4. 'mh_custom_slider', esc_html_x('MH Custom Slider (lite)', 'widget name', 'mh-corporate-basic'),  
  5. array( 
  6. 'classname' => 'mh_custom_slider',  
  7. 'description' => esc_html__('Custom Slider Widget to display custom content for use on homepage template.', 'mh-corporate-basic') 
  8. ); 
  9. function widget($args, $instance) { 
  10. extract($args); 
  11. $default_Image = get_template_directory_uri() . '/images/noimage_940x400.png'; 
  12.  
  13. $title1 = empty($instance['title1']) ? '' : $instance['title1']; 
  14. $url1 = empty($instance['url1']) ? '' : $instance['url1']; 
  15. $image1 = empty($instance['image1']) ? $default_Image : $instance['image1']; 
  16. $excerpt1 = empty($instance['excerpt1']) ? '' : $instance['excerpt1']; 
  17.  
  18. $title2 = empty($instance['title2']) ? '' : $instance['title2']; 
  19. $url2 = empty($instance['url2']) ? '' : $instance['url2']; 
  20. $image2 = empty($instance['image2']) ? $default_Image : $instance['image2']; 
  21. $excerpt2 = empty($instance['excerpt2']) ? '' : $instance['excerpt2']; 
  22.  
  23. $title3 = empty($instance['title3']) ? '' : $instance['title3']; 
  24. $url3 = empty($instance['url3']) ? '' : $instance['url3']; 
  25. $image3 = empty($instance['image3']) ? $default_Image : $instance['image3']; 
  26. $excerpt3 = empty($instance['excerpt3']) ? '' : $instance['excerpt3']; 
  27.  
  28. $slide1 = array('title' => $title1, 'url' => $url1, 'image' => $image1, 'excerpt' => $excerpt1); 
  29. $slide2 = array('title' => $title2, 'url' => $url2, 'image' => $image2, 'excerpt' => $excerpt2); 
  30. $slide3 = array('title' => $title3, 'url' => $url3, 'image' => $image3, 'excerpt' => $excerpt3); 
  31. $slides = array($slide1, $slide2, $slide3); 
  32.  
  33. echo $before_widget; ?> 
  34. <section id="mh-slider-<?php echo rand(1, 9999); ?>" class="flexslider"> 
  35. <ul class="slides"> 
  36. <?php foreach($slides as $slide) { ?> 
  37. <?php if ($slide['title'] || $slide['image'] != $default_Image || $slide['excerpt']) { ?> 
  38. <li> 
  39. <article class="slide-wrap"> 
  40. <a href="<?php echo esc_url($slide['url']); ?>" title="<?php echo esc_attr($slide['title']); ?>"><img src="<?php echo esc_url($slide['image']); ?>" alt="<?php echo esc_attr($slide['title']); ?>" /></a> 
  41. <?php if ($slide['title'] || $slide['excerpt']) { ?> 
  42. <div class="slide-caption"> 
  43. <div class="slide-data"> 
  44. <?php if ($slide['title']) { ?> 
  45. <a href="<?php echo esc_url($slide['url']); ?>" title="<?php echo esc_attr($slide['title']); ?>"><h2 class="slide-title"><?php echo esc_attr($slide['title']); ?></h2></a> 
  46. <?php } ?> 
  47. <?php if ($slide['excerpt']) { ?> 
  48. <div class="slide-excerpt mh-excerpt"><?php echo esc_attr($slide['excerpt']); ?> <a href="<?php echo esc_url($slide['url']); ?>" title="<?php echo esc_attr($slide['title']); ?>"></a></div> 
  49. <?php } ?> 
  50. </div> 
  51. </div> 
  52. <?php } ?> 
  53. </article> 
  54. </li> 
  55. <?php } ?> 
  56. <?php } ?> 
  57. </ul> 
  58. </section><?php 
  59. echo $after_widget; 
  60. function update($new_instance, $old_instance) { 
  61. $instance = $old_instance; 
  62.  
  63. $instance['title1'] = sanitize_text_field($new_instance['title1']); 
  64. $instance['url1'] = esc_url_raw($new_instance['url1']); 
  65. $instance['image1'] = esc_url_raw($new_instance['image1']); 
  66. $instance['excerpt1'] = strip_tags($new_instance['excerpt1']); 
  67.  
  68. $instance['title2'] = sanitize_text_field($new_instance['title2']); 
  69. $instance['url2'] = esc_url_raw($new_instance['url2']); 
  70. $instance['image2'] = esc_url_raw($new_instance['image2']); 
  71. $instance['excerpt2'] = strip_tags($new_instance['excerpt2']); 
  72.  
  73. $instance['title3'] = sanitize_text_field($new_instance['title3']); 
  74. $instance['url3'] = esc_url_raw($new_instance['url3']); 
  75. $instance['image3'] = esc_url_raw($new_instance['image3']); 
  76. $instance['excerpt3'] = strip_tags($new_instance['excerpt3']); 
  77.  
  78. return $instance; 
  79. function form($instance) { 
  80. $defaults = array('title1' => '', 'url1' => '', 'image1' => '', 'excerpt1' => '', 'title2' => '', 'url2' => '', 'image2' => '', 'excerpt2' => '', 'title3' => '', 'url3' => '', 'image3' => '', 'excerpt3' => ''); 
  81. $instance = wp_parse_args((array) $instance, $defaults); ?> 
  82.  
  83. <p class="widget-separator"><?php _e('Slide', 'mh-corporate-basic'); ?> 1</p> 
  84. <p> 
  85. <label for="<?php echo $this->get_field_id('title1'); ?>"><?php _e('Title:', 'mh-corporate-basic'); ?></label> 
  86. <input class="widefat" type="text" value="<?php echo esc_attr($instance['title1']); ?>" name="<?php echo $this->get_field_name('title1'); ?>" id="<?php echo $this->get_field_id('title1'); ?>" /> 
  87. </p> 
  88. <p> 
  89. <label for="<?php echo $this->get_field_id('url1'); ?>"><?php _e('Custom URL:', 'mh-corporate-basic'); ?></label> 
  90. <input class="widefat" type="text" value="<?php echo esc_url($instance['url1']); ?>" name="<?php echo $this->get_field_name('url1'); ?>" id="<?php echo $this->get_field_id('url1'); ?>" /> 
  91. </p> 
  92. <p> 
  93. <label for="<?php echo $this->get_field_id('image1'); ?>"><?php _e('Custom Image URL:', 'mh-corporate-basic'); ?></label> 
  94. <input class="widefat" type="text" value="<?php echo esc_url($instance['image1']); ?>" name="<?php echo $this->get_field_name('image1'); ?>" id="<?php echo $this->get_field_id('image1'); ?>" /> 
  95. </p> 
  96. <p> 
  97. <label for="<?php echo $this->get_field_id('excerpt1'); ?>"><?php _e('Custom Excerpt:', 'mh-corporate-basic'); ?></label> 
  98. <textarea cols="60" rows="3" style="width: 100%;" placeholder="Enter custom Excerpt" name="<?php echo $this->get_field_name('excerpt1'); ?>" id="<?php echo $this->get_field_id('excerpt1'); ?>"><?php echo esc_attr($instance['excerpt1']); ?></textarea> 
  99. </p> 
  100.  
  101. <p class="widget-separator"><?php _e('Slide', 'mh-corporate-basic'); ?> 2</p> 
  102. <p> 
  103. <label for="<?php echo $this->get_field_id('title2'); ?>"><?php _e('Title:', 'mh-corporate-basic'); ?></label> 
  104. <input class="widefat" type="text" value="<?php echo esc_attr($instance['title2']); ?>" name="<?php echo $this->get_field_name('title2'); ?>" id="<?php echo $this->get_field_id('title2'); ?>" /> 
  105. </p> 
  106. <p> 
  107. <label for="<?php echo $this->get_field_id('url2'); ?>"><?php _e('Custom URL:', 'mh-corporate-basic'); ?></label> 
  108. <input class="widefat" type="text" value="<?php echo esc_url($instance['url2']); ?>" name="<?php echo $this->get_field_name('url2'); ?>" id="<?php echo $this->get_field_id('url2'); ?>" /> 
  109. </p> 
  110. <p> 
  111. <label for="<?php echo $this->get_field_id('image2'); ?>"><?php _e('Custom Image URL:', 'mh-corporate-basic'); ?></label> 
  112. <input class="widefat" type="text" value="<?php echo esc_url($instance['image2']); ?>" name="<?php echo $this->get_field_name('image2'); ?>" id="<?php echo $this->get_field_id('image2'); ?>" /> 
  113. </p> 
  114. <p> 
  115. <label for="<?php echo $this->get_field_id('excerpt2'); ?>"><?php _e('Custom Excerpt:', 'mh-corporate-basic'); ?></label> 
  116. <textarea cols="60" rows="3" style="width: 100%;" placeholder="Enter custom Excerpt" name="<?php echo $this->get_field_name('excerpt2'); ?>" id="<?php echo $this->get_field_id('excerpt2'); ?>"><?php echo esc_attr($instance['excerpt2']); ?></textarea> 
  117. </p> 
  118.  
  119. <p class="widget-separator"><?php _e('Slide', 'mh-corporate-basic'); ?> 3</p> 
  120. <p> 
  121. <label for="<?php echo $this->get_field_id('title3'); ?>"><?php _e('Title:', 'mh-corporate-basic'); ?></label> 
  122. <input class="widefat" type="text" value="<?php echo esc_attr($instance['title3']); ?>" name="<?php echo $this->get_field_name('title3'); ?>" id="<?php echo $this->get_field_id('title3'); ?>" /> 
  123. </p> 
  124. <p> 
  125. <label for="<?php echo $this->get_field_id('url3'); ?>"><?php _e('Custom URL:', 'mh-corporate-basic'); ?></label> 
  126. <input class="widefat" type="text" value="<?php echo esc_url($instance['url3']); ?>" name="<?php echo $this->get_field_name('url3'); ?>" id="<?php echo $this->get_field_id('url3'); ?>" /> 
  127. </p> 
  128. <p> 
  129. <label for="<?php echo $this->get_field_id('image3'); ?>"><?php _e('Custom Image URL:', 'mh-corporate-basic'); ?></label> 
  130. <input class="widefat" type="text" value="<?php echo esc_url($instance['image3']); ?>" name="<?php echo $this->get_field_name('image3'); ?>" id="<?php echo $this->get_field_id('image3'); ?>" /> 
  131. </p> 
  132. <p> 
  133. <label for="<?php echo $this->get_field_id('excerpt3'); ?>"><?php _e('Custom Excerpt:', 'mh-corporate-basic'); ?></label> 
  134. <textarea cols="60" rows="3" style="width: 100%;" placeholder="Enter custom Excerpt" name="<?php echo $this->get_field_name('excerpt3'); ?>" id="<?php echo $this->get_field_id('excerpt3'); ?>"><?php echo esc_attr($instance['excerpt3']); ?></textarea> 
  135. </p> 
  136. <p> 
  137. <strong>Info:</strong> <?php _e('This is the lite version of this widget with basic features. If you need more professional features and options, you can upgrade to the premium version of this theme.', 'mh-corporate-basic'); ?> 
  138. </p><?php