PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.0.4
Jetpack – WP Security, Backup, Speed, & Growth v6.0.4
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / widgets / top-posts.php

top-posts.php in Jetpack – WP Security, Backup, Speed, & Growth 6.0.4, at modules/widgets/top-posts.php

645 lines 21.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * Currently, this widget depends on the Stats Module. To not load this file
5 * when the Stats Module is not active would potentially bypass Jetpack's
6 * fatal error detection on module activation, so we always load this file.
7 * Instead, we don't register the widget if the Stats Module isn't active.
8 */
9
10 /**
11 * Register the widget for use in Appearance -> Widgets
12 */
13 add_action( 'widgets_init', 'jetpack_top_posts_widget_init' );
14
15 function jetpack_top_posts_widget_init() {
16 // Currently, this widget depends on the Stats Module
17 if (
18 ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM )
19 &&
20 ! function_exists( 'stats_get_from_restapi' )
21 ) {
22 return;
23 }
24
25 register_widget( 'Jetpack_Top_Posts_Widget' );
26 }
27
28 class Jetpack_Top_Posts_Widget extends WP_Widget {
29 public $alt_option_name = 'widget_stats_topposts';
30 public $default_title = '';
31
32 function __construct() {
33 parent::__construct(
34 'top-posts',
35 /** This filter is documented in modules/widgets/facebook-likebox.php */
36 apply_filters( 'jetpack_widget_name', __( 'Top Posts &amp; Pages', 'jetpack' ) ),
37 array(
38 'description' => __( 'Shows your most viewed posts and pages.', 'jetpack' ),
39 'customize_selective_refresh' => true,
40 )
41 );
42
43 $this->default_title = __( 'Top Posts &amp; Pages', 'jetpack' );
44
45 if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) {
46 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
47 }
48
49 /**
50 * Add explanation about how the statistics are calculated.
51 *
52 * @module widgets
53 *
54 * @since 3.9.3
55 */
56 add_action( 'jetpack_widget_top_posts_after_fields', array( $this, 'stats_explanation' ) );
57 }
58
59 function enqueue_style() {
60 wp_register_style( 'jetpack-top-posts-widget', plugins_url( 'top-posts/style.css', __FILE__ ), array(), '20141013' );
61 wp_enqueue_style( 'jetpack-top-posts-widget' );
62 }
63
64 function form( $instance ) {
65 $instance = wp_parse_args( (array) $instance, $this->defaults() );
66
67 if ( false === $instance['title'] ) {
68 $instance['title'] = $this->default_title;
69 }
70 $title = stripslashes( $instance['title'] );
71
72 $count = isset( $instance['count'] ) ? (int) $instance['count'] : 10;
73 if ( $count < 1 || 10 < $count ) {
74 $count = 10;
75 }
76
77 $allowed_post_types = array_values( get_post_types( array( 'public' => true ) ) );
78 $types = isset( $instance['types'] ) ? (array) $instance['types'] : array( 'post', 'page' );
79
80 // 'likes' are not available in Jetpack
81 $ordering = isset( $instance['ordering'] ) && 'likes' === $instance['ordering'] ? 'likes' : 'views';
82
83 if ( isset( $instance['display'] ) && in_array( $instance['display'], array( 'grid', 'list', 'text' ) ) ) {
84 $display = $instance['display'];
85 } else {
86 $display = 'text';
87 }
88
89 ?>
90
91 <p>
92 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'jetpack' ); ?></label>
93 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
94 </p>
95
96 <p>
97 <label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php esc_html_e( 'Maximum number of posts to show (no more than 10):', 'jetpack' ); ?></label>
98 <input id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" type="number" value="<?php echo (int) $count; ?>" min="1" max="10" />
99 </p>
100
101 <?php if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) : ?>
102 <p>
103 <label><?php esc_html_e( 'Order Top Posts &amp; Pages By:', 'jetpack' ); ?></label>
104 <ul>
105 <li><label><input id="<?php echo $this->get_field_id( 'ordering' ); ?>-likes" name="<?php echo $this->get_field_name( 'ordering' ); ?>" type="radio" value="likes" <?php checked( 'likes', $ordering ); ?> /> <?php esc_html_e( 'Likes', 'jetpack' ); ?></label></li>
106 <li><label><input id="<?php echo $this->get_field_id( 'ordering' ); ?>-views" name="<?php echo $this->get_field_name( 'ordering' ); ?>" type="radio" value="views" <?php checked( 'views', $ordering ); ?> /> <?php esc_html_e( 'Views', 'jetpack' ); ?></label></li>
107 </ul>
108 </p>
109 <?php endif; ?>
110
111 <p>
112 <label for="<?php echo $this->get_field_id( 'types' ); ?>"><?php esc_html_e( 'Types of pages to display:', 'jetpack' ); ?></label>
113 <ul>
114 <?php foreach( $allowed_post_types as $type ) {
115 // Get the Post Type name to display next to the checkbox
116 $post_type_object = get_post_type_object( $type );
117 $label = $post_type_object->labels->name;
118
119 $checked = '';
120 if ( in_array( $type, $types ) ) {
121 $checked = 'checked="checked" ';
122 } ?>
123
124 <li><label>
125 <input value="<?php echo esc_attr( $type ); ?>" name="<?php echo $this->get_field_name( 'types' ); ?>[]" id="<?php echo $this->get_field_id( 'types' ); ?>-<?php echo $type; ?>" type="checkbox" <?php echo $checked; ?>>
126 <?php echo esc_html( $label ); ?>
127 </label></li>
128
129 <?php } // End foreach ?>
130 </ul>
131 </p>
132
133 <p>
134 <label><?php esc_html_e( 'Display as:', 'jetpack' ); ?></label>
135 <ul>
136 <li><label><input id="<?php echo $this->get_field_id( 'display' ); ?>-text" name="<?php echo $this->get_field_name( 'display' ); ?>" type="radio" value="text" <?php checked( 'text', $display ); ?> /> <?php esc_html_e( 'Text List', 'jetpack' ); ?></label></li>
137 <li><label><input id="<?php echo $this->get_field_id( 'display' ); ?>-list" name="<?php echo $this->get_field_name( 'display' ); ?>" type="radio" value="list" <?php checked( 'list', $display ); ?> /> <?php esc_html_e( 'Image List', 'jetpack' ); ?></label></li>
138 <li><label><input id="<?php echo $this->get_field_id( 'display' ); ?>-grid" name="<?php echo $this->get_field_name( 'display' ); ?>" type="radio" value="grid" <?php checked( 'grid', $display ); ?> /> <?php esc_html_e( 'Image Grid', 'jetpack' ); ?></label></li>
139 </ul>
140 </p><?php
141
142 /**
143 * Fires after the fields are displayed in the Top Posts Widget settings in wp-admin.
144 *
145 * Allow adding extra content after the fields are displayed.
146 *
147 * @module widgets
148 *
149 * @since 3.9.3
150 *
151 * @param array $args {
152 * @param array $instance The widget instance.
153 * @param object $this The class object.
154 * }
155 */
156 do_action( 'jetpack_widget_top_posts_after_fields', array( $instance, $this ) );
157 }
158
159 /**
160 * Explains how the statics are calculated.
161 */
162 function stats_explanation() {
163 ?>
164
165 <p><?php esc_html_e( 'Top Posts &amp; Pages by views are calculated from 24-48 hours of stats. They take a while to change.', 'jetpack' ); ?></p><?php
166 }
167
168 function update( $new_instance, $old_instance ) {
169 $instance = array();
170 $instance['title'] = wp_kses( $new_instance['title'], array() );
171 if ( $instance['title'] === $this->default_title ) {
172 $instance['title'] = false; // Store as false in case of language change
173 }
174
175 $instance['count'] = (int) $new_instance['count'];
176 if ( $instance['count'] < 1 || 10 < $instance['count'] ) {
177 $instance['count'] = 10;
178 }
179
180 // 'likes' are not available in Jetpack
181 $instance['ordering'] = isset( $new_instance['ordering'] ) && 'likes' == $new_instance['ordering'] ? 'likes' : 'views';
182
183 $allowed_post_types = array_values( get_post_types( array( 'public' => true ) ) );
184 $instance['types'] = $new_instance['types'];
185 foreach( $new_instance['types'] as $key => $type ) {
186 if ( ! in_array( $type, $allowed_post_types ) ) {
187 unset( $new_instance['types'][ $key ] );
188 }
189 }
190
191 if ( isset( $new_instance['display'] ) && in_array( $new_instance['display'], array( 'grid', 'list', 'text' ) ) ) {
192 $instance['display'] = $new_instance['display'];
193 } else {
194 $instance['display'] = 'text';
195 }
196
197 /**
198 * Filters Top Posts Widget settings before they're saved.
199 *
200 * @module widgets
201 *
202 * @since 3.9.3
203 *
204 * @param array $instance The santized widget instance. Only contains data processed by the current widget.
205 * @param array $new_instance The new widget instance before sanitization.
206 */
207 $instance = apply_filters( 'jetpack_top_posts_saving', $instance, $new_instance );
208
209 return $instance;
210 }
211
212 function widget( $args, $instance ) {
213 /** This action is documented in modules/widgets/gravatar-profile.php */
214 do_action( 'jetpack_stats_extra', 'widget_view', 'top_posts' );
215
216 $instance = wp_parse_args( (array) $instance, $this->defaults() );
217
218 $title = isset( $instance['title' ] ) ? $instance['title'] : false;
219 if ( false === $title ) {
220 $title = $this->default_title;
221 }
222 /** This filter is documented in core/src/wp-includes/default-widgets.php */
223 $title = apply_filters( 'widget_title', $title );
224
225 $count = isset( $instance['count'] ) ? (int) $instance['count'] : false;
226 if ( $count < 1 || 10 < $count ) {
227 $count = 10;
228 }
229 /**
230 * Control the number of displayed posts.
231 *
232 * @module widgets
233 *
234 * @since 3.3.0
235 *
236 * @param string $count Number of Posts displayed in the Top Posts widget. Default is 10.
237 */
238 $count = apply_filters( 'jetpack_top_posts_widget_count', $count );
239
240 $types = isset( $instance['types'] ) ? (array) $instance['types'] : array( 'post', 'page' );
241
242 // 'likes' are not available in Jetpack
243 $ordering = isset( $instance['ordering'] ) && 'likes' == $instance['ordering'] ? 'likes' : 'views';
244
245 if ( isset( $instance['display'] ) && in_array( $instance['display'], array( 'grid', 'list', 'text' ) ) ) {
246 $display = $instance['display'];
247 } else {
248 $display = 'text';
249 }
250
251 if ( 'text' != $display ) {
252 $get_image_options = array(
253 'fallback_to_avatars' => true,
254 /** This filter is documented in modules/stats.php */
255 'gravatar_default' => apply_filters( 'jetpack_static_url', set_url_scheme( 'https://en.wordpress.com/i/logo/white-gray-80.png' ) ),
256 'avatar_size' => 40,
257 'width' => null,
258 'height' => null,
259 );
260 if ( 'grid' == $display ) {
261 $get_image_options['avatar_size'] = 200;
262 }
263 /**
264 * Top Posts Widget Image options.
265 *
266 * @module widgets
267 *
268 * @since 1.8.0
269 *
270 * @param array $get_image_options {
271 * Array of Image options.
272 * @type bool true Should we default to Gravatars when no image is found? Default is true.
273 * @type string $gravatar_default Default Image URL if no Gravatar is found.
274 * @type int $avatar_size Default Image size.
275 * @type mixed $width Image width, not set by default and $avatar_size is used instead.
276 * @type mixed $height Image height, not set by default and $avatar_size is used instead.
277 * }
278 */
279 $get_image_options = apply_filters( 'jetpack_top_posts_widget_image_options', $get_image_options );
280 }
281
282 if ( function_exists( 'wpl_get_blogs_most_liked_posts' ) && 'likes' == $ordering ) {
283 $posts = $this->get_by_likes( $count );
284 } else {
285 $posts = $this->get_by_views( $count, $args );
286 }
287
288 // Filter the returned posts. Remove all posts that do not match the chosen Post Types.
289 if ( isset( $types ) ) {
290 foreach ( $posts as $k => $post ) {
291 if ( ! in_array( $post['post_type'], $types ) ) {
292 unset( $posts[$k] );
293 }
294 }
295 }
296
297 if ( ! $posts ) {
298 $posts = $this->get_fallback_posts();
299 }
300
301 echo $args['before_widget'];
302 if ( ! empty( $title ) )
303 echo $args['before_title'] . $title . $args['after_title'];
304
305 if ( ! $posts ) {
306 if ( current_user_can( 'edit_theme_options' ) ) {
307 echo '<p>' . sprintf(
308 __( 'There are no posts to display. <a href="%s" target="_blank">Want more traffic?</a>', 'jetpack' ),
309 'https://jetpack.com/support/getting-more-views-and-traffic/'
310 ) . '</p>';
311 }
312
313 echo $args['after_widget'];
314 return;
315 }
316
317 switch ( $display ) {
318 case 'list' :
319 case 'grid' :
320 // Keep the avatar_size as default dimensions for backward compatibility.
321 $width = (int) $get_image_options['avatar_size'];
322 $height = (int) $get_image_options['avatar_size'];
323
324 // Check if the user has changed the width.
325 if ( ! empty( $get_image_options['width'] ) ) {
326 $width = (int) $get_image_options['width'];
327 }
328
329 // Check if the user has changed the height.
330 if ( ! empty( $get_image_options['height'] ) ) {
331 $height = (int) $get_image_options['height'];
332 }
333
334 foreach ( $posts as &$post ) {
335 $image = Jetpack_PostImages::get_image(
336 $post['post_id'],
337 array(
338 'fallback_to_avatars' => true,
339 'width' => (int) $width,
340 'height' => (int) $height,
341 'avatar_size' => (int) $get_image_options['avatar_size'],
342 )
343 );
344 $post['image'] = $image['src'];
345 if ( 'blavatar' != $image['from'] && 'gravatar' != $image['from'] ) {
346 $post['image'] = jetpack_photon_url( $post['image'], array( 'resize' => "$width,$height" ) );
347 }
348 }
349
350 unset( $post );
351
352 if ( 'grid' == $display ) {
353 echo "<div class='widgets-grid-layout no-grav'>\n";
354 foreach ( $posts as $post ) :
355 ?>
356 <div class="widget-grid-view-image">
357 <?php
358 /**
359 * Fires before each Top Post result, inside <li>.
360 *
361 * @module widgets
362 *
363 * @since 3.2.0
364 *
365 * @param string $post['post_id'] Post ID.
366 */
367 do_action( 'jetpack_widget_top_posts_before_post', $post['post_id'] );
368
369 /**
370 * Filter the permalink of items in the Top Posts widget.
371 *
372 * @module widgets
373 *
374 * @since 4.4.0
375 *
376 * @param string $post['permalink'] Post permalink.
377 * @param array $post Post array.
378 */
379 $filtered_permalink = apply_filters( 'jetpack_top_posts_widget_permalink', $post['permalink'], $post );
380
381 ?>
382 <a href="<?php echo esc_url( $filtered_permalink ); ?>" title="<?php echo esc_attr( wp_kses( $post['title'], array() ) ); ?>" class="bump-view" data-bump-view="tp">
383 <img width="<?php echo absint( $width ); ?>" height="<?php echo absint( $height ); ?>" src="<?php echo esc_url( $post['image'] ); ?>" alt="<?php echo esc_attr( wp_kses( $post['title'], array() ) ); ?>" data-pin-nopin="true" />
384 </a>
385 <?php
386 /**
387 * Fires after each Top Post result, inside <li>.
388 *
389 * @module widgets
390 *
391 * @since 3.2.0
392 *
393 * @param string $post['post_id'] Post ID.
394 */
395 do_action( 'jetpack_widget_top_posts_after_post', $post['post_id'] );
396 ?>
397 </div>
398 <?php
399 endforeach;
400 echo "</div>\n";
401 } else {
402 echo "<ul class='widgets-list-layout no-grav'>\n";
403 foreach ( $posts as $post ) :
404 ?>
405 <li>
406 <?php
407 /** This action is documented in modules/widgets/top-posts.php */
408 do_action( 'jetpack_widget_top_posts_before_post', $post['post_id'] );
409
410 /** This filter is documented in modules/widgets/top-posts.php */
411 $filtered_permalink = apply_filters( 'jetpack_top_posts_widget_permalink', $post['permalink'], $post );
412 ?>
413 <a href="<?php echo esc_url( $filtered_permalink ); ?>" title="<?php echo esc_attr( wp_kses( $post['title'], array() ) ); ?>" class="bump-view" data-bump-view="tp">
414 <img width="<?php echo absint( $width ); ?>" height="<?php echo absint( $height ); ?>" src="<?php echo esc_url( $post['image'] ); ?>" class='widgets-list-layout-blavatar' alt="<?php echo esc_attr( wp_kses( $post['title'], array() ) ); ?>" data-pin-nopin="true" />
415 </a>
416 <div class="widgets-list-layout-links">
417 <a href="<?php echo esc_url( $filtered_permalink ); ?>" class="bump-view" data-bump-view="tp">
418 <?php echo esc_html( wp_kses( $post['title'], array() ) ); ?>
419 </a>
420 </div>
421 <?php
422 /** This action is documented in modules/widgets/top-posts.php */
423 do_action( 'jetpack_widget_top_posts_after_post', $post['post_id'] );
424 ?>
425 </li>
426 <?php
427 endforeach;
428 echo "</ul>\n";
429 }
430 break;
431 default :
432 echo '<ul>';
433 foreach ( $posts as $post ) :
434 ?>
435 <li>
436 <?php
437 /** This action is documented in modules/widgets/top-posts.php */
438 do_action( 'jetpack_widget_top_posts_before_post', $post['post_id'] );
439
440 /** This filter is documented in modules/widgets/top-posts.php */
441 $filtered_permalink = apply_filters( 'jetpack_top_posts_widget_permalink', $post['permalink'], $post );
442 ?>
443 <a href="<?php echo esc_url( $filtered_permalink ); ?>" class="bump-view" data-bump-view="tp">
444 <?php echo esc_html( wp_kses( $post['title'], array() ) ); ?>
445 </a>
446 <?php
447 /** This action is documented in modules/widgets/top-posts.php */
448 do_action( 'jetpack_widget_top_posts_after_post', $post['post_id'] );
449 ?>
450 </li>
451 <?php
452 endforeach;
453 echo '</ul>';
454 }
455
456 echo $args['after_widget'];
457 }
458
459 public static function defaults() {
460 return array(
461 'title' => esc_html__( 'Top Posts &amp; Pages', 'jetpack' ),
462 'count' => absint( 10 ),
463 'types' => array( 'post', 'page' ),
464 'ordering' => 'views',
465 'display' => 'text',
466 );
467 }
468
469 /*
470 * Get most liked posts
471 *
472 * ONLY TO BE USED IN WPCOM
473 */
474 function get_by_likes( $count ) {
475 $post_likes = wpl_get_blogs_most_liked_posts();
476 if ( !$post_likes ) {
477 return array();
478 }
479
480 return $this->get_posts( array_keys( $post_likes ), $count );
481 }
482
483 function get_by_views( $count, $args ) {
484 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
485 global $wpdb;
486
487 $post_views = wp_cache_get( "get_top_posts_$count", 'stats' );
488 if ( false === $post_views ) {
489 $post_views = array_shift( stats_get_daily_history( false, get_current_blog_id(), 'postviews', 'post_id', false, 2, '', $count * 2 + 10, true ) );
490 unset( $post_views[0] );
491 wp_cache_add( "get_top_posts_$count", $post_views, 'stats', 1200);
492 }
493
494 return $this->get_posts( array_keys( $post_views ), $count );
495 }
496
497 /**
498 * Filter the number of days used to calculate Top Posts for the Top Posts widget.
499 * We do not recommend accessing more than 10 days of results at one.
500 * When more than 10 days of results are accessed at once, results should be cached via the WordPress transients API.
501 * Querying for -1 days will give results for an infinite number of days.
502 *
503 * @module widgets
504 *
505 * @since 3.9.3
506 *
507 * @param int 2 Number of days. Default is 2.
508 * @param array $args The widget arguments.
509 */
510 $days = (int) apply_filters( 'jetpack_top_posts_days', 2, $args );
511
512 /** Handling situations where the number of days makes no sense - allows for unlimited days where $days = -1 */
513 if ( 0 == $days || false == $days ) {
514 $days = 2;
515 }
516
517 $post_view_posts = stats_get_from_restapi( array(), 'top-posts?max=11&summarize=1&num=' . absint( $days ) );
518
519 if ( ! isset( $post_view_posts->summary ) || empty( $post_view_posts->summary->postviews ) ) {
520 return array();
521 }
522
523 $post_view_ids = array_filter( wp_list_pluck( $post_view_posts->summary->postviews, 'id' ) );
524
525 if ( ! $post_view_ids ) {
526 return array();
527 }
528
529 return $this->get_posts( $post_view_ids, $count );
530 }
531
532 function get_fallback_posts() {
533 if ( current_user_can( 'edit_theme_options' ) ) {
534 return array();
535 }
536
537 $post_query = new WP_Query;
538
539 $posts = $post_query->query( array(
540 'posts_per_page' => 1,
541 'post_status' => 'publish',
542 'post_type' => array( 'post', 'page' ),
543 'no_found_rows' => true,
544 ) );
545
546 if ( ! $posts ) {
547 return array();
548 }
549
550 $post = array_pop( $posts );
551
552 return $this->get_posts( $post->ID, 1 );
553 }
554
555 function get_posts( $post_ids, $count ) {
556 $counter = 0;
557
558 $posts = array();
559 foreach ( (array) $post_ids as $post_id ) {
560 $post = get_post( $post_id );
561
562 if ( ! $post ) {
563 continue;
564 }
565
566 /**
567 * Attachment pages use the 'inherit' post status by default.
568 * To be able to remove attachment pages from private and password protect posts,
569 * we need to replace their post status by the parent post' status.
570 */
571 if ( 'inherit' == $post->post_status && 'attachment' == $post->post_type ) {
572 $post->post_status = get_post_status( $post_id );
573 }
574
575 // hide private and password protected posts
576 if ( 'publish' != $post->post_status || ! empty( $post->post_password ) ) {
577 continue;
578 }
579
580 // Both get HTML stripped etc on display
581 if ( empty( $post->post_title ) ) {
582 $title_source = $post->post_content;
583 $title = wp_html_excerpt( $title_source, 50 );
584 $title .= '&hellip;';
585 } else {
586 $title = $post->post_title;
587 }
588
589 $permalink = get_permalink( $post->ID );
590
591 $post_type = $post->post_type;
592
593 $posts[] = compact( 'title', 'permalink', 'post_id', 'post_type' );
594 $counter++;
595
596 if ( $counter == $count ) {
597 break; // only need to load and show x number of likes
598 }
599 }
600
601 /**
602 * Filter the Top Posts and Pages.
603 *
604 * @module widgets
605 *
606 * @since 3.0.0
607 *
608 * @param array $posts Array of the most popular posts.
609 * @param array $post_ids Array of Post IDs.
610 * @param string $count Number of Top Posts we want to display.
611 */
612 return apply_filters( 'jetpack_widget_get_top_posts', $posts, $post_ids, $count );
613 }
614 }
615
616 /**
617 * Create a shortcode to display the widget anywhere.
618 *
619 * @since 3.9.2
620 */
621 function jetpack_do_top_posts_widget( $instance ) {
622 // Post Types can't be entered as an array in the shortcode parameters.
623 if ( isset( $instance['types'] ) && is_array( $instance['types'] ) ) {
624 $instance['types'] = implode( ',', $instance['types'] );
625 }
626
627 $instance = shortcode_atts(
628 Jetpack_Top_Posts_Widget::defaults(),
629 $instance,
630 'jetpack_top_posts_widget'
631 );
632
633 // Add a class to allow styling
634 $args = array(
635 'before_widget' => sprintf( '<div class="%s">', 'jetpack_top_posts_widget' ),
636 );
637
638 ob_start();
639 the_widget( 'Jetpack_Top_Posts_Widget', $instance, $args );
640 $output = ob_get_clean();
641
642 return $output;
643 }
644 add_shortcode( 'jetpack_top_posts_widget', 'jetpack_do_top_posts_widget' );
645