| 1 |
<?php |
| 2 |
|
| 3 |
if ( !class_exists('htinstagram_default_widgets') ) { |
| 4 |
class htinstagram_default_widgets extends WP_Widget{ |
| 5 |
|
| 6 |
function __construct(){ |
| 7 |
|
| 8 |
$widget_options = array( |
| 9 |
'description' => esc_html__('WP Instagram', 'ht-instagram'), |
| 10 |
'customize_selective_refresh' => true, |
| 11 |
); |
| 12 |
|
| 13 |
parent:: __construct('htinstagram_default_widgets', esc_html__( 'HT : WP Instagram', 'ht-instagram'), $widget_options ); |
| 14 |
|
| 15 |
} |
| 16 |
/** |
| 17 |
* Front-end display of widget. |
| 18 |
* |
| 19 |
* @see WP_Widget::widget() |
| 20 |
* |
| 21 |
* @param array $args Widget arguments. |
| 22 |
* @param array $instance Saved values from database. |
| 23 |
*/ |
| 24 |
public function widget($args, $instance){ |
| 25 |
|
| 26 |
$title = isset( $instance['title'] ) ? $instance['title'] : ''; |
| 27 |
$limit = isset( $instance['limit'] ) ? (int)$instance['limit'] : 8; |
| 28 |
$delete_cache = isset( $instance['delete_cache'] ) ? $instance['delete_cache'] : 'no'; |
| 29 |
$cache_time = isset( $instance['cache_time'] ) ? $instance['cache_time'] : 'week'; |
| 30 |
$column = isset( $instance['column'] ) ? $instance['column'] : 4; |
| 31 |
$space = isset( $instance['space'] ) ? $instance['space'] : 5; |
| 32 |
$showcaption = isset( $instance['showcaption'] ) ? $instance['showcaption'] : ''; |
| 33 |
$showfollowbtn = isset( $instance['showfollowbtn'] ) ? $instance['showfollowbtn'] : ''; |
| 34 |
$followbtnpos = isset( $instance['followbtnpos'] ) ? $instance['followbtnpos'] : ''; |
| 35 |
$target = isset( $instance['target'] ) ? $instance['target'] : ''; |
| 36 |
|
| 37 |
// Options Value |
| 38 |
$likecommentbg = htinstagram_get_option( 'likecommentbg', 'htinstagram_widgets_style_tabs' ); |
| 39 |
$commentlike_color = htinstagram_get_option( 'commentlike_color', 'htinstagram_widgets_style_tabs' ); |
| 40 |
$commentlike_font_size = htinstagram_get_option( 'commentlike_font_size', 'htinstagram_widgets_style_tabs' ); |
| 41 |
$follow_background = htinstagram_get_option( 'follow_background', 'htinstagram_widgets_style_tabs' ); |
| 42 |
$follow_buttoncolor = htinstagram_get_option( 'follow_buttoncolor', 'htinstagram_widgets_style_tabs' ); |
| 43 |
$follow_button_f_s = htinstagram_get_option( 'follow_button_f_s', 'htinstagram_widgets_style_tabs' ); |
| 44 |
$follow_icon_color = htinstagram_get_option( 'follow_icon_color', 'htinstagram_widgets_style_tabs' ); |
| 45 |
$follow_icon_background = htinstagram_get_option( 'follow_icon_background', 'htinstagram_widgets_style_tabs' ); |
| 46 |
|
| 47 |
// Slider Options value |
| 48 |
$slider_on = htinstagram_get_option( 'slider_on', 'htinstagram_widgets_style_tabs' ); |
| 49 |
$slarrows = htinstagram_get_option( 'slarrows', 'htinstagram_widgets_style_tabs' ); |
| 50 |
$sldots = htinstagram_get_option( 'sldots', 'htinstagram_widgets_style_tabs' ); |
| 51 |
$slautolay = htinstagram_get_option( 'slautolay', 'htinstagram_widgets_style_tabs' ); |
| 52 |
$slautoplay_speed = htinstagram_get_option( 'slautoplay_speed', 'htinstagram_widgets_style_tabs' ); |
| 53 |
$slanimation_speed = htinstagram_get_option( 'slanimation_speed', 'htinstagram_widgets_style_tabs' ); |
| 54 |
$slcentermode = htinstagram_get_option( 'slcentermode', 'htinstagram_widgets_style_tabs' ); |
| 55 |
$slcenterpadding = htinstagram_get_option( 'slcenterpadding', 'htinstagram_widgets_style_tabs' ); |
| 56 |
$slitems = htinstagram_get_option( 'slitems', 'htinstagram_widgets_style_tabs' ); |
| 57 |
$slrows = htinstagram_get_option( 'slrows', 'htinstagram_widgets_style_tabs' ); |
| 58 |
$sltablet_display_columns = htinstagram_get_option( 'sltablet_display_columns', 'htinstagram_widgets_style_tabs' ); |
| 59 |
$slmobile_display_columns = htinstagram_get_option( 'slmobile_display_columns', 'htinstagram_widgets_style_tabs' ); |
| 60 |
|
| 61 |
$uniqid = 'htinstragram_form_default_widget_'.$limit.$column; |
| 62 |
|
| 63 |
$shortcode_atts = [ |
| 64 |
'id'=>'id="'.$uniqid.'"', |
| 65 |
'limit' => 'limit="'.$limit.'"', |
| 66 |
'column' => 'column="'.$column.'"', |
| 67 |
'delete_cache' => 'delete_cache="'.$delete_cache.'"', |
| 68 |
'cache_time' => 'cache_time="'.$cache_time.'"', |
| 69 |
'space' => 'space="'.$space.'"', |
| 70 |
'showcaption' => 'showcaption="'.$showcaption.'"', |
| 71 |
'caption_pos' => 'caption_pos="top"', |
| 72 |
'showfollowbtn' => 'showfollowbtn="'.$showfollowbtn.'"', |
| 73 |
'followbtnpos' => 'followbtnpos="'.$followbtnpos.'"', |
| 74 |
'target' => 'target="'.$target.'"', |
| 75 |
|
| 76 |
'slider_on' => 'slider_on="'.( $slider_on == 'on' ? 'yes' : 'no' ).'"', |
| 77 |
'slarrows' => 'slarrows="'.( $slarrows == 'on' ? 'yes' : 'no' ).'"', |
| 78 |
'slprevicon' => 'slprevicon="fa fa-angle-left"', |
| 79 |
'slnexticon' => 'slnexticon="fa fa-angle-right"', |
| 80 |
'sldots' => 'sldots="'.( $sldots == 'on' ? 'yes' : 'no' ).'"', |
| 81 |
'slautolay' => 'slautolay="'.( $slautolay == 'on' ? 'yes' : 'no' ).'"', |
| 82 |
'slautoplay_speed' => 'slautoplay_speed="'.$slautoplay_speed.'"', |
| 83 |
'slanimation_speed' => 'slanimation_speed="'.$slanimation_speed.'"', |
| 84 |
'slcentermode' => 'slcentermode="'.( $slcentermode == 'on' ? 'yes' : 'no' ).'"', |
| 85 |
'slcenterpadding' => 'slcenterpadding="'.$slcenterpadding.'"', |
| 86 |
'slitems' => 'slitems="'.( $slitems <= 0 ? 4 : $slitems ).'"', |
| 87 |
'slrows' => 'slrows="'.( $slrows <= 0 ? 1 : $slrows ).'"', |
| 88 |
'slscroll_columns' => 'slscroll_columns="1"', |
| 89 |
'sltablet_width' => 'sltablet_width="750"', |
| 90 |
'sltablet_display_columns' => 'sltablet_display_columns="'.( $sltablet_display_columns <= 0 ? 1 : $sltablet_display_columns).'"', |
| 91 |
'sltablet_scroll_columns' => 'sltablet_scroll_columns="1"', |
| 92 |
'slmobile_width' => 'slmobile_width="480"', |
| 93 |
'slmobile_display_columns' => 'slmobile_display_columns="'.( $slmobile_display_columns <= 0 ? 1 : $slmobile_display_columns ).'"', |
| 94 |
'slmobile_scroll_columns' => 'slmobile_scroll_columns="1"', |
| 95 |
|
| 96 |
'captionbg' => 'captionbg="'.$likecommentbg.'"', |
| 97 |
'caption_color' => 'caption_color="'.$commentlike_color.'"', |
| 98 |
'caption_font_size' => 'caption_font_size="'.( $commentlike_font_size <= 0 ? 14 : $commentlike_font_size ).'"', |
| 99 |
'follow_background' => 'follow_background="'.$follow_background.'"', |
| 100 |
'follow_buttoncolor' => 'follow_buttoncolor="'.$follow_buttoncolor.'"', |
| 101 |
'follow_button_f_s' => 'follow_button_f_s="'.( $follow_button_f_s <= 0 ? 14 : $follow_button_f_s).'"', |
| 102 |
'follow_icon_color' => 'follow_icon_color="'.$follow_icon_color.'"', |
| 103 |
'follow_icon_background' => 'follow_icon_background="'.$follow_icon_background.'"', |
| 104 |
]; |
| 105 |
|
| 106 |
// Render Html |
| 107 |
echo $args['before_widget']; |
| 108 |
if ( !empty( $title ) ) { echo $args['before_title'] . esc_html( $title ) . $args['after_title']; } |
| 109 |
?> |
| 110 |
<div class="htinsta-widgets"> |
| 111 |
<?php echo do_shortcode( sprintf( '[htinstagram %s]', implode(' ', $shortcode_atts ) ) ); ?> |
| 112 |
</div> |
| 113 |
<?php echo $args['after_widget']; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
/** |
| 118 |
* Sanitize widget form values as they are saved. |
| 119 |
* |
| 120 |
* @see WP_Widget::update() |
| 121 |
* |
| 122 |
* @param array $new_instance Values just sent to be saved. |
| 123 |
* @param array $old_instance Previously saved values from database. |
| 124 |
* |
| 125 |
* @return array Updated safe values to be saved. |
| 126 |
*/ |
| 127 |
|
| 128 |
public function update( $new_instance, $old_instance ) { |
| 129 |
$instance = $old_instance; |
| 130 |
$instance['title'] = strip_tags($new_instance['title']); |
| 131 |
$instance['limit'] = $new_instance['limit']; |
| 132 |
$instance['delete_cache'] = $new_instance['delete_cache']; |
| 133 |
$instance['cache_time'] = $new_instance['cache_time']; |
| 134 |
$instance['column'] = $new_instance['column']; |
| 135 |
$instance['space'] = $new_instance['space']; |
| 136 |
$instance['showcaption'] = $new_instance['showcaption']; |
| 137 |
$instance['showfollowbtn'] = $new_instance['showfollowbtn']; |
| 138 |
$instance['followbtnpos'] = $new_instance['followbtnpos']; |
| 139 |
$instance['target'] = $new_instance['target']; |
| 140 |
return $instance; |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* Back-end widget form. |
| 145 |
* |
| 146 |
* @see WP_Widget::form() |
| 147 |
* |
| 148 |
* @param array $instance Previously saved values from database. |
| 149 |
*/ |
| 150 |
|
| 151 |
public function form( $instance ){ |
| 152 |
|
| 153 |
$array_default = array( |
| 154 |
'title' => 'HT Instagram' |
| 155 |
,'limit' => 8 |
| 156 |
,'delete_cache' => 'no' |
| 157 |
,'cache_time' => 'week' |
| 158 |
,'column' => 4 |
| 159 |
,'space' => 5 |
| 160 |
,'showcaption' => 'no' |
| 161 |
,'showfollowbtn'=> 'yes' |
| 162 |
,'followbtnpos'=> 'bottom' |
| 163 |
,'target' => '_self' |
| 164 |
); |
| 165 |
$instance = wp_parse_args( (array) $instance, $array_default ); |
| 166 |
|
| 167 |
?> |
| 168 |
|
| 169 |
<p> |
| 170 |
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Enter your title', 'ht-instagram'); ?> </label> |
| 171 |
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($instance['title']); ?>" /> |
| 172 |
</p> |
| 173 |
<p> |
| 174 |
<label for="<?php echo esc_attr($this->get_field_id('limit')); ?>"><?php echo esc_html__('Item Limit:' ,'ht-instagram') ?></label> |
| 175 |
<input id="<?php echo esc_attr($this->get_field_id('limit')); ?>" name="<?php echo esc_attr($this->get_field_name('limit')); ?>" type="number" class="widefat" value="<?php echo esc_attr($instance['limit']); ?>"> |
| 176 |
</p> |
| 177 |
|
| 178 |
<p> |
| 179 |
<label for="<?php echo esc_attr($this->get_field_id('delete_cache')); ?>"><?php esc_html_e('Delete Cache', 'ht-instagram'); ?> </label> |
| 180 |
<select class="widefat" id="<?php echo esc_attr($this->get_field_id('delete_cache')); ?>" name="<?php echo esc_attr($this->get_field_name('delete_cache')); ?>" > |
| 181 |
<option value="yes" <?php selected($instance['delete_cache'], 'yes'); ?> ><?php esc_html_e('Yes','ht-instagram');?></option> |
| 182 |
<option value="no" <?php selected($instance['delete_cache'], 'no'); ?> ><?php esc_html_e('No','ht-instagram');?></option> |
| 183 |
</select> |
| 184 |
</p> |
| 185 |
|
| 186 |
<p> |
| 187 |
<label for="<?php echo esc_attr($this->get_field_id('cache_time')); ?>"><?php esc_html_e('Cache Time', 'ht-instagram'); ?> </label> |
| 188 |
<select class="widefat" id="<?php echo esc_attr($this->get_field_id('cache_time')); ?>" name="<?php echo esc_attr($this->get_field_name('cache_time')); ?>" > |
| 189 |
<option value="minute" <?php selected($instance['cache_time'], 'minute'); ?> ><?php esc_html_e('One Minute','ht-instagram');?></option> |
| 190 |
<option value="hour" <?php selected($instance['cache_time'], 'hour'); ?> ><?php esc_html_e('One hour','ht-instagram');?></option> |
| 191 |
<option value="day" <?php selected($instance['cache_time'], 'day'); ?> ><?php esc_html_e('One day','ht-instagram');?></option> |
| 192 |
<option value="week" <?php selected($instance['cache_time'], 'week'); ?> ><?php esc_html_e('One week','ht-instagram');?></option> |
| 193 |
<option value="month" <?php selected($instance['cache_time'], 'month'); ?> ><?php esc_html_e('One month','ht-instagram');?></option> |
| 194 |
<option value="year" <?php selected($instance['cache_time'], 'year'); ?> ><?php esc_html_e('One year','ht-instagram');?></option> |
| 195 |
</select> |
| 196 |
</p> |
| 197 |
|
| 198 |
<p> |
| 199 |
<label for="<?php echo esc_attr($this->get_field_id('column')); ?>"><?php esc_html_e('Column', 'ht-instagram'); ?> </label> |
| 200 |
<select class="widefat" id="<?php echo esc_attr($this->get_field_id('column')); ?>" name="<?php echo esc_attr($this->get_field_name('column')); ?>" > |
| 201 |
<?php for( $i = 1; $i <= 6; $i++ ): ?> |
| 202 |
<option value="<?php echo esc_attr($i); ?>" <?php selected($instance['column'], $i); ?> ><?php echo esc_html($i); ?></option> |
| 203 |
<?php endfor; ?> |
| 204 |
</select> |
| 205 |
</p> |
| 206 |
|
| 207 |
<p> |
| 208 |
<label for="<?php echo esc_attr($this->get_field_id('space')); ?>"><?php echo esc_html__('Item Space:' ,'ht-instagram') ?></label> |
| 209 |
<input id="<?php echo esc_attr($this->get_field_id('space')); ?>" name="<?php echo esc_attr($this->get_field_name('space')); ?>" type="number" class="widefat" value="<?php echo esc_attr($instance['space']); ?>"> |
| 210 |
</p> |
| 211 |
|
| 212 |
<p> |
| 213 |
<label for="<?php echo esc_attr($this->get_field_id('showcaption')); ?>"><?php esc_html_e('Show Caption', 'ht-instagram'); ?> </label> |
| 214 |
<select class="widefat" id="<?php echo esc_attr($this->get_field_id('showcaption')); ?>" name="<?php echo esc_attr($this->get_field_name('showcaption')); ?>" > |
| 215 |
<option value="yes" <?php selected($instance['showcaption'], 'yes'); ?> ><?php esc_html_e('Yes','ht-instagram');?></option> |
| 216 |
<option value="no" <?php selected($instance['showcaption'], 'no'); ?> ><?php esc_html_e('No','ht-instagram');?></option> |
| 217 |
</select> |
| 218 |
</p> |
| 219 |
<p> |
| 220 |
<label for="<?php echo esc_attr($this->get_field_id('showfollowbtn')); ?>"><?php esc_html_e('Show Follow Button', 'ht-instagram'); ?> </label> |
| 221 |
<select class="widefat" id="<?php echo esc_attr($this->get_field_id('showfollowbtn')); ?>" name="<?php echo esc_attr($this->get_field_name('showfollowbtn')); ?>" > |
| 222 |
<option value="yes" <?php selected($instance['showfollowbtn'], 'yes'); ?> ><?php esc_html_e('Yes','ht-instagram');?></option> |
| 223 |
<option value="no" <?php selected($instance['showfollowbtn'], 'no'); ?> ><?php esc_html_e('No','ht-instagram');?></option> |
| 224 |
</select> |
| 225 |
</p> |
| 226 |
<p> |
| 227 |
<label for="<?php echo esc_attr($this->get_field_id('followbtnpos')); ?>"><?php esc_html_e('Follow Button Position', 'ht-instagram'); ?> </label> |
| 228 |
<select class="widefat" id="<?php echo esc_attr($this->get_field_id('followbtnpos')); ?>" name="<?php echo esc_attr($this->get_field_name('followbtnpos')); ?>" > |
| 229 |
<option value="top" <?php selected($instance['followbtnpos'], 'top'); ?> ><?php esc_html_e('Top','ht-instagram');?></option> |
| 230 |
<option value="middle" <?php selected($instance['followbtnpos'], 'middle'); ?> ><?php esc_html_e('Middle','ht-instagram');?></option> |
| 231 |
<option value="bottom" <?php selected($instance['followbtnpos'], 'bottom'); ?> ><?php esc_html_e('Bottom','ht-instagram');?></option> |
| 232 |
</select> |
| 233 |
</p> |
| 234 |
<p> |
| 235 |
<label for="<?php echo esc_attr($this->get_field_id('target')); ?>"><?php esc_html_e('Target', 'ht-instagram'); ?> </label> |
| 236 |
<select class="widefat" id="<?php echo esc_attr($this->get_field_id('target')); ?>" name="<?php echo esc_attr($this->get_field_name('target')); ?>" > |
| 237 |
<option value="_self" <?php selected($instance['target'], '_self'); ?> >Current window</option> |
| 238 |
<option value="_blank" <?php selected($instance['target'], '_blank'); ?> >New window</option> |
| 239 |
</select> |
| 240 |
</p> |
| 241 |
|
| 242 |
<?php } |
| 243 |
|
| 244 |
} // end extends class |
| 245 |
} // end exists class |
| 246 |
|
| 247 |
|
| 248 |
// Register Author information widget. |
| 249 |
|
| 250 |
function htinstagram_default_widgets() { |
| 251 |
register_widget( 'htinstagram_default_widgets' ); |
| 252 |
} |
| 253 |
add_action( 'widgets_init', 'htinstagram_default_widgets' ); |