WP Tab Widget - Version 1.2.8

Version Description

(Apr 20, 2018) = * Fixed compatibility with PHP 7.1 * Checked compatibility with WordPress v4.9.5 * Improved Code

Download this release

Release Info

Developer roymahfooz
Plugin Icon 128x128 WP Tab Widget
Version 1.2.8
Comparing to
See all releases

Code changes from version 1.2.7 to 1.2.8

img/wp-tab-widget-pro.jpg CHANGED
File without changes
languages/default.mo CHANGED
File without changes
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
- === WP Tab Widget ===
2
  Contributors: mythemeshop
3
  Creator's website link: http://mythemeshop.com/
4
  Tags: tabs, tab widget, recent posts tab, tabs widget, ajax tabs, ajax widget.
5
  Requires at least: 4.0
6
- Tested up to: 4.9.1
7
- Stable tag: 1.2.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -62,7 +62,7 @@ MyThemeShop is a premium WordPress theme provider and we develop premium plugins
62
  GitHub link: <a href="https://github.com/MyThemeShopTeam/WP-Tab-Widget">https://github.com/MyThemeShopTeam/WP-Tab-Widget</a>
63
 
64
  = Feedback =
65
- If you like this plugin, then please leave us a good rating and review.<br> Consider following us on <a rel="author" href="https://plus.google.com/+Mythemeshop/">Google+</a>, <a href="https://twitter.com/MyThemeShopTeam">Twitter</a>, and <a href="https://www.facebook.com/MyThemeShop">Facebook</a>
66
 
67
  == Installation ==
68
 
@@ -101,6 +101,11 @@ add_filter( 'wpt_sampling_rate', 'wpt_my_sampling_rate' );
101
 
102
  == Changelog ==
103
 
 
 
 
 
 
104
  = 1.2.7 (Feb 03, 2017) =
105
  * Added new wpt_sampling_rate filter. See the FAQ section on how this works.
106
 
1
+ === WP Tab Widget ===
2
  Contributors: mythemeshop
3
  Creator's website link: http://mythemeshop.com/
4
  Tags: tabs, tab widget, recent posts tab, tabs widget, ajax tabs, ajax widget.
5
  Requires at least: 4.0
6
+ Tested up to: 4.9.5
7
+ Stable tag: 1.2.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
62
  GitHub link: <a href="https://github.com/MyThemeShopTeam/WP-Tab-Widget">https://github.com/MyThemeShopTeam/WP-Tab-Widget</a>
63
 
64
  = Feedback =
65
+ If you like this plugin, then please leave us a good rating and review.<br> Consider following us on <a rel="author" href="https://plus.google.com/+Mythemeshop/">Google+</a>, <a href="https://twitter.com/MyThemeShopTeam">Twitter</a>, and <a href="https://www.facebook.com/MyThemeShop">Facebook</a>
66
 
67
  == Installation ==
68
 
101
 
102
  == Changelog ==
103
 
104
+ = 1.2.8 (Apr 20, 2018) =
105
+ * Fixed compatibility with PHP 7.1
106
+ * Checked compatibility with WordPress v4.9.5
107
+ * Improved Code
108
+
109
  = 1.2.7 (Feb 03, 2017) =
110
  * Added new wpt_sampling_rate filter. See the FAQ section on how this works.
111
 
wp-tab-widget.php CHANGED
@@ -4,20 +4,20 @@ Plugin Name: WP Tab Widget
4
  Plugin URI: http://mythemeshop.com/plugins/wp-tab-widget/
5
  Description: WP Tab Widget is the AJAXified plugin which loads content by demand, and thus it makes the plugin incredibly lightweight.
6
  Author: MyThemeShop
7
- Version: 1.2.7
8
  Author URI: http://mythemeshop.com/
9
  */
10
  if ( !class_exists('wpt_widget') ) {
11
  class wpt_widget extends WP_Widget {
12
  function __construct() {
13
-
14
  // add image sizes and load language file
15
  add_action( 'init', array(&$this, 'wpt_init') );
16
-
17
  // ajax functions
18
  add_action('wp_ajax_wpt_widget_content', array(&$this, 'ajax_wpt_widget_content'));
19
  add_action('wp_ajax_nopriv_wpt_widget_content', array(&$this, 'ajax_wpt_widget_content'));
20
-
21
  // css
22
  add_action('wp_enqueue_scripts', array(&$this, 'wpt_register_scripts'));
23
  add_action('admin_enqueue_scripts', array(&$this, 'wpt_admin_scripts'));
@@ -25,62 +25,62 @@ if ( !class_exists('wpt_widget') ) {
25
  $widget_ops = array('classname' => 'widget_wpt', 'description' => __('Display popular posts, recent posts, comments, and tags in tabbed format.', 'wp-tab-widget'));
26
  $control_ops = array('width' => 300, 'height' => 350);
27
  parent::__construct('wpt_widget', __('WP Tab Widget by MyThemeShop', 'wp-tab-widget'), $widget_ops, $control_ops);
28
- }
29
-
30
  function wpt_init() {
31
  load_plugin_textdomain('wp-tab-widget', false, dirname(plugin_basename(__FILE__)) . '/languages/' );
32
-
33
  add_image_size( 'wp_review_small', 65, 65, true ); // small thumb
34
  add_image_size( 'wp_review_large', 320, 240, true ); // large thumb
35
  }
36
  function wpt_admin_scripts($hook) {
37
  if ($hook != 'widgets.php')
38
  return;
39
- wp_register_script('wpt_widget_admin', plugins_url('js/wpt-admin.js', __FILE__), array('jquery'));
40
  wp_enqueue_script('wpt_widget_admin');
41
  }
42
- function wpt_register_scripts() {
43
- // JS
44
- wp_register_script('wpt_widget', plugins_url('js/wp-tab-widget.js', __FILE__), array('jquery'));
45
- wp_localize_script( 'wpt_widget', 'wpt',
46
- array( 'ajax_url' => admin_url( 'admin-ajax.php' ))
47
- );
48
- // CSS
49
  wp_register_style('wpt_widget', plugins_url('css/wp-tab-widget.css', __FILE__), true);
50
- }
51
-
52
  function form( $instance ) {
53
- $instance = wp_parse_args( (array) $instance, array(
54
- 'tabs' => array('recent' => 1, 'popular' => 1, 'comments' => 0, 'tags' => 0),
55
- 'tab_order' => array('popular' => 1, 'recent' => 2, 'comments' => 3, 'tags' => 4),
56
- 'allow_pagination' => 1,
57
- 'post_num' => '5',
58
- 'comment_num' => '5',
59
- 'show_thumb' => 1,
60
- 'thumb_size' => 'small',
61
- 'show_date' => 1,
62
- 'show_excerpt' => 0,
63
- 'excerpt_length' => apply_filters( 'wpt_excerpt_length_default', '15' ),
64
- 'show_comment_num' => 0,
65
- 'show_avatar' => 1,
66
  'title_length' => apply_filters( 'wpt_title_length_default', '15' ) ,
67
- 'show_love' => 0,
68
  ) );
69
-
70
  extract($instance);
71
 
72
  ?>
73
  <div class="wpt_options_form">
74
-
75
  <h4><?php _e('Select Tabs', 'wp-tab-widget'); ?></h4>
76
-
77
  <div class="wpt_select_tabs">
78
  <label class="alignleft" style="display: block; width: 50%; margin-bottom: 5px" for="<?php echo $this->get_field_id("tabs"); ?>_popular">
79
  <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("tabs"); ?>_popular" name="<?php echo $this->get_field_name("tabs"); ?>[popular]" value="1" <?php if (isset($tabs['popular'])) { checked( 1, $tabs['popular'], true ); } ?> />
80
  <?php _e( 'Popular Tab', 'wp-tab-widget'); ?>
81
  </label>
82
  <label class="alignleft" style="display: block; width: 50%; margin-bottom: 5px;" for="<?php echo $this->get_field_id("tabs"); ?>_recent">
83
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("tabs"); ?>_recent" name="<?php echo $this->get_field_name("tabs"); ?>[recent]" value="1" <?php if (isset($tabs['recent'])) { checked( 1, $tabs['recent'], true ); } ?> />
84
  <?php _e( 'Recent Tab', 'wp-tab-widget'); ?>
85
  </label>
86
  <label class="alignleft" style="display: block; width: 50%;" for="<?php echo $this->get_field_id("tabs"); ?>_comments">
@@ -93,11 +93,11 @@ if ( !class_exists('wpt_widget') ) {
93
  </label>
94
  </div>
95
  <div class="clear"></div>
96
-
97
  <h4 class="wpt_tab_order_header"><a href="#"><?php _e('Tab Order', 'wp-tab-widget'); ?></a></h4>
98
-
99
  <div class="wpt_tab_order" style="display: none;">
100
-
101
  <label class="alignleft" for="<?php echo $this->get_field_id('tab_order'); ?>_popular" style="width: 50%;">
102
  <input id="<?php echo $this->get_field_id('tab_order'); ?>_popular" name="<?php echo $this->get_field_name('tab_order'); ?>[popular]" type="number" min="1" step="1" value="<?php echo $tab_order['popular']; ?>" style="width: 48px;" />
103
  <?php _e('Popular', 'wp-tab-widget'); ?>
@@ -116,17 +116,17 @@ if ( !class_exists('wpt_widget') ) {
116
  </label>
117
  </div>
118
  <div class="clear"></div>
119
-
120
  <h4 class="wpt_advanced_options_header"><a href="#"><?php _e('Advanced Options', 'wp-tab-widget'); ?></a></h4>
121
-
122
  <div class="wpt_advanced_options" style="display: none;">
123
  <p>
124
- <label for="<?php echo $this->get_field_id("allow_pagination"); ?>">
125
  <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("allow_pagination"); ?>" name="<?php echo $this->get_field_name("allow_pagination"); ?>" value="1" <?php if (isset($allow_pagination)) { checked( 1, $allow_pagination, true ); } ?> />
126
  <?php _e( 'Allow pagination', 'wp-tab-widget'); ?>
127
  </label>
128
  </p>
129
-
130
  <div class="wpt_post_options">
131
 
132
  <p>
@@ -142,153 +142,153 @@ if ( !class_exists('wpt_widget') ) {
142
  <input id="<?php echo $this->get_field_id('title_length'); ?>" name="<?php echo $this->get_field_name('title_length'); ?>" type="number" min="1" step="1" value="<?php echo $title_length; ?>" />
143
  </label>
144
  </p>
145
-
146
  <p>
147
  <label for="<?php echo $this->get_field_id("show_thumb"); ?>">
148
  <input type="checkbox" class="checkbox wpt_show_thumbnails" id="<?php echo $this->get_field_id("show_thumb"); ?>" name="<?php echo $this->get_field_name("show_thumb"); ?>" value="1" <?php if (isset($show_thumb)) { checked( 1, $show_thumb, true ); } ?> />
149
  <?php _e( 'Show post thumbnails', 'wp-tab-widget'); ?>
150
  </label>
151
- </p>
152
-
153
  <p class="wpt_thumbnail_size"<?php echo (empty($show_thumb) ? ' style="display: none;"' : ''); ?>>
154
- <label for="<?php echo $this->get_field_id('thumb_size'); ?>"><?php _e('Thumbnail size:', 'wp-tab-widget'); ?></label>
155
  <select id="<?php echo $this->get_field_id('thumb_size'); ?>" name="<?php echo $this->get_field_name('thumb_size'); ?>" style="margin-left: 12px;">
156
  <option value="small" <?php selected($thumb_size, 'small', true); ?>><?php _e('Small', 'wp-tab-widget'); ?></option>
157
- <option value="large" <?php selected($thumb_size, 'large', true); ?>><?php _e('Large', 'wp-tab-widget'); ?></option>
158
- </select>
159
- </p>
160
-
161
- <p>
162
- <label for="<?php echo $this->get_field_id("show_date"); ?>">
163
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_date"); ?>" name="<?php echo $this->get_field_name("show_date"); ?>" value="1" <?php if (isset($show_date)) { checked( 1, $show_date, true ); } ?> />
164
- <?php _e( 'Show post date', 'wp-tab-widget'); ?>
165
- </label>
 
 
 
 
 
 
 
166
  </p>
167
-
168
- <p>
169
- <label for="<?php echo $this->get_field_id("show_comment_num"); ?>">
170
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_comment_num"); ?>" name="<?php echo $this->get_field_name("show_comment_num"); ?>" value="1" <?php if (isset($show_comment_num)) { checked( 1, $show_comment_num, true ); } ?> />
171
- <?php _e( 'Show number of comments', 'wp-tab-widget'); ?>
172
- </label>
173
- </p>
174
-
175
- <p>
176
- <label for="<?php echo $this->get_field_id("show_excerpt"); ?>">
177
  <input type="checkbox" class="checkbox wpt_show_excerpt" id="<?php echo $this->get_field_id("show_excerpt"); ?>" name="<?php echo $this->get_field_name("show_excerpt"); ?>" value="1" <?php if (isset($show_excerpt)) { checked( 1, $show_excerpt, true ); } ?> />
178
  <?php _e( 'Show post excerpt', 'wp-tab-widget'); ?>
179
- </label>
180
  </p>
181
-
182
  <p class="wpt_excerpt_length"<?php echo (empty($show_excerpt) ? ' style="display: none;"' : ''); ?>>
183
  <label for="<?php echo $this->get_field_id('excerpt_length'); ?>">
184
- <?php _e('Excerpt length (words):', 'wp-tab-widget'); ?>
185
  <br />
186
  <input type="number" min="1" step="1" id="<?php echo $this->get_field_id('excerpt_length'); ?>" name="<?php echo $this->get_field_name('excerpt_length'); ?>" value="<?php echo $excerpt_length; ?>" />
187
  </label>
188
- </p>
189
-
190
  </div>
191
  <div class="clear"></div>
192
-
193
  <div class="wpt_comment_options"<?php echo (empty($tabs['comments']) ? ' style="display: none;"' : ''); ?>>
194
-
195
  <p>
196
  <label for="<?php echo $this->get_field_id('comment_num'); ?>">
197
  <?php _e('Number of comments on Comments Tab:', 'wp-tab-widget'); ?>
198
  <br />
199
  <input type="number" min="1" step="1" id="<?php echo $this->get_field_id('comment_num'); ?>" name="<?php echo $this->get_field_name('comment_num'); ?>" value="<?php echo $comment_num; ?>" />
200
- </label>
201
- </p>
202
-
203
- <p>
204
- <label for="<?php echo $this->get_field_id("show_avatar"); ?>">
205
  <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_avatar"); ?>" name="<?php echo $this->get_field_name("show_avatar"); ?>" value="1" <?php if (isset($show_avatar)) { checked( 1, $show_avatar, true ); } ?> />
206
- <?php _e( 'Show avatars on Comments Tab', 'wp-tab-widget'); ?>
207
- </label>
208
  </p>
209
  </div><!-- .wpt_comment_options -->
210
  </div><!-- .wpt_advanced_options -->
211
  <p>
212
- <label for="<?php echo $this->get_field_id("show_love"); ?>">
213
  <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_love"); ?>" name="<?php echo $this->get_field_name("show_love"); ?>" value="1" <?php if (isset($show_love)) { checked( 1, $show_love, true ); } ?> />
214
  <?php _e( 'Show Some Love (Powered by Tab Widget Pro)', 'wp-tab-widget'); ?>
215
  </label>
216
  </p>
217
  <a href="https://mythemeshop.com/plugins/wp-tab-widget-pro/?utm_source=WP+Tab+Widget+Free&utm_medium=Banner+CPC&utm_content=WP+Tab+Widget+Pro+LP&utm_campaign=WordPressOrg&wpmts" target="_blank"><img src="<?php echo plugin_dir_url( __FILE__ ); ?>/img/wp-tab-widget-pro.jpg" style="width:100%; max-width: 100%; margin-bottom: 10px;"></a>
218
  </div><!-- .wpt_options_form -->
219
- <?php
220
- }
221
-
222
- function update( $new_instance, $old_instance ) {
223
- $instance = $old_instance;
224
- $instance['tabs'] = $new_instance['tabs'];
225
- $instance['tab_order'] = $new_instance['tab_order'];
226
- $instance['allow_pagination'] = $new_instance['allow_pagination'];
227
- $instance['post_num'] = $new_instance['post_num'];
228
- $instance['title_length'] = $new_instance['title_length'];
229
- $instance['comment_num'] = $new_instance['comment_num'];
230
- $instance['show_thumb'] = $new_instance['show_thumb'];
231
- $instance['thumb_size'] = $new_instance['thumb_size'];
232
- $instance['show_date'] = $new_instance['show_date'];
233
- $instance['show_excerpt'] = $new_instance['show_excerpt'];
234
- $instance['excerpt_length'] = $new_instance['excerpt_length'];
235
- $instance['show_comment_num'] = $new_instance['show_comment_num'];
236
- $instance['show_avatar'] = $new_instance['show_avatar'];
237
- $instance['show_love'] = $new_instance['show_love'];
238
- return $instance;
239
- }
240
- function widget( $args, $instance ) {
241
- extract($args);
242
- extract($instance);
243
- wp_enqueue_script('wpt_widget');
244
- wp_enqueue_style('wpt_widget');
245
- if (empty($tabs)) $tabs = array('recent' => 1, 'popular' => 1);
246
- $tabs_count = count($tabs);
247
- if ($tabs_count <= 1) {
248
- $tabs_count = 1;
249
- } elseif($tabs_count > 3) {
250
- $tabs_count = 4;
251
  }
252
-
253
- $available_tabs = array('popular' => __('Popular', 'wp-tab-widget'),
254
- 'recent' => __('Recent', 'wp-tab-widget'),
255
- 'comments' => __('Comments', 'wp-tab-widget'),
256
  'tags' => __('Tags', 'wp-tab-widget'));
257
-
258
  array_multisort($tab_order, $available_tabs);
259
-
260
  $show_love = !empty($instance['show_love']);
261
- ?>
262
- <?php echo $before_widget; ?>
263
- <div class="wpt_widget_content" id="<?php echo $widget_id; ?>_content" data-widget-number="<?php echo esc_attr( $this->number ); ?>">
264
  <ul class="wpt-tabs <?php echo "has-$tabs_count-"; ?>tabs">
265
  <?php foreach ($available_tabs as $tab => $label) { ?>
266
  <?php if (!empty($tabs[$tab])): ?>
267
- <li class="tab_title"><a href="#" id="<?php echo $tab; ?>-tab"><?php echo $label; ?></a></li>
268
  <?php endif; ?>
269
- <?php } ?>
270
- </ul> <!--end .tabs-->
271
- <div class="clear"></div>
272
- <div class="inside">
273
- <?php if (!empty($tabs['popular'])): ?>
274
- <div id="popular-tab-content" class="tab-content">
275
- </div> <!--end #popular-tab-content-->
276
- <?php endif; ?>
277
- <?php if (!empty($tabs['recent'])): ?>
278
- <div id="recent-tab-content" class="tab-content">
279
- </div> <!--end #recent-tab-content-->
280
- <?php endif; ?>
281
- <?php if (!empty($tabs['comments'])): ?>
282
- <div id="comments-tab-content" class="tab-content">
283
- <ul>
284
- </ul>
285
- </div> <!--end #comments-tab-content-->
286
- <?php endif; ?>
287
- <?php if (!empty($tabs['tags'])): ?>
288
- <div id="tags-tab-content" class="tab-content">
289
- <ul>
290
- </ul>
291
- </div> <!--end #tags-tab-content-->
292
  <?php endif; ?>
293
  <div class="clear"></div>
294
  </div> <!--end .inside -->
@@ -297,28 +297,28 @@ if ( !class_exists('wpt_widget') ) {
297
  <?php } ?>
298
  <div class="clear"></div>
299
  </div><!--end #tabber -->
300
- <?php
301
- // inline script
302
- // to support multiple instances per page with different settings
303
-
304
- unset($instance['tabs'], $instance['tab_order']); // unset unneeded
305
- ?>
306
- <script type="text/javascript">
307
- jQuery(function($) {
308
- $('#<?php echo $widget_id; ?>_content').data('args', <?php echo json_encode($instance); ?>);
309
- });
310
- </script>
311
  <?php echo $after_widget; ?>
312
- <?php
313
- }
314
-
315
-
316
- function ajax_wpt_widget_content() {
317
- $tab = $_POST['tab'];
318
- $args = $_POST['args'];
319
- $number = intval( $_POST['widget_number'] );
320
- $page = intval($_POST['page']);
321
- if ($page < 1)
322
  $page = 1;
323
 
324
  if ( !is_array( $args ) || empty( $args ) ) { // json_encode() failed
@@ -331,231 +331,230 @@ if ( !class_exists('wpt_widget') ) {
331
  die( __('Unable to load tab content', 'wp-tab-widget') );
332
  }
333
  }
334
-
335
-
336
- // sanitize args
337
- $post_num = (empty($args['post_num']) ? 5 : intval($args['post_num']));
338
  if ($post_num > 20 || $post_num < 1) { // max 20 posts
339
- $post_num = 5;
340
- }
341
- $comment_num = (empty($args['comment_num']) ? 5 : intval($args['comment_num']));
342
- if ($comment_num > 20 || $comment_num < 1) {
343
- $comment_num = 5;
344
- }
345
- $show_thumb = !empty($args['show_thumb']);
346
- $thumb_size = $args['thumb_size'];
347
- if ($thumb_size != 'small' && $thumb_size != 'large') {
348
- $thumb_size = 'small'; // default
349
- }
350
- $show_date = !empty($args['show_date']);
351
- $show_excerpt = !empty($args['show_excerpt']);
352
- $excerpt_length = intval($args['excerpt_length']);
353
- if ($excerpt_length > 50 || $excerpt_length < 1) {
354
- $excerpt_length = 10;
355
- }
356
- $show_comment_num = !empty($args['show_comment_num']);
357
- $show_avatar = !empty($args['show_avatar']);
358
- $allow_pagination = !empty($args['allow_pagination']);
359
-
360
- $title_length = ! empty($args['title_length']) ? $args['title_length'] : apply_filters( 'wpt_title_length_default', '15' );
361
-
362
- /* ---------- Tab Contents ---------- */
363
- switch ($tab) {
364
-
365
- /* ---------- Popular Posts ---------- */
366
- case "popular":
367
- ?>
368
- <ul>
369
- <?php
370
- $popular = new WP_Query( array('ignore_sticky_posts' => 1, 'posts_per_page' => $post_num, 'post_status' => 'publish', 'orderby' => 'meta_value_num', 'meta_key' => '_wpt_view_count', 'order' => 'desc', 'paged' => $page));
371
- $last_page = $popular->max_num_pages;
372
- while ($popular->have_posts()) : $popular->the_post(); ?>
373
  <li>
374
- <?php if ( $show_thumb == 1 ) : ?>
375
- <div class="wpt_thumbnail wpt_thumb_<?php echo $thumb_size; ?>">
376
- <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>">
377
- <?php if(has_post_thumbnail()): ?>
378
- <?php the_post_thumbnail('wp_review_'.$thumb_size, array('title' => '')); ?>
379
- <?php else: ?>
380
- <img src="<?php echo plugins_url('img/'.$thumb_size.'thumb.png', __FILE__); ?>" alt="<?php the_title(); ?>" class="wp-post-image" />
381
  <?php endif; ?>
382
  </a>
383
- </div>
384
- <?php endif; ?>
385
- <div class="entry-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php echo $this->post_title( $title_length ); ?></a></div>
386
- <?php if ( $show_date == 1 || $show_comment_num == 1) : ?>
387
- <div class="wpt-postmeta">
388
- <?php if ( $show_date == 1 ) : ?>
389
- <?php the_time('F j, Y'); ?>
390
- <?php endif; ?>
391
- <?php if ( $show_date == 1 && $show_comment_num == 1) : ?>
392
- &bull;
393
- <?php endif; ?>
394
- <?php if ( $show_comment_num == 1 ) : ?>
395
- <?php echo comments_number(__('No Comment','wp-tab-widget'), __('One Comment','wp-tab-widget'), '<span class="comments-number">%</span> '.__('Comments','wp-tab-widget'));?>
396
- <?php endif; ?>
397
- </div> <!--end .entry-meta-->
398
  <?php endif; ?>
399
-
400
- <?php if ( $show_excerpt == 1 ) : ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401
  <div class="wpt_excerpt">
402
  <p><?php echo $this->excerpt($excerpt_length); ?></p>
403
  </div>
404
- <?php endif; ?>
405
-
406
- <div class="clear"></div>
407
- </li>
408
- <?php $post_num++; endwhile; wp_reset_query(); ?>
409
  </ul>
410
  <div class="clear"></div>
411
- <?php if ($allow_pagination) : ?>
412
- <?php $this->tab_pagination($page, $last_page); ?>
413
- <?php endif; ?>
414
- <?php
415
- break;
416
-
417
- /* ---------- Recent Posts ---------- */
418
- case "recent":
419
- ?>
420
- <ul>
421
- <?php
422
- $recent = new WP_Query('posts_per_page='. $post_num .'&orderby=post_date&order=desc&post_status=publish&paged='. $page);
423
- $last_page = $recent->max_num_pages;
424
- while ($recent->have_posts()) : $recent->the_post();
425
- ?>
426
  <li>
427
- <?php if ( $show_thumb == 1 ) : ?>
428
- <div class="wpt_thumbnail wpt_thumb_<?php echo $thumb_size; ?>">
429
- <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>">
430
- <?php if(has_post_thumbnail()): ?>
431
- <?php the_post_thumbnail('wp_review_'.$thumb_size, array('title' => '')); ?>
432
- <?php else: ?>
433
- <img src="<?php echo plugins_url('img/'.$thumb_size.'thumb.png', __FILE__); ?>" alt="<?php the_title(); ?>" class="wp-post-image" />
434
  <?php endif; ?>
435
  </a>
436
- </div>
437
- <?php endif; ?>
438
- <div class="entry-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php echo $this->post_title( $title_length ); ?></a></div>
439
- <?php if ( $show_date == 1 || $show_comment_num == 1) : ?>
440
- <div class="wpt-postmeta">
441
- <?php if ( $show_date == 1 ) : ?>
442
- <?php the_time('F j, Y'); ?>
443
- <?php endif; ?>
444
- <?php if ( $show_date == 1 && $show_comment_num == 1) : ?>
445
- &bull;
446
- <?php endif; ?>
447
- <?php if ( $show_comment_num == 1 ) : ?>
448
- <?php echo comments_number(__('No Comment','wp-tab-widget'), __('One Comment','wp-tab-widget'), '<span class="comments-number">%</span> '.__('Comments','wp-tab-widget'));?>
449
- <?php endif; ?>
450
- </div> <!--end .entry-meta-->
451
  <?php endif; ?>
452
-
453
- <?php if ( $show_excerpt == 1 ) : ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
454
  <div class="wpt_excerpt">
455
  <p><?php echo $this->excerpt($excerpt_length); ?></p>
456
  </div>
457
- <?php endif; ?>
458
-
459
- <div class="clear"></div>
460
- </li>
461
- <?php endwhile; wp_reset_query(); ?>
462
  </ul>
463
  <div class="clear"></div>
464
- <?php if ($allow_pagination) : ?>
465
- <?php $this->tab_pagination($page, $last_page); ?>
466
- <?php endif; ?>
467
- <?php
468
- break;
469
-
470
- /* ---------- Latest Comments ---------- */
471
- case "comments":
472
- ?>
473
- <ul>
474
- <?php
475
- $no_comments = false;
476
- $avatar_size = 65;
477
- $comment_length = 90; // max length for comments
478
  $comment_args = apply_filters(
479
  'wpt_comments_tab_args',
480
  array(
481
  'type' => 'comments',
482
  'status' => 'approve'
483
  )
484
- );
485
  $comments_total = new WP_Comment_Query();
486
  $comments_total_number = $comments_total->query( array_merge( array('count' => 1 ), $comment_args ) );
487
  $last_page = (int) ceil($comments_total_number / $comment_num);
488
  $comments_query = new WP_Comment_Query();
489
  $offset = ($page-1) * $comment_num;
490
  $comments = $comments_query->query( array_merge( array( 'number' => $comment_num, 'offset' => $offset ), $comment_args ) );
491
- if ( $comments ) : foreach ( $comments as $comment ) : ?>
492
- <li>
493
- <?php if ($show_avatar) : ?>
494
  <div class="wpt_avatar">
495
  <a href="<?php echo get_comment_link($comment->comment_ID); ?>">
496
- <?php echo get_avatar( $comment->comment_author_email, $avatar_size ); ?>
497
- </a>
498
- </div>
499
- <?php endif; ?>
500
  <div class="wpt_comment_meta">
501
- <a href="<?php echo get_comment_link($comment->comment_ID); ?>">
502
- <span class="wpt_comment_author"><?php echo get_comment_author( $comment->comment_ID ); ?> </span> - <span class="wpt_comment_post"><?php echo get_the_title($comment->comment_post_ID); ?></span>
503
  </a>
504
- </div>
505
- <div class="wpt_comment_content">
506
  <p><?php echo $this->truncate(strip_tags(apply_filters( 'get_comment_text', $comment->comment_content )), $comment_length);?></p>
507
- </div>
508
- <div class="clear"></div>
509
- </li>
510
- <?php endforeach; else : ?>
511
- <li>
512
- <div class="no-comments"><?php _e('No comments yet.', 'wp-tab-widget'); ?></div>
513
- </li>
514
- <?php $no_comments = true;
515
- endif; ?>
516
- </ul>
517
- <?php if ($allow_pagination && !$no_comments) : ?>
518
- <?php $this->tab_pagination($page, $last_page); ?>
519
- <?php endif; ?>
520
- <?php
521
- break;
522
-
523
- /* ---------- Tags ---------- */
524
- case "tags":
525
- ?>
526
- <ul>
527
- <?php
528
- $tags = get_tags(array('get'=>'all'));
529
- if($tags) {
530
- foreach ($tags as $tag): ?>
531
- <li><a href="<?php echo get_term_link($tag); ?>"><?php echo $tag->name; ?></a></li>
532
- <?php
533
- endforeach;
534
- } else {
535
- _e('No tags created.', 'wp-tab-widget');
536
- }
537
- ?>
538
- </ul>
539
- <?php
540
- break;
541
- }
542
- die(); // required to return a proper result
543
- }
544
- function tab_pagination($page, $last_page) {
545
- ?>
546
- <div class="wpt-pagination">
547
- <?php if ($page > 1) : ?>
548
- <a href="#" class="previous"><span><?php _e('&laquo; Previous', 'wp-tab-widget'); ?></span></a>
549
- <?php endif; ?>
550
- <?php if ($page != $last_page) : ?>
551
- <a href="#" class="next"><span><?php _e('Next &raquo;', 'wp-tab-widget'); ?></span></a>
552
- <?php endif; ?>
553
- </div>
554
  <div class="clear"></div>
555
- <input type="hidden" class="page_num" name="page_num" value="<?php echo $page; ?>" />
556
- <?php
557
  }
558
-
559
  function excerpt($limit = 10) {
560
  $limit++;
561
  $excerpt = explode(' ', get_the_excerpt(), $limit);
@@ -596,13 +595,13 @@ add_filter('the_content', 'wpt_view_count_js'); // outputs JS for AJAX call on s
596
  add_action('wp_ajax_wpt_view_count', 'ajax_wpt_view_count');
597
  add_action('wp_ajax_nopriv_wpt_view_count','ajax_wpt_view_count');
598
  // prevent additional ajax call if theme has view counter already
599
- add_action('mts_view_count_after_update', 'wpt_update_view_count');
600
 
601
  function wpt_view_count_js( $content ) {
602
  global $post;
603
  $id = $post->ID;
604
  $use_ajax = apply_filters( 'mts_view_count_cache_support', true );
605
-
606
  $exclude_admins = apply_filters( 'mts_view_count_exclude_admins', false ); // pass in true or a user capaibility
607
  if ($exclude_admins === true) $exclude_admins = 'edit_posts';
608
  if ($exclude_admins && current_user_can( $exclude_admins )) return $content; // do not count post views here
@@ -611,7 +610,7 @@ function wpt_view_count_js( $content ) {
611
  if ($use_ajax) { // prevent additional ajax call if theme has view counter already
612
  // enqueue jquery
613
  wp_enqueue_script( 'jquery' );
614
-
615
  $url = admin_url( 'admin-ajax.php' );
616
  $content .= "
617
  <script type=\"text/javascript\">
@@ -684,7 +683,7 @@ function wp_tab_widget_admin_notice() {
684
  $user_id = $current_user->ID;
685
  /* Check that the user hasn't already clicked to ignore the message */
686
  if ( ! get_user_meta($user_id, 'wp_tab_widget_ignore_notice') ) {
687
- echo '<div class="updated notice-info wp-tab-widget-pro-notice" style="position:relative;"><p>';
688
  printf(__('Like WP Tab Widget? You will <strong>LOVE WP Tab Widget Pro</strong>!','wp-tab-widget').'<a href="https://mythemeshop.com/plugins/wp-tab-widget-pro/?utm_source=WP+Tab+Widget+Free&utm_medium=Notification+Link&utm_content=WP+Tab+Widget+Pro+LP&utm_campaign=WordPressOrg&wpmts" target="_blank">&nbsp;'.__('Click here for all the exciting features.','wp-tab-widget').'</a><a href="%1$s" class="dashicons dashicons-dismiss dashicons-dismiss-icon" style="position: absolute; top: 8px; right: 8px; color: #222; opacity: 0.4; text-decoration: none !important;"></a>', '?wp_tab_widget_notice_ignore=0');
689
  echo "</p></div>";
690
  }
4
  Plugin URI: http://mythemeshop.com/plugins/wp-tab-widget/
5
  Description: WP Tab Widget is the AJAXified plugin which loads content by demand, and thus it makes the plugin incredibly lightweight.
6
  Author: MyThemeShop
7
+ Version: 1.2.8
8
  Author URI: http://mythemeshop.com/
9
  */
10
  if ( !class_exists('wpt_widget') ) {
11
  class wpt_widget extends WP_Widget {
12
  function __construct() {
13
+
14
  // add image sizes and load language file
15
  add_action( 'init', array(&$this, 'wpt_init') );
16
+
17
  // ajax functions
18
  add_action('wp_ajax_wpt_widget_content', array(&$this, 'ajax_wpt_widget_content'));
19
  add_action('wp_ajax_nopriv_wpt_widget_content', array(&$this, 'ajax_wpt_widget_content'));
20
+
21
  // css
22
  add_action('wp_enqueue_scripts', array(&$this, 'wpt_register_scripts'));
23
  add_action('admin_enqueue_scripts', array(&$this, 'wpt_admin_scripts'));
25
  $widget_ops = array('classname' => 'widget_wpt', 'description' => __('Display popular posts, recent posts, comments, and tags in tabbed format.', 'wp-tab-widget'));
26
  $control_ops = array('width' => 300, 'height' => 350);
27
  parent::__construct('wpt_widget', __('WP Tab Widget by MyThemeShop', 'wp-tab-widget'), $widget_ops, $control_ops);
28
+ }
29
+
30
  function wpt_init() {
31
  load_plugin_textdomain('wp-tab-widget', false, dirname(plugin_basename(__FILE__)) . '/languages/' );
32
+
33
  add_image_size( 'wp_review_small', 65, 65, true ); // small thumb
34
  add_image_size( 'wp_review_large', 320, 240, true ); // large thumb
35
  }
36
  function wpt_admin_scripts($hook) {
37
  if ($hook != 'widgets.php')
38
  return;
39
+ wp_register_script('wpt_widget_admin', plugins_url('js/wpt-admin.js', __FILE__), array('jquery'));
40
  wp_enqueue_script('wpt_widget_admin');
41
  }
42
+ function wpt_register_scripts() {
43
+ // JS
44
+ wp_register_script('wpt_widget', plugins_url('js/wp-tab-widget.js', __FILE__), array('jquery'));
45
+ wp_localize_script( 'wpt_widget', 'wpt',
46
+ array( 'ajax_url' => admin_url( 'admin-ajax.php' ))
47
+ );
48
+ // CSS
49
  wp_register_style('wpt_widget', plugins_url('css/wp-tab-widget.css', __FILE__), true);
50
+ }
51
+
52
  function form( $instance ) {
53
+ $instance = wp_parse_args( (array) $instance, array(
54
+ 'tabs' => array('recent' => 1, 'popular' => 1, 'comments' => 0, 'tags' => 0),
55
+ 'tab_order' => array('popular' => 1, 'recent' => 2, 'comments' => 3, 'tags' => 4),
56
+ 'allow_pagination' => 1,
57
+ 'post_num' => '5',
58
+ 'comment_num' => '5',
59
+ 'show_thumb' => 1,
60
+ 'thumb_size' => 'small',
61
+ 'show_date' => 1,
62
+ 'show_excerpt' => 0,
63
+ 'excerpt_length' => apply_filters( 'wpt_excerpt_length_default', '15' ),
64
+ 'show_comment_num' => 0,
65
+ 'show_avatar' => 1,
66
  'title_length' => apply_filters( 'wpt_title_length_default', '15' ) ,
67
+ 'show_love' => 0,
68
  ) );
69
+
70
  extract($instance);
71
 
72
  ?>
73
  <div class="wpt_options_form">
74
+
75
  <h4><?php _e('Select Tabs', 'wp-tab-widget'); ?></h4>
76
+
77
  <div class="wpt_select_tabs">
78
  <label class="alignleft" style="display: block; width: 50%; margin-bottom: 5px" for="<?php echo $this->get_field_id("tabs"); ?>_popular">
79
  <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("tabs"); ?>_popular" name="<?php echo $this->get_field_name("tabs"); ?>[popular]" value="1" <?php if (isset($tabs['popular'])) { checked( 1, $tabs['popular'], true ); } ?> />
80
  <?php _e( 'Popular Tab', 'wp-tab-widget'); ?>
81
  </label>
82
  <label class="alignleft" style="display: block; width: 50%; margin-bottom: 5px;" for="<?php echo $this->get_field_id("tabs"); ?>_recent">
83
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("tabs"); ?>_recent" name="<?php echo $this->get_field_name("tabs"); ?>[recent]" value="1" <?php if (isset($tabs['recent'])) { checked( 1, $tabs['recent'], true ); } ?> />
84
  <?php _e( 'Recent Tab', 'wp-tab-widget'); ?>
85
  </label>
86
  <label class="alignleft" style="display: block; width: 50%;" for="<?php echo $this->get_field_id("tabs"); ?>_comments">
93
  </label>
94
  </div>
95
  <div class="clear"></div>
96
+
97
  <h4 class="wpt_tab_order_header"><a href="#"><?php _e('Tab Order', 'wp-tab-widget'); ?></a></h4>
98
+
99
  <div class="wpt_tab_order" style="display: none;">
100
+
101
  <label class="alignleft" for="<?php echo $this->get_field_id('tab_order'); ?>_popular" style="width: 50%;">
102
  <input id="<?php echo $this->get_field_id('tab_order'); ?>_popular" name="<?php echo $this->get_field_name('tab_order'); ?>[popular]" type="number" min="1" step="1" value="<?php echo $tab_order['popular']; ?>" style="width: 48px;" />
103
  <?php _e('Popular', 'wp-tab-widget'); ?>
116
  </label>
117
  </div>
118
  <div class="clear"></div>
119
+
120
  <h4 class="wpt_advanced_options_header"><a href="#"><?php _e('Advanced Options', 'wp-tab-widget'); ?></a></h4>
121
+
122
  <div class="wpt_advanced_options" style="display: none;">
123
  <p>
124
+ <label for="<?php echo $this->get_field_id("allow_pagination"); ?>">
125
  <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("allow_pagination"); ?>" name="<?php echo $this->get_field_name("allow_pagination"); ?>" value="1" <?php if (isset($allow_pagination)) { checked( 1, $allow_pagination, true ); } ?> />
126
  <?php _e( 'Allow pagination', 'wp-tab-widget'); ?>
127
  </label>
128
  </p>
129
+
130
  <div class="wpt_post_options">
131
 
132
  <p>
142
  <input id="<?php echo $this->get_field_id('title_length'); ?>" name="<?php echo $this->get_field_name('title_length'); ?>" type="number" min="1" step="1" value="<?php echo $title_length; ?>" />
143
  </label>
144
  </p>
145
+
146
  <p>
147
  <label for="<?php echo $this->get_field_id("show_thumb"); ?>">
148
  <input type="checkbox" class="checkbox wpt_show_thumbnails" id="<?php echo $this->get_field_id("show_thumb"); ?>" name="<?php echo $this->get_field_name("show_thumb"); ?>" value="1" <?php if (isset($show_thumb)) { checked( 1, $show_thumb, true ); } ?> />
149
  <?php _e( 'Show post thumbnails', 'wp-tab-widget'); ?>
150
  </label>
151
+ </p>
152
+
153
  <p class="wpt_thumbnail_size"<?php echo (empty($show_thumb) ? ' style="display: none;"' : ''); ?>>
154
+ <label for="<?php echo $this->get_field_id('thumb_size'); ?>"><?php _e('Thumbnail size:', 'wp-tab-widget'); ?></label>
155
  <select id="<?php echo $this->get_field_id('thumb_size'); ?>" name="<?php echo $this->get_field_name('thumb_size'); ?>" style="margin-left: 12px;">
156
  <option value="small" <?php selected($thumb_size, 'small', true); ?>><?php _e('Small', 'wp-tab-widget'); ?></option>
157
+ <option value="large" <?php selected($thumb_size, 'large', true); ?>><?php _e('Large', 'wp-tab-widget'); ?></option>
158
+ </select>
159
+ </p>
160
+
161
+ <p>
162
+ <label for="<?php echo $this->get_field_id("show_date"); ?>">
163
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_date"); ?>" name="<?php echo $this->get_field_name("show_date"); ?>" value="1" <?php if (isset($show_date)) { checked( 1, $show_date, true ); } ?> />
164
+ <?php _e( 'Show post date', 'wp-tab-widget'); ?>
165
+ </label>
166
+ </p>
167
+
168
+ <p>
169
+ <label for="<?php echo $this->get_field_id("show_comment_num"); ?>">
170
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_comment_num"); ?>" name="<?php echo $this->get_field_name("show_comment_num"); ?>" value="1" <?php if (isset($show_comment_num)) { checked( 1, $show_comment_num, true ); } ?> />
171
+ <?php _e( 'Show number of comments', 'wp-tab-widget'); ?>
172
+ </label>
173
  </p>
174
+
175
+ <p>
176
+ <label for="<?php echo $this->get_field_id("show_excerpt"); ?>">
 
 
 
 
 
 
 
177
  <input type="checkbox" class="checkbox wpt_show_excerpt" id="<?php echo $this->get_field_id("show_excerpt"); ?>" name="<?php echo $this->get_field_name("show_excerpt"); ?>" value="1" <?php if (isset($show_excerpt)) { checked( 1, $show_excerpt, true ); } ?> />
178
  <?php _e( 'Show post excerpt', 'wp-tab-widget'); ?>
179
+ </label>
180
  </p>
181
+
182
  <p class="wpt_excerpt_length"<?php echo (empty($show_excerpt) ? ' style="display: none;"' : ''); ?>>
183
  <label for="<?php echo $this->get_field_id('excerpt_length'); ?>">
184
+ <?php _e('Excerpt length (words):', 'wp-tab-widget'); ?>
185
  <br />
186
  <input type="number" min="1" step="1" id="<?php echo $this->get_field_id('excerpt_length'); ?>" name="<?php echo $this->get_field_name('excerpt_length'); ?>" value="<?php echo $excerpt_length; ?>" />
187
  </label>
188
+ </p>
189
+
190
  </div>
191
  <div class="clear"></div>
192
+
193
  <div class="wpt_comment_options"<?php echo (empty($tabs['comments']) ? ' style="display: none;"' : ''); ?>>
194
+
195
  <p>
196
  <label for="<?php echo $this->get_field_id('comment_num'); ?>">
197
  <?php _e('Number of comments on Comments Tab:', 'wp-tab-widget'); ?>
198
  <br />
199
  <input type="number" min="1" step="1" id="<?php echo $this->get_field_id('comment_num'); ?>" name="<?php echo $this->get_field_name('comment_num'); ?>" value="<?php echo $comment_num; ?>" />
200
+ </label>
201
+ </p>
202
+
203
+ <p>
204
+ <label for="<?php echo $this->get_field_id("show_avatar"); ?>">
205
  <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_avatar"); ?>" name="<?php echo $this->get_field_name("show_avatar"); ?>" value="1" <?php if (isset($show_avatar)) { checked( 1, $show_avatar, true ); } ?> />
206
+ <?php _e( 'Show avatars on Comments Tab', 'wp-tab-widget'); ?>
207
+ </label>
208
  </p>
209
  </div><!-- .wpt_comment_options -->
210
  </div><!-- .wpt_advanced_options -->
211
  <p>
212
+ <label for="<?php echo $this->get_field_id("show_love"); ?>">
213
  <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_love"); ?>" name="<?php echo $this->get_field_name("show_love"); ?>" value="1" <?php if (isset($show_love)) { checked( 1, $show_love, true ); } ?> />
214
  <?php _e( 'Show Some Love (Powered by Tab Widget Pro)', 'wp-tab-widget'); ?>
215
  </label>
216
  </p>
217
  <a href="https://mythemeshop.com/plugins/wp-tab-widget-pro/?utm_source=WP+Tab+Widget+Free&utm_medium=Banner+CPC&utm_content=WP+Tab+Widget+Pro+LP&utm_campaign=WordPressOrg&wpmts" target="_blank"><img src="<?php echo plugin_dir_url( __FILE__ ); ?>/img/wp-tab-widget-pro.jpg" style="width:100%; max-width: 100%; margin-bottom: 10px;"></a>
218
  </div><!-- .wpt_options_form -->
219
+ <?php
220
+ }
221
+
222
+ function update( $new_instance, $old_instance ) {
223
+ $instance = $old_instance;
224
+ $instance['tabs'] = $new_instance['tabs'];
225
+ $instance['tab_order'] = $new_instance['tab_order'];
226
+ $instance['allow_pagination'] = $new_instance['allow_pagination'];
227
+ $instance['post_num'] = $new_instance['post_num'];
228
+ $instance['title_length'] = $new_instance['title_length'];
229
+ $instance['comment_num'] = $new_instance['comment_num'];
230
+ $instance['show_thumb'] = $new_instance['show_thumb'];
231
+ $instance['thumb_size'] = $new_instance['thumb_size'];
232
+ $instance['show_date'] = $new_instance['show_date'];
233
+ $instance['show_excerpt'] = $new_instance['show_excerpt'];
234
+ $instance['excerpt_length'] = $new_instance['excerpt_length'];
235
+ $instance['show_comment_num'] = $new_instance['show_comment_num'];
236
+ $instance['show_avatar'] = $new_instance['show_avatar'];
237
+ $instance['show_love'] = $new_instance['show_love'];
238
+ return $instance;
239
+ }
240
+ function widget( $args, $instance ) {
241
+ extract($args);
242
+ extract($instance);
243
+ wp_enqueue_script('wpt_widget');
244
+ wp_enqueue_style('wpt_widget');
245
+ if (empty($tabs)) $tabs = array('recent' => 1, 'popular' => 1);
246
+ $tabs_count = count($tabs);
247
+ if ($tabs_count <= 1) {
248
+ $tabs_count = 1;
249
+ } elseif($tabs_count > 3) {
250
+ $tabs_count = 4;
251
  }
252
+
253
+ $available_tabs = array('popular' => __('Popular', 'wp-tab-widget'),
254
+ 'recent' => __('Recent', 'wp-tab-widget'),
255
+ 'comments' => __('Comments', 'wp-tab-widget'),
256
  'tags' => __('Tags', 'wp-tab-widget'));
257
+
258
  array_multisort($tab_order, $available_tabs);
259
+
260
  $show_love = !empty($instance['show_love']);
261
+ ?>
262
+ <?php echo $before_widget; ?>
263
+ <div class="wpt_widget_content" id="<?php echo $widget_id; ?>_content" data-widget-number="<?php echo esc_attr( $this->number ); ?>">
264
  <ul class="wpt-tabs <?php echo "has-$tabs_count-"; ?>tabs">
265
  <?php foreach ($available_tabs as $tab => $label) { ?>
266
  <?php if (!empty($tabs[$tab])): ?>
267
+ <li class="tab_title"><a href="#" id="<?php echo $tab; ?>-tab"><?php echo $label; ?></a></li>
268
  <?php endif; ?>
269
+ <?php } ?>
270
+ </ul> <!--end .tabs-->
271
+ <div class="clear"></div>
272
+ <div class="inside">
273
+ <?php if (!empty($tabs['popular'])): ?>
274
+ <div id="popular-tab-content" class="tab-content">
275
+ </div> <!--end #popular-tab-content-->
276
+ <?php endif; ?>
277
+ <?php if (!empty($tabs['recent'])): ?>
278
+ <div id="recent-tab-content" class="tab-content">
279
+ </div> <!--end #recent-tab-content-->
280
+ <?php endif; ?>
281
+ <?php if (!empty($tabs['comments'])): ?>
282
+ <div id="comments-tab-content" class="tab-content">
283
+ <ul>
284
+ </ul>
285
+ </div> <!--end #comments-tab-content-->
286
+ <?php endif; ?>
287
+ <?php if (!empty($tabs['tags'])): ?>
288
+ <div id="tags-tab-content" class="tab-content">
289
+ <ul>
290
+ </ul>
291
+ </div> <!--end #tags-tab-content-->
292
  <?php endif; ?>
293
  <div class="clear"></div>
294
  </div> <!--end .inside -->
297
  <?php } ?>
298
  <div class="clear"></div>
299
  </div><!--end #tabber -->
300
+ <?php
301
+ // inline script
302
+ // to support multiple instances per page with different settings
303
+
304
+ unset($instance['tabs'], $instance['tab_order']); // unset unneeded
305
+ ?>
306
+ <script type="text/javascript">
307
+ jQuery(function($) {
308
+ $('#<?php echo $widget_id; ?>_content').data('args', <?php echo json_encode($instance); ?>);
309
+ });
310
+ </script>
311
  <?php echo $after_widget; ?>
312
+ <?php
313
+ }
314
+
315
+
316
+ function ajax_wpt_widget_content() {
317
+ $tab = $_POST['tab'];
318
+ $args = $_POST['args'];
319
+ $number = isset( $_POST['widget_number'] ) ? intval( $_POST['widget_number'] ) : '';
320
+ $page = isset( $_POST['page'] ) ? intval( $_POST['page'] ) : '';
321
+ if ($page < 1)
322
  $page = 1;
323
 
324
  if ( !is_array( $args ) || empty( $args ) ) { // json_encode() failed
331
  die( __('Unable to load tab content', 'wp-tab-widget') );
332
  }
333
  }
334
+
335
+
336
+ // sanitize args
337
+ $post_num = (!isset($args['post_num']) ? 5 : intval($args['post_num']));
338
  if ($post_num > 20 || $post_num < 1) { // max 20 posts
339
+ $post_num = 5;
340
+ }
341
+ $comment_num = (!isset($args['comment_num']) ? 5 : intval($args['comment_num']));
342
+ if ($comment_num > 20 || $comment_num < 1) {
343
+ $comment_num = 5;
344
+ }
345
+ $show_thumb = isset( $args['show_thumb'] ) ? $args['show_thumb'] : 0;
346
+ $thumb_size = isset( $args['thumb_size'] ) ? $args['thumb_size'] : 'small';
347
+ if ($thumb_size != 'small' && $thumb_size != 'large') {
348
+ $thumb_size = 'small'; // default
349
+ }
350
+ $show_date = isset( $args['show_date'] ) ? $args['show_date'] : 1;
351
+ $show_excerpt = isset( $args['show_excerpt'] ) ? $args['show_excerpt'] : 1;
352
+ $excerpt_length = isset( $args['excerpt_length'] ) ? intval( $args['excerpt_length'] ) : 15;
353
+ if ($excerpt_length > 50 || $excerpt_length < 1) {
354
+ $excerpt_length = 10;
355
+ }
356
+ $show_comment_num = isset( $args['show_comment_num'] ) ? $args['show_comment_num'] : 0;
357
+ $show_avatar = isset( $args['show_avatar'] ) ? $args['show_avatar'] : 0;
358
+ $allow_pagination = isset( $args['allow_pagination'] ) ? $args['allow_pagination'] : 0;
359
+ $title_length = !isset($args['title_length']) ? $args['title_length'] : apply_filters( 'wpt_title_length_default', '15' );
360
+
361
+ /* ---------- Tab Contents ---------- */
362
+ switch ($tab) {
363
+
364
+ /* ---------- Popular Posts ---------- */
365
+ case "popular":
366
+ ?>
367
+ <ul>
368
+ <?php
369
+ $popular = new WP_Query( array('ignore_sticky_posts' => 1, 'posts_per_page' => $post_num, 'post_status' => 'publish', 'orderby' => 'meta_value_num', 'meta_key' => '_wpt_view_count', 'order' => 'desc', 'paged' => $page));
370
+ $last_page = $popular->max_num_pages;
371
+ while ($popular->have_posts()) : $popular->the_post(); ?>
 
372
  <li>
373
+ <?php if ( $show_thumb == 1 ) : ?>
374
+ <div class="wpt_thumbnail wpt_thumb_<?php echo $thumb_size; ?>">
375
+ <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>">
376
+ <?php if(has_post_thumbnail()): ?>
377
+ <?php the_post_thumbnail('wp_review_'.$thumb_size, array('title' => '')); ?>
378
+ <?php else: ?>
379
+ <img src="<?php echo plugins_url('img/'.$thumb_size.'thumb.png', __FILE__); ?>" alt="<?php the_title(); ?>" class="wp-post-image" />
380
  <?php endif; ?>
381
  </a>
382
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
  <?php endif; ?>
384
+ <div class="entry-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php echo $this->post_title( $title_length ); ?></a></div>
385
+ <?php if ( $show_date == 1 || $show_comment_num == 1) : ?>
386
+ <div class="wpt-postmeta">
387
+ <?php if ( $show_date == 1 ) : ?>
388
+ <?php the_time('F j, Y'); ?>
389
+ <?php endif; ?>
390
+ <?php if ( $show_date == 1 && $show_comment_num == 1) : ?>
391
+ &bull;
392
+ <?php endif; ?>
393
+ <?php if ( $show_comment_num == 1 ) : ?>
394
+ <?php echo comments_number(__('No Comment','wp-tab-widget'), __('One Comment','wp-tab-widget'), '<span class="comments-number">%</span> '.__('Comments','wp-tab-widget'));?>
395
+ <?php endif; ?>
396
+ </div> <!--end .entry-meta-->
397
+ <?php endif; ?>
398
+
399
+ <?php if ( $show_excerpt == 1 ) : ?>
400
  <div class="wpt_excerpt">
401
  <p><?php echo $this->excerpt($excerpt_length); ?></p>
402
  </div>
403
+ <?php endif; ?>
404
+
405
+ <div class="clear"></div>
406
+ </li>
407
+ <?php $post_num++; endwhile; wp_reset_query(); ?>
408
  </ul>
409
  <div class="clear"></div>
410
+ <?php if ($allow_pagination) : ?>
411
+ <?php $this->tab_pagination($page, $last_page); ?>
412
+ <?php endif; ?>
413
+ <?php
414
+ break;
415
+
416
+ /* ---------- Recent Posts ---------- */
417
+ case "recent":
418
+ ?>
419
+ <ul>
420
+ <?php
421
+ $recent = new WP_Query('posts_per_page='. $post_num .'&orderby=post_date&order=desc&post_status=publish&paged='. $page);
422
+ $last_page = $recent->max_num_pages;
423
+ while ($recent->have_posts()) : $recent->the_post();
424
+ ?>
425
  <li>
426
+ <?php if ( $show_thumb == 1 ) : ?>
427
+ <div class="wpt_thumbnail wpt_thumb_<?php echo $thumb_size; ?>">
428
+ <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>">
429
+ <?php if(has_post_thumbnail()): ?>
430
+ <?php the_post_thumbnail('wp_review_'.$thumb_size, array('title' => '')); ?>
431
+ <?php else: ?>
432
+ <img src="<?php echo plugins_url('img/'.$thumb_size.'thumb.png', __FILE__); ?>" alt="<?php the_title(); ?>" class="wp-post-image" />
433
  <?php endif; ?>
434
  </a>
435
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
  <?php endif; ?>
437
+ <div class="entry-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php echo $this->post_title( $title_length ); ?></a></div>
438
+ <?php if ( $show_date == 1 || $show_comment_num == 1) : ?>
439
+ <div class="wpt-postmeta">
440
+ <?php if ( $show_date == 1 ) : ?>
441
+ <?php the_time('F j, Y'); ?>
442
+ <?php endif; ?>
443
+ <?php if ( $show_date == 1 && $show_comment_num == 1) : ?>
444
+ &bull;
445
+ <?php endif; ?>
446
+ <?php if ( $show_comment_num == 1 ) : ?>
447
+ <?php echo comments_number(__('No Comment','wp-tab-widget'), __('One Comment','wp-tab-widget'), '<span class="comments-number">%</span> '.__('Comments','wp-tab-widget'));?>
448
+ <?php endif; ?>
449
+ </div> <!--end .entry-meta-->
450
+ <?php endif; ?>
451
+
452
+ <?php if ( $show_excerpt == 1 ) : ?>
453
  <div class="wpt_excerpt">
454
  <p><?php echo $this->excerpt($excerpt_length); ?></p>
455
  </div>
456
+ <?php endif; ?>
457
+
458
+ <div class="clear"></div>
459
+ </li>
460
+ <?php endwhile; wp_reset_query(); ?>
461
  </ul>
462
  <div class="clear"></div>
463
+ <?php if ($allow_pagination) : ?>
464
+ <?php $this->tab_pagination($page, $last_page); ?>
465
+ <?php endif; ?>
466
+ <?php
467
+ break;
468
+
469
+ /* ---------- Latest Comments ---------- */
470
+ case "comments":
471
+ ?>
472
+ <ul>
473
+ <?php
474
+ $no_comments = false;
475
+ $avatar_size = 65;
476
+ $comment_length = 90; // max length for comments
477
  $comment_args = apply_filters(
478
  'wpt_comments_tab_args',
479
  array(
480
  'type' => 'comments',
481
  'status' => 'approve'
482
  )
483
+ );
484
  $comments_total = new WP_Comment_Query();
485
  $comments_total_number = $comments_total->query( array_merge( array('count' => 1 ), $comment_args ) );
486
  $last_page = (int) ceil($comments_total_number / $comment_num);
487
  $comments_query = new WP_Comment_Query();
488
  $offset = ($page-1) * $comment_num;
489
  $comments = $comments_query->query( array_merge( array( 'number' => $comment_num, 'offset' => $offset ), $comment_args ) );
490
+ if ( $comments ) : foreach ( $comments as $comment ) : ?>
491
+ <li>
492
+ <?php if ($show_avatar) : ?>
493
  <div class="wpt_avatar">
494
  <a href="<?php echo get_comment_link($comment->comment_ID); ?>">
495
+ <?php echo get_avatar( $comment->comment_author_email, $avatar_size ); ?>
496
+ </a>
497
+ </div>
498
+ <?php endif; ?>
499
  <div class="wpt_comment_meta">
500
+ <a href="<?php echo get_comment_link($comment->comment_ID); ?>">
501
+ <span class="wpt_comment_author"><?php echo get_comment_author( $comment->comment_ID ); ?> </span> - <span class="wpt_comment_post"><?php echo get_the_title($comment->comment_post_ID); ?></span>
502
  </a>
503
+ </div>
504
+ <div class="wpt_comment_content">
505
  <p><?php echo $this->truncate(strip_tags(apply_filters( 'get_comment_text', $comment->comment_content )), $comment_length);?></p>
506
+ </div>
507
+ <div class="clear"></div>
508
+ </li>
509
+ <?php endforeach; else : ?>
510
+ <li>
511
+ <div class="no-comments"><?php _e('No comments yet.', 'wp-tab-widget'); ?></div>
512
+ </li>
513
+ <?php $no_comments = true;
514
+ endif; ?>
515
+ </ul>
516
+ <?php if ($allow_pagination && !$no_comments) : ?>
517
+ <?php $this->tab_pagination($page, $last_page); ?>
518
+ <?php endif; ?>
519
+ <?php
520
+ break;
521
+
522
+ /* ---------- Tags ---------- */
523
+ case "tags":
524
+ ?>
525
+ <ul>
526
+ <?php
527
+ $tags = get_tags(array('get'=>'all'));
528
+ if($tags) {
529
+ foreach ($tags as $tag): ?>
530
+ <li><a href="<?php echo get_term_link($tag); ?>"><?php echo $tag->name; ?></a></li>
531
+ <?php
532
+ endforeach;
533
+ } else {
534
+ _e('No tags created.', 'wp-tab-widget');
535
+ }
536
+ ?>
537
+ </ul>
538
+ <?php
539
+ break;
540
+ }
541
+ die(); // required to return a proper result
542
+ }
543
+ function tab_pagination($page, $last_page) {
544
+ ?>
545
+ <div class="wpt-pagination">
546
+ <?php if ($page > 1) : ?>
547
+ <a href="#" class="previous"><span><?php _e('&laquo; Previous', 'wp-tab-widget'); ?></span></a>
548
+ <?php endif; ?>
549
+ <?php if ($page != $last_page) : ?>
550
+ <a href="#" class="next"><span><?php _e('Next &raquo;', 'wp-tab-widget'); ?></span></a>
551
+ <?php endif; ?>
552
+ </div>
553
  <div class="clear"></div>
554
+ <input type="hidden" class="page_num" name="page_num" value="<?php echo $page; ?>" />
555
+ <?php
556
  }
557
+
558
  function excerpt($limit = 10) {
559
  $limit++;
560
  $excerpt = explode(' ', get_the_excerpt(), $limit);
595
  add_action('wp_ajax_wpt_view_count', 'ajax_wpt_view_count');
596
  add_action('wp_ajax_nopriv_wpt_view_count','ajax_wpt_view_count');
597
  // prevent additional ajax call if theme has view counter already
598
+ add_action('mts_view_count_after_update', 'wpt_update_view_count');
599
 
600
  function wpt_view_count_js( $content ) {
601
  global $post;
602
  $id = $post->ID;
603
  $use_ajax = apply_filters( 'mts_view_count_cache_support', true );
604
+
605
  $exclude_admins = apply_filters( 'mts_view_count_exclude_admins', false ); // pass in true or a user capaibility
606
  if ($exclude_admins === true) $exclude_admins = 'edit_posts';
607
  if ($exclude_admins && current_user_can( $exclude_admins )) return $content; // do not count post views here
610
  if ($use_ajax) { // prevent additional ajax call if theme has view counter already
611
  // enqueue jquery
612
  wp_enqueue_script( 'jquery' );
613
+
614
  $url = admin_url( 'admin-ajax.php' );
615
  $content .= "
616
  <script type=\"text/javascript\">
683
  $user_id = $current_user->ID;
684
  /* Check that the user hasn't already clicked to ignore the message */
685
  if ( ! get_user_meta($user_id, 'wp_tab_widget_ignore_notice') ) {
686
+ echo '<div class="updated notice-info wp-tab-widget-pro-notice" style="position:relative;"><p>';
687
  printf(__('Like WP Tab Widget? You will <strong>LOVE WP Tab Widget Pro</strong>!','wp-tab-widget').'<a href="https://mythemeshop.com/plugins/wp-tab-widget-pro/?utm_source=WP+Tab+Widget+Free&utm_medium=Notification+Link&utm_content=WP+Tab+Widget+Pro+LP&utm_campaign=WordPressOrg&wpmts" target="_blank">&nbsp;'.__('Click here for all the exciting features.','wp-tab-widget').'</a><a href="%1$s" class="dashicons dashicons-dismiss dashicons-dismiss-icon" style="position: absolute; top: 8px; right: 8px; color: #222; opacity: 0.4; text-decoration: none !important;"></a>', '?wp_tab_widget_notice_ignore=0');
688
  echo "</p></div>";
689
  }