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