Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/widgets
File: top-posts.php
absint( $width ),
[500] Fix | Delete
absint( $height ),
[501] Fix | Delete
esc_url( $post['image'] ),
[502] Fix | Delete
esc_attr( $post['image_srcset'] )
[503] Fix | Delete
);
[504] Fix | Delete
}
[505] Fix | Delete
[506] Fix | Delete
/**
[507] Fix | Delete
* Fires after each Top Post result, inside <li>.
[508] Fix | Delete
*
[509] Fix | Delete
* @module widgets
[510] Fix | Delete
*
[511] Fix | Delete
* @since 3.2.0
[512] Fix | Delete
*
[513] Fix | Delete
* @param string $post['post_id'] Post ID.
[514] Fix | Delete
*/
[515] Fix | Delete
do_action( 'jetpack_widget_top_posts_after_post', $post['post_id'] );
[516] Fix | Delete
[517] Fix | Delete
echo '</div>';
[518] Fix | Delete
}
[519] Fix | Delete
echo "</div>\n";
[520] Fix | Delete
} else {
[521] Fix | Delete
echo "<ul class='widgets-list-layout no-grav'>\n";
[522] Fix | Delete
foreach ( $posts as $post ) {
[523] Fix | Delete
echo '<li>';
[524] Fix | Delete
[525] Fix | Delete
/** This action is documented in modules/widgets/top-posts.php */
[526] Fix | Delete
do_action( 'jetpack_widget_top_posts_before_post', $post['post_id'] );
[527] Fix | Delete
[528] Fix | Delete
/** This filter is documented in modules/widgets/top-posts.php */
[529] Fix | Delete
$filtered_permalink = apply_filters( 'jetpack_top_posts_widget_permalink', $post['permalink'], $post );
[530] Fix | Delete
[531] Fix | Delete
if ( $post['image'] ) {
[532] Fix | Delete
printf(
[533] 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" class="widgets-list-layout-blavatar" /></a>',
[534] Fix | Delete
esc_url( $filtered_permalink ),
[535] Fix | Delete
esc_attr( wp_kses( $post['title'], array() ) ),
[536] Fix | Delete
( get_queried_object_id() === $post['post_id'] ? ' aria-current="page"' : '' ),
[537] Fix | Delete
absint( $width ),
[538] Fix | Delete
absint( $height ),
[539] Fix | Delete
esc_url( $post['image'] ),
[540] Fix | Delete
esc_attr( $post['image_srcset'] )
[541] Fix | Delete
);
[542] Fix | Delete
}
[543] Fix | Delete
[544] Fix | Delete
printf(
[545] Fix | Delete
'<div class="widgets-list-layout-links">
[546] Fix | Delete
<a href="%1$s" title="%2$s" class="bump-view" data-bump-view="tp"%3$s>%4$s</a>
[547] Fix | Delete
</div>
[548] Fix | Delete
',
[549] Fix | Delete
esc_url( $filtered_permalink ),
[550] Fix | Delete
esc_attr( wp_kses( $post['title'], array() ) ),
[551] Fix | Delete
( get_queried_object_id() === $post['post_id'] ? ' aria-current="page"' : '' ),
[552] Fix | Delete
esc_html( wp_kses( $post['title'], array() ) )
[553] Fix | Delete
);
[554] Fix | Delete
[555] Fix | Delete
/** This action is documented in modules/widgets/top-posts.php */
[556] Fix | Delete
do_action( 'jetpack_widget_top_posts_after_post', $post['post_id'] );
[557] Fix | Delete
[558] Fix | Delete
echo '</li>';
[559] Fix | Delete
}
[560] Fix | Delete
echo "</ul>\n";
[561] Fix | Delete
}
[562] Fix | Delete
break;
[563] Fix | Delete
default:
[564] Fix | Delete
echo '<ul>';
[565] Fix | Delete
[566] Fix | Delete
foreach ( $posts as $post ) {
[567] Fix | Delete
echo '<li>';
[568] Fix | Delete
[569] Fix | Delete
/** This action is documented in modules/widgets/top-posts.php */
[570] Fix | Delete
do_action( 'jetpack_widget_top_posts_before_post', $post['post_id'] );
[571] Fix | Delete
[572] Fix | Delete
/** This filter is documented in modules/widgets/top-posts.php */
[573] Fix | Delete
$filtered_permalink = apply_filters( 'jetpack_top_posts_widget_permalink', $post['permalink'], $post );
[574] Fix | Delete
[575] Fix | Delete
printf(
[576] Fix | Delete
'<a href="%1$s" class="bump-view" data-bump-view="tp"%2$s>%3$s</a>',
[577] Fix | Delete
esc_url( $filtered_permalink ),
[578] Fix | Delete
( get_queried_object_id() === $post['post_id'] ? ' aria-current="page"' : '' ),
[579] Fix | Delete
esc_html( wp_kses( $post['title'], array() ) )
[580] Fix | Delete
);
[581] Fix | Delete
[582] Fix | Delete
/** This action is documented in modules/widgets/top-posts.php */
[583] Fix | Delete
do_action( 'jetpack_widget_top_posts_after_post', $post['post_id'] );
[584] Fix | Delete
[585] Fix | Delete
echo '</li>';
[586] Fix | Delete
}
[587] Fix | Delete
[588] Fix | Delete
echo '</ul>';
[589] Fix | Delete
break;
[590] Fix | Delete
}
[591] Fix | Delete
[592] Fix | Delete
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[593] Fix | Delete
}
[594] Fix | Delete
[595] Fix | Delete
/**
[596] Fix | Delete
* Display a message with recommendations when there are no recorded top posts.
[597] Fix | Delete
*
[598] Fix | Delete
* @return string $fallback_message
[599] Fix | Delete
*/
[600] Fix | Delete
private static function fallback_message() {
[601] Fix | Delete
$link = esc_url( Redirect::get_url( 'jetpack-support-getting-more-views-and-traffic' ) );
[602] Fix | Delete
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
[603] Fix | Delete
$link = 'https://en.support.wordpress.com/getting-more-site-traffic/';
[604] Fix | Delete
}
[605] Fix | Delete
[606] Fix | Delete
$fallback_message = '<p>';
[607] Fix | Delete
$fallback_message .= sprintf(
[608] Fix | Delete
wp_kses(
[609] Fix | Delete
/* Translators: Placeholder: link to the Jetpack support article. */
[610] Fix | Delete
__( 'There are no popular posts to display. Instead, your visitors will see a list of your recent posts below. <a href="%s" target="_blank">Want more traffic?</a>', 'jetpack' ),
[611] Fix | Delete
array(
[612] Fix | Delete
'a' => array(
[613] Fix | Delete
'href' => array(),
[614] Fix | Delete
'target' => array(),
[615] Fix | Delete
),
[616] Fix | Delete
)
[617] Fix | Delete
),
[618] Fix | Delete
esc_url( $link )
[619] Fix | Delete
);
[620] Fix | Delete
$fallback_message .= '<p>';
[621] Fix | Delete
[622] Fix | Delete
return $fallback_message;
[623] Fix | Delete
}
[624] Fix | Delete
[625] Fix | Delete
/**
[626] Fix | Delete
* Widget default option values.
[627] Fix | Delete
*/
[628] Fix | Delete
public static function defaults() {
[629] Fix | Delete
return array(
[630] Fix | Delete
'title' => esc_html__( 'Top Posts &amp; Pages', 'jetpack' ),
[631] Fix | Delete
'count' => absint( 10 ),
[632] Fix | Delete
'types' => array( 'post', 'page' ),
[633] Fix | Delete
'ordering' => 'views',
[634] Fix | Delete
'display' => 'text',
[635] Fix | Delete
);
[636] Fix | Delete
}
[637] Fix | Delete
[638] Fix | Delete
/**
[639] Fix | Delete
* Get most liked posts
[640] Fix | Delete
*
[641] Fix | Delete
* ONLY TO BE USED IN WPCOM
[642] Fix | Delete
*
[643] Fix | Delete
* @since 8.4.0 Added $types param
[644] Fix | Delete
*
[645] Fix | Delete
* @param int $count The maximum number of posts to be returned.
[646] Fix | Delete
* @param array $types The post types that should be returned. Optional. Defaults to 'post' and 'page'.
[647] Fix | Delete
*
[648] Fix | Delete
* @return array array of posts.
[649] Fix | Delete
*/
[650] Fix | Delete
public function get_by_likes( $count, $types = array( 'post', 'page' ) ) {
[651] Fix | Delete
$post_likes = wpl_get_blogs_most_liked_posts();
[652] Fix | Delete
if ( ! $post_likes ) {
[653] Fix | Delete
return array();
[654] Fix | Delete
}
[655] Fix | Delete
[656] Fix | Delete
return $this->get_posts( array_keys( $post_likes ), $count, $types );
[657] Fix | Delete
}
[658] Fix | Delete
[659] Fix | Delete
/**
[660] Fix | Delete
* Get the top posts based on views
[661] Fix | Delete
*
[662] Fix | Delete
* @since 8.4.0 Added $types param
[663] Fix | Delete
*
[664] Fix | Delete
* @param int $count The maximum number of posts to be returned.
[665] Fix | Delete
* @param array $args The widget arguments.
[666] Fix | Delete
* @param array $types The post types that should be returned.
[667] Fix | Delete
*
[668] Fix | Delete
* @return array array of posts. Defaults to 'post' and 'page'.
[669] Fix | Delete
*/
[670] Fix | Delete
public function get_by_views( $count, $args, $types = array( 'post', 'page' ) ) {
[671] Fix | Delete
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
[672] Fix | Delete
$post_views = wp_cache_get( "get_top_posts_$count", 'stats' );
[673] Fix | Delete
if ( false === $post_views ) {
[674] Fix | Delete
$stats_get_daily_history = stats_get_daily_history(
[675] Fix | Delete
false,
[676] Fix | Delete
get_current_blog_id(),
[677] Fix | Delete
'postviews',
[678] Fix | Delete
'post_id',
[679] Fix | Delete
false,
[680] Fix | Delete
2,
[681] Fix | Delete
'',
[682] Fix | Delete
$count * 2 + 10,
[683] Fix | Delete
true
[684] Fix | Delete
);
[685] Fix | Delete
$post_views = array_shift( $stats_get_daily_history );
[686] Fix | Delete
unset( $post_views[0] );
[687] Fix | Delete
wp_cache_add( "get_top_posts_$count", $post_views, 'stats', 1200 );
[688] Fix | Delete
}
[689] Fix | Delete
[690] Fix | Delete
return $this->get_posts( array_keys( $post_views ), $count, $types );
[691] Fix | Delete
}
[692] Fix | Delete
[693] Fix | Delete
/**
[694] Fix | Delete
* Filter the number of days used to calculate Top Posts for the Top Posts widget.
[695] Fix | Delete
* We do not recommend accessing more than 10 days of results at one.
[696] Fix | Delete
* When more than 10 days of results are accessed at once, results should be cached via the WordPress transients API.
[697] Fix | Delete
* Querying for -1 days will give results for an infinite number of days.
[698] Fix | Delete
*
[699] Fix | Delete
* @module widgets
[700] Fix | Delete
*
[701] Fix | Delete
* @since 3.9.3
[702] Fix | Delete
*
[703] Fix | Delete
* @param int 2 Number of days. Default is 2.
[704] Fix | Delete
* @param array $args The widget arguments.
[705] Fix | Delete
*/
[706] Fix | Delete
$days = (int) apply_filters( 'jetpack_top_posts_days', 2, $args );
[707] Fix | Delete
[708] Fix | Delete
/** Handling situations where the number of days makes no sense - allows for unlimited days where $days = -1 */
[709] Fix | Delete
if ( 0 === $days ) {
[710] Fix | Delete
$days = 2;
[711] Fix | Delete
}
[712] Fix | Delete
[713] Fix | Delete
$query_args = array(
[714] Fix | Delete
'max' => 11,
[715] Fix | Delete
'summarize' => 1,
[716] Fix | Delete
'num' => (int) $days,
[717] Fix | Delete
);
[718] Fix | Delete
$wpcom_stats = new WPCOM_Stats();
[719] Fix | Delete
$post_view_posts = $wpcom_stats->convert_stats_array_to_object(
[720] Fix | Delete
$wpcom_stats->get_top_posts( $query_args )
[721] Fix | Delete
);
[722] Fix | Delete
[723] Fix | Delete
if ( ! isset( $post_view_posts->summary ) || empty( $post_view_posts->summary->postviews ) ) {
[724] Fix | Delete
return array();
[725] Fix | Delete
}
[726] Fix | Delete
[727] Fix | Delete
$post_view_ids = array_filter( wp_list_pluck( $post_view_posts->summary->postviews, 'id' ) );
[728] Fix | Delete
[729] Fix | Delete
if ( ! $post_view_ids ) {
[730] Fix | Delete
return array();
[731] Fix | Delete
}
[732] Fix | Delete
[733] Fix | Delete
return $this->get_posts( $post_view_ids, $count, $types );
[734] Fix | Delete
}
[735] Fix | Delete
[736] Fix | Delete
/**
[737] Fix | Delete
* Get some posts if no posts are found in the stats API
[738] Fix | Delete
*
[739] Fix | Delete
* @since 8.4.0 Added $count and $types
[740] Fix | Delete
*
[741] Fix | Delete
* @param int $count The maximum number of posts to be returned.
[742] Fix | Delete
* @param array $types The post types that should be returned.
[743] Fix | Delete
* @return array
[744] Fix | Delete
*/
[745] Fix | Delete
public function get_fallback_posts( $count = 10, $types = array( 'post', 'page' ) ) {
[746] Fix | Delete
$post_query = new WP_Query();
[747] Fix | Delete
[748] Fix | Delete
if ( ! is_array( $types ) || empty( $types ) ) {
[749] Fix | Delete
$types = array( 'post', 'page' );
[750] Fix | Delete
}
[751] Fix | Delete
[752] Fix | Delete
$posts = $post_query->query(
[753] Fix | Delete
array(
[754] Fix | Delete
'posts_per_page' => $count,
[755] Fix | Delete
'post_status' => 'publish',
[756] Fix | Delete
'post_type' => $types,
[757] Fix | Delete
'no_found_rows' => true,
[758] Fix | Delete
'fields' => 'ids',
[759] Fix | Delete
)
[760] Fix | Delete
);
[761] Fix | Delete
[762] Fix | Delete
if ( ! $posts ) {
[763] Fix | Delete
return array();
[764] Fix | Delete
}
[765] Fix | Delete
[766] Fix | Delete
return $this->get_posts( $posts, $count, $types );
[767] Fix | Delete
}
[768] Fix | Delete
[769] Fix | Delete
/**
[770] Fix | Delete
* Get posts from an array of IDs
[771] Fix | Delete
*
[772] Fix | Delete
* @since 8.4.0 Added $types parameters
[773] Fix | Delete
*
[774] Fix | Delete
* @param array $post_ids The post IDs.
[775] Fix | Delete
* @param int $count The maximum number of posts to return.
[776] Fix | Delete
* @param array $types The post types that should be returned. Optional. Defaults to 'post', 'page'.
[777] Fix | Delete
* @return array
[778] Fix | Delete
*/
[779] Fix | Delete
public function get_posts( $post_ids, $count, $types = array( 'post', 'page' ) ) {
[780] Fix | Delete
$counter = 0;
[781] Fix | Delete
[782] Fix | Delete
if ( ! is_array( $types ) || empty( $types ) ) {
[783] Fix | Delete
$types = array( 'post', 'page' );
[784] Fix | Delete
}
[785] Fix | Delete
[786] Fix | Delete
$posts = array();
[787] Fix | Delete
foreach ( (array) $post_ids as $post_id ) {
[788] Fix | Delete
$post = get_post( $post_id );
[789] Fix | Delete
[790] Fix | Delete
if ( ! $post ) {
[791] Fix | Delete
continue;
[792] Fix | Delete
}
[793] Fix | Delete
[794] Fix | Delete
/**
[795] Fix | Delete
* Attachment pages use the 'inherit' post status by default.
[796] Fix | Delete
* To be able to remove attachment pages from private and password protect posts,
[797] Fix | Delete
* we need to replace their post status by the parent post' status.
[798] Fix | Delete
*/
[799] Fix | Delete
if ( 'inherit' === $post->post_status && 'attachment' === $post->post_type ) {
[800] Fix | Delete
$post->post_status = get_post_status( $post_id );
[801] Fix | Delete
}
[802] Fix | Delete
[803] Fix | Delete
// hide private and password protected posts.
[804] Fix | Delete
if ( 'publish' !== $post->post_status || ! empty( $post->post_password ) ) {
[805] Fix | Delete
continue;
[806] Fix | Delete
}
[807] Fix | Delete
[808] Fix | Delete
// Filter by chosen Post Types.
[809] Fix | Delete
if ( ! in_array( $post->post_type, $types, true ) ) {
[810] Fix | Delete
continue;
[811] Fix | Delete
}
[812] Fix | Delete
[813] Fix | Delete
// Both get HTML stripped etc on display.
[814] Fix | Delete
if ( empty( $post->post_title ) ) {
[815] Fix | Delete
$title_source = $post->post_content;
[816] Fix | Delete
$title = wp_html_excerpt( $title_source, 50 );
[817] Fix | Delete
$title .= '&hellip;';
[818] Fix | Delete
} else {
[819] Fix | Delete
$title = $post->post_title;
[820] Fix | Delete
}
[821] Fix | Delete
[822] Fix | Delete
$permalink = get_permalink( $post->ID );
[823] Fix | Delete
[824] Fix | Delete
$post_type = $post->post_type;
[825] Fix | Delete
[826] Fix | Delete
$posts[] = compact( 'title', 'permalink', 'post_id', 'post_type' );
[827] Fix | Delete
++$counter;
[828] Fix | Delete
[829] Fix | Delete
if ( $counter == $count ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
[830] Fix | Delete
break; // only need to load and show x number of likes.
[831] Fix | Delete
}
[832] Fix | Delete
}
[833] Fix | Delete
[834] Fix | Delete
/**
[835] Fix | Delete
* Filter the Top Posts and Pages.
[836] Fix | Delete
*
[837] Fix | Delete
* @module widgets
[838] Fix | Delete
*
[839] Fix | Delete
* @since 3.0.0
[840] Fix | Delete
*
[841] Fix | Delete
* @param array $posts Array of the most popular posts.
[842] Fix | Delete
* @param array $post_ids Array of Post IDs.
[843] Fix | Delete
* @param string $count Number of Top Posts we want to display.
[844] Fix | Delete
*/
[845] Fix | Delete
return apply_filters( 'jetpack_widget_get_top_posts', $posts, $post_ids, $count );
[846] Fix | Delete
}
[847] Fix | Delete
}
[848] Fix | Delete
[849] Fix | Delete
/**
[850] Fix | Delete
* Create a shortcode to display the widget anywhere.
[851] Fix | Delete
*
[852] Fix | Delete
* @since 3.9.2
[853] Fix | Delete
*
[854] Fix | Delete
* @param array $instance Saved values from database.
[855] Fix | Delete
*/
[856] Fix | Delete
function jetpack_do_top_posts_widget( $instance ) {
[857] Fix | Delete
// Post Types can't be entered as an array in the shortcode parameters.
[858] Fix | Delete
if ( isset( $instance['types'] ) && is_string( $instance['types'] ) ) {
[859] Fix | Delete
$instance['types'] = explode( ',', $instance['types'] );
[860] Fix | Delete
}
[861] Fix | Delete
[862] Fix | Delete
$instance = shortcode_atts(
[863] Fix | Delete
Jetpack_Top_Posts_Widget::defaults(),
[864] Fix | Delete
$instance,
[865] Fix | Delete
'jetpack_top_posts_widget'
[866] Fix | Delete
);
[867] Fix | Delete
[868] Fix | Delete
// Add a class to allow styling.
[869] Fix | Delete
$args = array(
[870] Fix | Delete
'before_widget' => sprintf( '<div class="%s">', 'jetpack_top_posts_widget' ),
[871] Fix | Delete
);
[872] Fix | Delete
[873] Fix | Delete
ob_start();
[874] Fix | Delete
the_widget( 'Jetpack_Top_Posts_Widget', $instance, $args );
[875] Fix | Delete
$output = ob_get_clean();
[876] Fix | Delete
[877] Fix | Delete
return $output;
[878] Fix | Delete
}
[879] Fix | Delete
add_shortcode( 'jetpack_top_posts_widget', 'jetpack_do_top_posts_widget' );
[880] Fix | Delete
[881] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function