PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 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 All 504 releases
← All changes | modules/widgets/top-posts.php +18 -14 13.9.216.3-a.1 View file →
@@ -11,13 +11,18 @@
11 11 */
12 12
13 13 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
14 14
15 +use Automattic\Jetpack\Post_Media\Images;
15 16 use Automattic\Jetpack\Redirect;
16 17 use Automattic\Jetpack\Stats\WPCOM_Stats;
17 18 use Automattic\Jetpack\Status;
18 19 use Automattic\Jetpack\Status\Host;
19 20
21 +if ( ! defined( 'ABSPATH' ) ) {
22 + exit( 0 );
23 +}
24 +
20 25 // Register the widget for use in Appearance -> Widgets
21 26 add_action( 'widgets_init', 'jetpack_top_posts_widget_init' );
22 27
23 28 /**
@@ -72,12 +77,8 @@
72 77 );
73 78
74 79 $this->default_title = __( 'Top Posts & Pages', 'jetpack' );
75 80
76 - if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) {
77 - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
78 - }
79 -
80 81 /**
81 82 * Add explanation about how the statistics are calculated.
82 83 *
83 84 * @module widgets
@@ -114,9 +115,9 @@
114 115 * Displays the form for this widget on the Widgets page of the WP Admin area.
115 116 *
116 117 * @param array $instance Instance configuration.
117 118 *
118 - * @return void
119 + * @return string|void
119 120 */
120 121 public function form( $instance ) {
121 122 $instance = wp_parse_args( (array) $instance, static::defaults() );
122 123
@@ -150,9 +151,9 @@
150 151 </p>
151 152
152 153 <p>
153 154 <label for="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>"><?php esc_html_e( 'Maximum number of posts to show (no more than 10):', 'jetpack' ); ?></label>
154 - <input id="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'count' ) ); ?>" type="number" value="<?php echo (int) $count; ?>" min="1" max="10" />
155 + <input id="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'count' ) ); ?>" type="number" value="<?php echo esc_attr( (string) $count ); ?>" min="1" max="10" />
155 156 </p>
156 157
157 158 <?php if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) : ?>
158 159 <p>
@@ -297,9 +298,9 @@
297 298 do_action( 'jetpack_stats_extra', 'widget_view', 'top_posts' );
298 299
299 300 $instance = wp_parse_args( (array) $instance, static::defaults() );
300 301
301 - $title = isset( $instance['title'] ) ? $instance['title'] : false;
302 + $title = $instance['title'] ?? false;
302 303 if ( false === $title ) {
303 304 $title = $this->default_title;
304 305 }
305 306
@@ -305,8 +306,11 @@
305 306
306 307 /** This filter is documented in core/src/wp-includes/default-widgets.php */
307 308 $title = apply_filters( 'widget_title', $title );
308 309
310 + // Enqueue front end assets.
311 + $this->enqueue_style();
312 +
309 313 $count = isset( $instance['count'] ) ? (int) $instance['count'] : false;
310 314 if ( $count < 1 || 10 < $count ) {
311 315 $count = 10;
312 316 }
@@ -430,26 +434,26 @@
430 434 $height = (int) $get_image_options['height'];
431 435 }
432 436
433 437 foreach ( $posts as &$post ) {
434 - $image = Jetpack_PostImages::get_image(
438 + $image = Images::get_image(
435 439 $post['post_id'],
436 440 array(
437 441 'fallback_to_avatars' => (bool) $get_image_options['fallback_to_avatars'],
438 - 'width' => (int) $width,
439 - 'height' => (int) $height,
442 + 'width' => $width,
443 + 'height' => $height,
440 444 'avatar_size' => (int) $get_image_options['avatar_size'],
441 445 )
442 446 );
443 447
444 448 if ( $image ) {
445 - $post['image'] = Jetpack_PostImages::fit_image_url(
449 + $post['image'] = Images::fit_image_url(
446 450 $image['src'],
447 451 $width,
448 452 $height
449 453 );
450 454
451 - $post['image_srcset'] = Jetpack_PostImages::generate_cropped_srcset(
455 + $post['image_srcset'] = Images::generate_cropped_srcset(
452 456 $image,
453 457 $width,
454 458 $height
455 459 );
@@ -704,9 +708,9 @@
704 708 */
705 709 $days = (int) apply_filters( 'jetpack_top_posts_days', 2, $args );
706 710
707 711 /** Handling situations where the number of days makes no sense - allows for unlimited days where $days = -1 */
708 - if ( 0 === $days || false === $days ) {
712 + if ( 0 === $days ) {
709 713 $days = 2;
710 714 }
711 715
712 716 $query_args = array(
@@ -711,9 +715,9 @@
711 715
712 716 $query_args = array(
713 717 'max' => 11,
714 718 'summarize' => 1,
715 - 'num' => (int) $days,
719 + 'num' => $days,
716 720 );
717 721 $wpcom_stats = new WPCOM_Stats();
718 722 $post_view_posts = $wpcom_stats->convert_stats_array_to_object(
719 723 $wpcom_stats->get_top_posts( $query_args )