Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/widgets
File: top-posts.php
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
[0] Fix | Delete
/**
[1] Fix | Delete
* Top Posts widget.
[2] Fix | Delete
*
[3] Fix | Delete
* Currently, this widget depends on the Stats Module. To not load this file
[4] Fix | Delete
* when the Stats Module is not active would potentially bypass Jetpack's
[5] Fix | Delete
* fatal error detection on module activation, so we always load this file.
[6] Fix | Delete
* Instead, we don't register the widget if the Stats Module isn't active.
[7] Fix | Delete
*
[8] Fix | Delete
* @package automattic/jetpack
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
[12] Fix | Delete
[13] Fix | Delete
use Automattic\Jetpack\Post_Media\Images;
[14] Fix | Delete
use Automattic\Jetpack\Redirect;
[15] Fix | Delete
use Automattic\Jetpack\Stats\WPCOM_Stats;
[16] Fix | Delete
use Automattic\Jetpack\Status;
[17] Fix | Delete
use Automattic\Jetpack\Status\Host;
[18] Fix | Delete
[19] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[20] Fix | Delete
exit( 0 );
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
// Register the widget for use in Appearance -> Widgets
[24] Fix | Delete
add_action( 'widgets_init', 'jetpack_top_posts_widget_init' );
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Register the widget, if the Stats module is active.
[28] Fix | Delete
*/
[29] Fix | Delete
function jetpack_top_posts_widget_init() {
[30] Fix | Delete
// Currently, this widget depends on the Stats Module.
[31] Fix | Delete
if (
[32] Fix | Delete
! ( defined( 'IS_WPCOM' ) && IS_WPCOM )
[33] Fix | Delete
&& (
[34] Fix | Delete
! Jetpack::is_module_active( 'stats' )
[35] Fix | Delete
|| ( new Status() )->is_offline_mode()
[36] Fix | Delete
)
[37] Fix | Delete
) {
[38] Fix | Delete
return;
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
register_widget( 'Jetpack_Top_Posts_Widget' );
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Widget class.
[46] Fix | Delete
*/
[47] Fix | Delete
class Jetpack_Top_Posts_Widget extends WP_Widget {
[48] Fix | Delete
/**
[49] Fix | Delete
* Widget unique identifier.
[50] Fix | Delete
*
[51] Fix | Delete
* @var string
[52] Fix | Delete
*/
[53] Fix | Delete
public $alt_option_name = 'widget_stats_topposts';
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Widget default title.
[57] Fix | Delete
*
[58] Fix | Delete
* @var string
[59] Fix | Delete
*/
[60] Fix | Delete
public $default_title = '';
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Constructor.
[64] Fix | Delete
*/
[65] Fix | Delete
public function __construct() {
[66] Fix | Delete
parent::__construct(
[67] Fix | Delete
'top-posts',
[68] Fix | Delete
/** This filter is documented in modules/widgets/facebook-likebox.php */
[69] Fix | Delete
apply_filters( 'jetpack_widget_name', __( 'Top Posts &amp; Pages', 'jetpack' ) ),
[70] Fix | Delete
array(
[71] Fix | Delete
'description' => __( 'Shows your most viewed posts and pages.', 'jetpack' ),
[72] Fix | Delete
'customize_selective_refresh' => true,
[73] Fix | Delete
'show_instance_in_rest' => true,
[74] Fix | Delete
)
[75] Fix | Delete
);
[76] Fix | Delete
[77] Fix | Delete
$this->default_title = __( 'Top Posts &amp; Pages', 'jetpack' );
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Add explanation about how the statistics are calculated.
[81] Fix | Delete
*
[82] Fix | Delete
* @module widgets
[83] Fix | Delete
*
[84] Fix | Delete
* @since 3.9.3
[85] Fix | Delete
*/
[86] Fix | Delete
add_action( 'jetpack_widget_top_posts_after_fields', array( $this, 'stats_explanation' ) );
[87] Fix | Delete
add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) );
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* Remove the "Top Posts and Pages" widget from the Legacy Widget block
[92] Fix | Delete
*
[93] Fix | Delete
* @param array $widget_types List of widgets that are currently removed from the Legacy Widget block.
[94] Fix | Delete
* @return array $widget_types New list of widgets that will be removed.
[95] Fix | Delete
*/
[96] Fix | Delete
public function hide_widget_in_block_editor( $widget_types ) {
[97] Fix | Delete
// @TODO: Hide for Simple sites when the block API starts working.
[98] Fix | Delete
if ( ! ( new Host() )->is_wpcom_simple() ) {
[99] Fix | Delete
$widget_types[] = 'top-posts';
[100] Fix | Delete
}
[101] Fix | Delete
return $widget_types;
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
/**
[105] Fix | Delete
* Enqueue stylesheet.
[106] Fix | Delete
*/
[107] Fix | Delete
public function enqueue_style() {
[108] Fix | Delete
wp_register_style( 'jetpack-top-posts-widget', plugins_url( 'top-posts/style.css', __FILE__ ), array(), '20141013' );
[109] Fix | Delete
wp_enqueue_style( 'jetpack-top-posts-widget' );
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Displays the form for this widget on the Widgets page of the WP Admin area.
[114] Fix | Delete
*
[115] Fix | Delete
* @param array $instance Instance configuration.
[116] Fix | Delete
*
[117] Fix | Delete
* @return string|void
[118] Fix | Delete
*/
[119] Fix | Delete
public function form( $instance ) {
[120] Fix | Delete
$instance = wp_parse_args( (array) $instance, static::defaults() );
[121] Fix | Delete
[122] Fix | Delete
if ( false === $instance['title'] ) {
[123] Fix | Delete
$instance['title'] = $this->default_title;
[124] Fix | Delete
}
[125] Fix | Delete
$title = stripslashes( $instance['title'] );
[126] Fix | Delete
[127] Fix | Delete
$count = isset( $instance['count'] ) ? (int) $instance['count'] : 10;
[128] Fix | Delete
if ( $count < 1 || 10 < $count ) {
[129] Fix | Delete
$count = 10;
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
$allowed_post_types = array_values( get_post_types( array( 'public' => true ) ) );
[133] Fix | Delete
$types = isset( $instance['types'] ) ? (array) $instance['types'] : array( 'post', 'page' );
[134] Fix | Delete
[135] Fix | Delete
// 'likes' are not available in Jetpack
[136] Fix | Delete
$ordering = isset( $instance['ordering'] ) && 'likes' === $instance['ordering'] ? 'likes' : 'views';
[137] Fix | Delete
[138] Fix | Delete
if ( isset( $instance['display'] ) && in_array( $instance['display'], array( 'grid', 'list', 'text' ), true ) ) {
[139] Fix | Delete
$display = $instance['display'];
[140] Fix | Delete
} else {
[141] Fix | Delete
$display = 'text';
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
?>
[145] Fix | Delete
[146] Fix | Delete
<p>
[147] Fix | Delete
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'jetpack' ); ?></label>
[148] Fix | Delete
<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( $title ); ?>" />
[149] Fix | Delete
</p>
[150] Fix | Delete
[151] Fix | Delete
<p>
[152] Fix | Delete
<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>
[153] Fix | Delete
<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" />
[154] Fix | Delete
</p>
[155] Fix | Delete
[156] Fix | Delete
<?php if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) : ?>
[157] Fix | Delete
<p>
[158] Fix | Delete
<label><?php esc_html_e( 'Order Top Posts &amp; Pages By:', 'jetpack' ); ?></label>
[159] Fix | Delete
<ul>
[160] Fix | Delete
<li><label><input id="<?php echo esc_attr( $this->get_field_id( 'ordering' ) ); ?>-likes" name="<?php echo esc_attr( $this->get_field_name( 'ordering' ) ); ?>" type="radio" value="likes" <?php checked( 'likes', $ordering ); ?> /> <?php esc_html_e( 'Likes', 'jetpack' ); ?></label></li>
[161] Fix | Delete
<li><label><input id="<?php echo esc_attr( $this->get_field_id( 'ordering' ) ); ?>-views" name="<?php echo esc_attr( $this->get_field_name( 'ordering' ) ); ?>" type="radio" value="views" <?php checked( 'views', $ordering ); ?> /> <?php esc_html_e( 'Views', 'jetpack' ); ?></label></li>
[162] Fix | Delete
</ul>
[163] Fix | Delete
</p>
[164] Fix | Delete
<?php endif; ?>
[165] Fix | Delete
[166] Fix | Delete
<p>
[167] Fix | Delete
<label for="<?php echo esc_attr( $this->get_field_id( 'types' ) ); ?>"><?php esc_html_e( 'Types of pages to display:', 'jetpack' ); ?></label>
[168] Fix | Delete
<ul>
[169] Fix | Delete
<?php
[170] Fix | Delete
foreach ( $allowed_post_types as $type ) {
[171] Fix | Delete
// Get the Post Type name to display next to the checkbox.
[172] Fix | Delete
$post_type_object = get_post_type_object( $type );
[173] Fix | Delete
$label = $post_type_object->labels->name;
[174] Fix | Delete
[175] Fix | Delete
$checked = '';
[176] Fix | Delete
if ( in_array( $type, $types, true ) ) {
[177] Fix | Delete
$checked = 'checked="checked" ';
[178] Fix | Delete
}
[179] Fix | Delete
?>
[180] Fix | Delete
[181] Fix | Delete
<li><label>
[182] Fix | Delete
<input
[183] Fix | Delete
value="<?php echo esc_attr( $type ); ?>"
[184] Fix | Delete
name="<?php echo esc_attr( $this->get_field_name( 'types' ) ); ?>[]"
[185] Fix | Delete
id="<?php echo esc_attr( $this->get_field_id( 'types' ) . '-' . $type ); ?>"
[186] Fix | Delete
type="checkbox"
[187] Fix | Delete
<?php echo $checked; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
[188] Fix | Delete
>
[189] Fix | Delete
<?php echo esc_html( $label ); ?>
[190] Fix | Delete
</label></li>
[191] Fix | Delete
[192] Fix | Delete
<?php } // End foreach ?>
[193] Fix | Delete
</ul>
[194] Fix | Delete
</p>
[195] Fix | Delete
[196] Fix | Delete
<p>
[197] Fix | Delete
<label><?php esc_html_e( 'Display as:', 'jetpack' ); ?></label>
[198] Fix | Delete
<ul>
[199] Fix | Delete
<li><label><input id="<?php echo esc_attr( $this->get_field_id( 'display' ) ); ?>-text" name="<?php echo esc_attr( $this->get_field_name( 'display' ) ); ?>" type="radio" value="text" <?php checked( 'text', $display ); ?> /> <?php esc_html_e( 'Text List', 'jetpack' ); ?></label></li>
[200] Fix | Delete
<li><label><input id="<?php echo esc_attr( $this->get_field_id( 'display' ) ); ?>-list" name="<?php echo esc_attr( $this->get_field_name( 'display' ) ); ?>" type="radio" value="list" <?php checked( 'list', $display ); ?> /> <?php esc_html_e( 'Image List', 'jetpack' ); ?></label></li>
[201] Fix | Delete
<li><label><input id="<?php echo esc_attr( $this->get_field_id( 'display' ) ); ?>-grid" name="<?php echo esc_attr( $this->get_field_name( 'display' ) ); ?>" type="radio" value="grid" <?php checked( 'grid', $display ); ?> /> <?php esc_html_e( 'Image Grid', 'jetpack' ); ?></label></li>
[202] Fix | Delete
</ul>
[203] Fix | Delete
</p>
[204] Fix | Delete
<?php
[205] Fix | Delete
[206] Fix | Delete
/**
[207] Fix | Delete
* Fires after the fields are displayed in the Top Posts Widget settings in wp-admin.
[208] Fix | Delete
*
[209] Fix | Delete
* Allow adding extra content after the fields are displayed.
[210] Fix | Delete
*
[211] Fix | Delete
* @module widgets
[212] Fix | Delete
*
[213] Fix | Delete
* @since 3.9.3
[214] Fix | Delete
*
[215] Fix | Delete
* @param array $args {
[216] Fix | Delete
* @param array $instance The widget instance.
[217] Fix | Delete
* @param object $this The class object.
[218] Fix | Delete
* }
[219] Fix | Delete
*/
[220] Fix | Delete
do_action( 'jetpack_widget_top_posts_after_fields', array( $instance, $this ) );
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* Explains how the statics are calculated.
[225] Fix | Delete
*/
[226] Fix | Delete
public function stats_explanation() {
[227] Fix | Delete
echo '<p>';
[228] Fix | Delete
esc_html_e( 'Top Posts &amp; Pages by views are calculated from 24-48 hours of stats. They take a while to change.', 'jetpack' );
[229] Fix | Delete
echo '</p>';
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
/**
[233] Fix | Delete
* Deals with the settings when they are saved by the admin.
[234] Fix | Delete
*
[235] Fix | Delete
* @param array $new_instance New configuration values.
[236] Fix | Delete
* @param array $old_instance Old configuration values.
[237] Fix | Delete
*
[238] Fix | Delete
* @return array
[239] Fix | Delete
*/
[240] Fix | Delete
public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
[241] Fix | Delete
$instance = array();
[242] Fix | Delete
$instance['title'] = wp_kses( $new_instance['title'], array() );
[243] Fix | Delete
if ( $instance['title'] === $this->default_title ) {
[244] Fix | Delete
$instance['title'] = false; // Store as false in case of language change.
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
$instance['count'] = (int) $new_instance['count'];
[248] Fix | Delete
if ( $instance['count'] < 1 || 10 < $instance['count'] ) {
[249] Fix | Delete
$instance['count'] = 10;
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
// 'likes' are not available in Jetpack
[253] Fix | Delete
$instance['ordering'] = isset( $new_instance['ordering'] ) && 'likes' === $new_instance['ordering']
[254] Fix | Delete
? 'likes'
[255] Fix | Delete
: 'views';
[256] Fix | Delete
[257] Fix | Delete
$allowed_post_types = array_values( get_post_types( array( 'public' => true ) ) );
[258] Fix | Delete
$instance['types'] = $new_instance['types'];
[259] Fix | Delete
foreach ( $new_instance['types'] as $key => $type ) {
[260] Fix | Delete
if ( ! in_array( $type, $allowed_post_types, true ) ) {
[261] Fix | Delete
unset( $new_instance['types'][ $key ] );
[262] Fix | Delete
}
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
if ( isset( $new_instance['display'] ) && in_array( $new_instance['display'], array( 'grid', 'list', 'text' ), true ) ) {
[266] Fix | Delete
$instance['display'] = $new_instance['display'];
[267] Fix | Delete
} else {
[268] Fix | Delete
$instance['display'] = 'text';
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
/**
[272] Fix | Delete
* Filters Top Posts Widget settings before they're saved.
[273] Fix | Delete
*
[274] Fix | Delete
* @module widgets
[275] Fix | Delete
*
[276] Fix | Delete
* @since 3.9.3
[277] Fix | Delete
*
[278] Fix | Delete
* @param array $instance The santized widget instance. Only contains data processed by the current widget.
[279] Fix | Delete
* @param array $new_instance The new widget instance before sanitization.
[280] Fix | Delete
*/
[281] Fix | Delete
$instance = apply_filters( 'jetpack_top_posts_saving', $instance, $new_instance );
[282] Fix | Delete
[283] Fix | Delete
return $instance;
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
/**
[287] Fix | Delete
* Outputs the HTML for this widget.
[288] Fix | Delete
*
[289] Fix | Delete
* @param array $args An array of standard parameters for widgets in this theme.
[290] Fix | Delete
* @param array $instance An array of settings for this widget instance.
[291] Fix | Delete
*
[292] Fix | Delete
* @return void Echoes it's output
[293] Fix | Delete
*/
[294] Fix | Delete
public function widget( $args, $instance ) {
[295] Fix | Delete
/** This action is documented in modules/widgets/gravatar-profile.php */
[296] Fix | Delete
do_action( 'jetpack_stats_extra', 'widget_view', 'top_posts' );
[297] Fix | Delete
[298] Fix | Delete
$instance = wp_parse_args( (array) $instance, static::defaults() );
[299] Fix | Delete
[300] Fix | Delete
$title = isset( $instance['title'] ) ? $instance['title'] : false;
[301] Fix | Delete
if ( false === $title ) {
[302] Fix | Delete
$title = $this->default_title;
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
/** This filter is documented in core/src/wp-includes/default-widgets.php */
[306] Fix | Delete
$title = apply_filters( 'widget_title', $title );
[307] Fix | Delete
[308] Fix | Delete
// Enqueue front end assets.
[309] Fix | Delete
$this->enqueue_style();
[310] Fix | Delete
[311] Fix | Delete
$count = isset( $instance['count'] ) ? (int) $instance['count'] : false;
[312] Fix | Delete
if ( $count < 1 || 10 < $count ) {
[313] Fix | Delete
$count = 10;
[314] Fix | Delete
}
[315] Fix | Delete
/**
[316] Fix | Delete
* Control the number of displayed posts.
[317] Fix | Delete
*
[318] Fix | Delete
* @module widgets
[319] Fix | Delete
*
[320] Fix | Delete
* @since 3.3.0
[321] Fix | Delete
*
[322] Fix | Delete
* @param string $count Number of Posts displayed in the Top Posts widget. Default is 10.
[323] Fix | Delete
*/
[324] Fix | Delete
$count = apply_filters( 'jetpack_top_posts_widget_count', $count );
[325] Fix | Delete
[326] Fix | Delete
$types = isset( $instance['types'] ) ? (array) $instance['types'] : array( 'post', 'page' );
[327] Fix | Delete
[328] Fix | Delete
// 'likes' are not available in Jetpack
[329] Fix | Delete
$ordering = isset( $instance['ordering'] ) && 'likes' === $instance['ordering']
[330] Fix | Delete
? 'likes'
[331] Fix | Delete
: 'views';
[332] Fix | Delete
[333] Fix | Delete
if (
[334] Fix | Delete
isset( $instance['display'] )
[335] Fix | Delete
&& in_array( $instance['display'], array( 'grid', 'list', 'text' ), true )
[336] Fix | Delete
) {
[337] Fix | Delete
$display = $instance['display'];
[338] Fix | Delete
} else {
[339] Fix | Delete
$display = 'text';
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
$get_image_options = array();
[343] Fix | Delete
if ( 'text' !== $display ) {
[344] Fix | Delete
$get_image_options = array(
[345] Fix | Delete
'fallback_to_avatars' => true,
[346] Fix | Delete
/** This filter is documented in modules/stats.php */
[347] Fix | Delete
'gravatar_default' => apply_filters( 'jetpack_static_url', set_url_scheme( 'https://en.wordpress.com/i/logo/white-gray-80.png' ) ),
[348] Fix | Delete
'avatar_size' => 40,
[349] Fix | Delete
'width' => null,
[350] Fix | Delete
'height' => null,
[351] Fix | Delete
);
[352] Fix | Delete
if ( 'grid' === $display ) {
[353] Fix | Delete
$get_image_options['avatar_size'] = 200;
[354] Fix | Delete
}
[355] Fix | Delete
/**
[356] Fix | Delete
* Top Posts Widget Image options.
[357] Fix | Delete
*
[358] Fix | Delete
* @module widgets
[359] Fix | Delete
*
[360] Fix | Delete
* @since 1.8.0
[361] Fix | Delete
*
[362] Fix | Delete
* @param array $get_image_options {
[363] Fix | Delete
* Array of Image options.
[364] Fix | Delete
* @type bool true Should we default to Gravatars when no image is found? Default is true.
[365] Fix | Delete
* @type string $gravatar_default Default Image URL if no Gravatar is found.
[366] Fix | Delete
* @type int $avatar_size Default Image size.
[367] Fix | Delete
* @type mixed $width Image width, not set by default and $avatar_size is used instead.
[368] Fix | Delete
* @type mixed $height Image height, not set by default and $avatar_size is used instead.
[369] Fix | Delete
* }
[370] Fix | Delete
*/
[371] Fix | Delete
$get_image_options = apply_filters( 'jetpack_top_posts_widget_image_options', $get_image_options );
[372] Fix | Delete
}
[373] Fix | Delete
[374] Fix | Delete
if ( function_exists( 'wpl_get_blogs_most_liked_posts' ) && 'likes' === $ordering ) {
[375] Fix | Delete
$posts = $this->get_by_likes( $count, $types );
[376] Fix | Delete
} else {
[377] Fix | Delete
$posts = $this->get_by_views( $count, $args, $types );
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[381] Fix | Delete
[382] Fix | Delete
if ( ! empty( $title ) ) {
[383] Fix | Delete
echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
/*
[387] Fix | Delete
* If we have no posts, add some fallback posts
[388] Fix | Delete
* and display a fallback message for admins.
[389] Fix | Delete
*/
[390] Fix | Delete
if ( ! $posts ) {
[391] Fix | Delete
if ( current_user_can( 'edit_theme_options' ) ) {
[392] Fix | Delete
echo self::fallback_message(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
$posts = $this->get_fallback_posts( $count, $types );
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
/*
[399] Fix | Delete
* Display our posts.
[400] Fix | Delete
*/
[401] Fix | Delete
[402] Fix | Delete
/**
[403] Fix | Delete
* Filter the layout of the Top Posts Widget
[404] Fix | Delete
*
[405] Fix | Delete
* @module widgets
[406] Fix | Delete
*
[407] Fix | Delete
* @since 6.4.0
[408] Fix | Delete
*
[409] Fix | Delete
* @param string $layout layout of the Top Posts Widget (empty string).
[410] Fix | Delete
* @param array $posts IDs of the posts to be displayed.
[411] Fix | Delete
* @param array $display Display option from widget form.
[412] Fix | Delete
*/
[413] Fix | Delete
$layout = apply_filters( 'jetpack_top_posts_widget_layout', '', $posts, $display );
[414] Fix | Delete
if ( ! empty( $layout ) ) {
[415] Fix | Delete
echo $layout; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[416] Fix | Delete
}
[417] Fix | Delete
[418] Fix | Delete
switch ( $display ) {
[419] Fix | Delete
case 'list':
[420] Fix | Delete
case 'grid':
[421] Fix | Delete
// Keep the avatar_size as default dimensions for backward compatibility.
[422] Fix | Delete
$width = (int) $get_image_options['avatar_size'];
[423] Fix | Delete
$height = (int) $get_image_options['avatar_size'];
[424] Fix | Delete
[425] Fix | Delete
// Check if the user has changed the width.
[426] Fix | Delete
if ( ! empty( $get_image_options['width'] ) ) {
[427] Fix | Delete
$width = (int) $get_image_options['width'];
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
// Check if the user has changed the height.
[431] Fix | Delete
if ( ! empty( $get_image_options['height'] ) ) {
[432] Fix | Delete
$height = (int) $get_image_options['height'];
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
foreach ( $posts as &$post ) {
[436] Fix | Delete
$image = Images::get_image(
[437] Fix | Delete
$post['post_id'],
[438] Fix | Delete
array(
[439] Fix | Delete
'fallback_to_avatars' => (bool) $get_image_options['fallback_to_avatars'],
[440] Fix | Delete
'width' => $width,
[441] Fix | Delete
'height' => $height,
[442] Fix | Delete
'avatar_size' => (int) $get_image_options['avatar_size'],
[443] Fix | Delete
)
[444] Fix | Delete
);
[445] Fix | Delete
[446] Fix | Delete
if ( $image ) {
[447] Fix | Delete
$post['image'] = Images::fit_image_url(
[448] Fix | Delete
$image['src'],
[449] Fix | Delete
$width,
[450] Fix | Delete
$height
[451] Fix | Delete
);
[452] Fix | Delete
[453] Fix | Delete
$post['image_srcset'] = Images::generate_cropped_srcset(
[454] Fix | Delete
$image,
[455] Fix | Delete
$width,
[456] Fix | Delete
$height
[457] Fix | Delete
);
[458] Fix | Delete
[459] Fix | Delete
if ( empty( $post['image_srcset'] ) ) {
[460] Fix | Delete
$post['image_srcset'] = "{$post['image']} 1x";
[461] Fix | Delete
}
[462] Fix | Delete
}
[463] Fix | Delete
}
[464] Fix | Delete
unset( $post );
[465] Fix | Delete
[466] Fix | Delete
if ( 'grid' === $display ) {
[467] Fix | Delete
echo "<div class='widgets-grid-layout no-grav'>\n";
[468] Fix | Delete
foreach ( $posts as $post ) {
[469] Fix | Delete
echo '<div class="widget-grid-view-image">';
[470] Fix | Delete
[471] Fix | Delete
/**
[472] Fix | Delete
* Fires before each Top Post result, inside <li>.
[473] Fix | Delete
*
[474] Fix | Delete
* @module widgets
[475] Fix | Delete
*
[476] Fix | Delete
* @since 3.2.0
[477] Fix | Delete
*
[478] Fix | Delete
* @param string $post['post_id'] Post ID.
[479] Fix | Delete
*/
[480] Fix | Delete
do_action( 'jetpack_widget_top_posts_before_post', $post['post_id'] );
[481] Fix | Delete
[482] Fix | Delete
/**
[483] Fix | Delete
* Filter the permalink of items in the Top Posts widget.
[484] Fix | Delete
*
[485] Fix | Delete
* @module widgets
[486] Fix | Delete
*
[487] Fix | Delete
* @since 4.4.0
[488] Fix | Delete
*
[489] Fix | Delete
* @param string $post['permalink'] Post permalink.
[490] Fix | Delete
* @param array $post Post array.
[491] Fix | Delete
*/
[492] Fix | Delete
$filtered_permalink = apply_filters( 'jetpack_top_posts_widget_permalink', $post['permalink'], $post );
[493] Fix | Delete
[494] Fix | Delete
if ( $post['image'] ) {
[495] Fix | Delete
printf(
[496] Fix | Delete
'<a href="%1$s" title="%2$s" class="bump-view" data-bump-view="tp"%3$s><img loading="lazy" width="%4$d" height="%5$d" src="%6$s" srcset="%7$s" alt="%2$s" data-pin-nopin="true"/></a>',
[497] Fix | Delete
esc_url( $filtered_permalink ),
[498] Fix | Delete
esc_attr( wp_kses( $post['title'], array() ) ),
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function