Make WordPress Core

Ticket #37312: 37312.1.diff

File 37312.1.diff, 2.2 KB (added by westonruter, 7 years ago)

Add missing printing of permalink; bring code up to par with WPCS

  • src/wp-includes/widgets/class-wp-widget-recent-posts.php

    diff --git src/wp-includes/widgets/class-wp-widget-recent-posts.php src/wp-includes/widgets/class-wp-widget-recent-posts.php
    index c8d19055b4..37843c3a8b 100644
    class WP_Widget_Recent_Posts extends WP_Widget { 
    5151                $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    5252
    5353                $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
    54                 if ( ! $number )
     54                if ( ! $number ) {
    5555                        $number = 5;
     56                }
    5657                $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
    5758
    5859                /**
    class WP_Widget_Recent_Posts extends WP_Widget { 
    7071                        'posts_per_page'      => $number,
    7172                        'no_found_rows'       => true,
    7273                        'post_status'         => 'publish',
    73                         'ignore_sticky_posts' => true
     74                        'ignore_sticky_posts' => true,
    7475                ), $instance ) );
    7576
    76                 if ($r->have_posts()) :
     77                if ( ! $r->have_posts() ) {
     78                        return;
     79                }
    7780                ?>
    7881                <?php echo $args['before_widget']; ?>
    79                 <?php if ( $title ) {
     82                <?php
     83                if ( $title ) {
    8084                        echo $args['before_title'] . $title . $args['after_title'];
    81                 } ?>
     85                }
     86                ?>
    8287                <ul>
    83                 <?php while ( $r->have_posts() ) : $r->the_post(); ?>
    84                         <li>
    85                                 <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : _e( '(no title)' ); ?></a>
    86                         <?php if ( $show_date ) : ?>
    87                                 <span class="post-date"><?php echo get_the_date(); ?></span>
    88                         <?php endif; ?>
    89                         </li>
    90                 <?php endwhile; ?>
     88                        <?php foreach ( $r->posts as $recent_post ) : ?>
     89                                <?php
     90                                $post_title = get_the_title( $recent_post->ID );
     91                                $title      = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
     92                                ?>
     93                                <li>
     94                                        <a href="<?php the_permalink( $recent_post->ID ); ?>"><?php echo $title ; ?></a>
     95                                        <?php if ( $show_date ) : ?>
     96                                                <span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span>
     97                                        <?php endif; ?>
     98                                </li>
     99                        <?php endforeach; ?>
    91100                </ul>
    92                 <?php echo $args['after_widget']; ?>
    93101                <?php
    94                 // Reset the global $the_post as this query will have stomped on it
    95                 wp_reset_postdata();
    96 
    97                 endif;
     102                echo $args['after_widget'];
    98103        }
    99104
    100105        /**