Make WordPress Core

Ticket #34892: 34892.patch

File 34892.patch, 2.6 KB (added by anthony.lim, 9 years ago)

Added a text field for PHP date format and use this for displaying the post date, if supplied.

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

     
    5252                if ( ! $number )
    5353                        $number = 5;
    5454                $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
     55                $format = ( ! empty( $instance['format'] ) ) ? $instance['format'] : null;
    5556
    5657                /**
    5758                 * Filter the arguments for the Recent Posts widget.
     
    8081                        <li>
    8182                                <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
    8283                        <?php if ( $show_date ) : ?>
    83                                 <span class="post-date"><?php echo get_the_date(); ?></span>
     84                                <span class="post-date"><?php echo ( $format===null ? get_the_date() : get_the_date($format) ); ?></span>
    8485                        <?php endif; ?>
    8586                        </li>
    8687                <?php endwhile; ?>
     
    109110                $instance['title'] = sanitize_text_field( $new_instance['title'] );
    110111                $instance['number'] = (int) $new_instance['number'];
    111112                $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
     113                $instance['format'] = sanitize_text_field( trim($new_instance['format']) );
    112114                return $instance;
    113115        }
    114116
     
    124126                $title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
    125127                $number    = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
    126128                $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
     129                $format    = isset( $instance['format'] ) ? esc_attr( $instance['format'] ) : '';
    127130?>
    128131                <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
    129132                <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>
     
    133136
    134137                <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' ); ?>" />
    135138                <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p>
     139
     140        <p><label for="<?php echo $this->get_field_id( 'format' ); ?>"><?php _e( 'PHP date format:' ); ?></label>
     141                <input class="widefat" id="<?php echo $this->get_field_id( 'format' ); ?>" name="<?php echo $this->get_field_name( 'format' ); ?>" placeholder="<?php _e('Leave blank for default'); ?>" type="text" value="<?php echo $format; ?>" /></p>
    136142<?php
    137143        }
    138144}