Make WordPress Core

Ticket #40203: 40203.1.patch

File 40203.1.patch, 3.6 KB (added by dingo_bastard, 7 years ago)

Patch for the latest version

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

     
    5656                }
    5757                $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
    5858
     59                $show_thumbnail = isset( $instance['show_thumbnail'] ) ? $instance['show_thumbnail'] : false;
     60
    5961                /**
    6062                 * Filters the arguments for the Recent Posts widget.
    6163                 *
     
    9799                                $title      = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
    98100                                ?>
    99101                                <li>
     102                                        <?php
     103                                        if ( $show_thumbnail && has_post_thumbnail( $recent_post->ID ) ) :
     104                                                echo wp_get_attachment_image( get_post_thumbnail_id( $recent_post->ID ) );
     105                                        endif;
     106                                        ?>
    100107                                        <a href="<?php the_permalink( $recent_post->ID ); ?>"><?php echo $title; ?></a>
    101108                                        <?php if ( $show_date ) : ?>
    102109                                                <span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span>
     
    119126         * @return array Updated settings to save.
    120127         */
    121128        public function update( $new_instance, $old_instance ) {
    122                 $instance              = $old_instance;
    123                 $instance['title']     = sanitize_text_field( $new_instance['title'] );
    124                 $instance['number']    = (int) $new_instance['number'];
    125                 $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
     129                $instance                   = $old_instance;
     130                $instance['title']          = sanitize_text_field( $new_instance['title'] );
     131                $instance['number']         = (int) $new_instance['number'];
     132                $instance['show_date']      = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
     133                $instance['show_thumbnail'] = isset( $new_instance['show_thumbnail'] ) ? (bool) $new_instance['show_thumbnail'] : false;
    126134                return $instance;
    127135        }
    128136
     
    134142         * @param array $instance Current settings.
    135143         */
    136144        public function form( $instance ) {
    137                 $title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
    138                 $number    = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
    139                 $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
     145                $title          = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
     146                $number         = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
     147                $show_date      = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
     148                $show_thumbnail = isset( $instance['show_thumbnail'] ) ? (bool) $instance['show_thumbnail'] : false;
    140149                ?>
    141150                <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
    142151                <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p>
     
    146155
    147156                <p><input class="checkbox" type="checkbox"<?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" />
    148157                <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p>
     158
     159                <p><input class="checkbox" type="checkbox"<?php checked( $show_thumbnail ); ?> id="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>" name="<?php echo $this->get_field_name( 'show_thumbnail' ); ?>" />
     160                <label for="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>"><?php _e( 'Display post thumbnail?' ); ?></label></p>
    149161                <?php
    150162        }
    151163}