From 7ee77760af9398964f49f043d191818120013873 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 18 Oct 2017 00:34:46 +0000 Subject: [PATCH] Widgets: Use a `foreach` loop instead of The Loop to iterate over posts in Recent Posts widget to avoid needing to reset a polluted global `$post`. Props welcher, westonruter. Amends [14607]. See #12320. Fixes #37312. Built from https://develop.svn.wordpress.org/trunk@41890 git-svn-id: http://core.svn.wordpress.org/trunk@41724 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/version.php | 2 +- .../widgets/class-wp-widget-recent-posts.php | 47 ++++++++++--------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/wp-includes/version.php b/wp-includes/version.php index d7ddbe3175..cd9d449d52 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-beta2-41889'; +$wp_version = '4.9-beta2-41890'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-includes/widgets/class-wp-widget-recent-posts.php b/wp-includes/widgets/class-wp-widget-recent-posts.php index c8d19055b4..37843c3a8b 100644 --- a/wp-includes/widgets/class-wp-widget-recent-posts.php +++ b/wp-includes/widgets/class-wp-widget-recent-posts.php @@ -51,8 +51,9 @@ class WP_Widget_Recent_Posts extends WP_Widget { $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; - if ( ! $number ) + if ( ! $number ) { $number = 5; + } $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false; /** @@ -70,31 +71,35 @@ class WP_Widget_Recent_Posts extends WP_Widget { 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', - 'ignore_sticky_posts' => true + 'ignore_sticky_posts' => true, ), $instance ) ); - if ($r->have_posts()) : + if ( ! $r->have_posts() ) { + return; + } ?> - - - + +