Ticket #31085: 31085.diff
File 31085.diff, 3.8 KB (added by , 10 years ago) |
---|
-
src/wp-includes/default-widgets.php
705 705 /** This filter is documented in wp-includes/default-widgets.php */ 706 706 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 707 707 708 $cpt = isset( $instance['cpt'] ) ? $instance['cpt'] : 'post'; 709 708 710 $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; 709 711 if ( ! $number ) 710 712 $number = 5; … … 720 722 * @param array $args An array of arguments used to retrieve the recent posts. 721 723 */ 722 724 $r = new WP_Query( apply_filters( 'widget_posts_args', array( 725 'post_type' => $cpt, 723 726 'posts_per_page' => $number, 724 727 'no_found_rows' => true, 725 728 'post_status' => 'publish', … … 760 763 public function update( $new_instance, $old_instance ) { 761 764 $instance = $old_instance; 762 765 $instance['title'] = strip_tags($new_instance['title']); 766 $instance['cpt'] = stripslashes($new_instance['cpt']); 763 767 $instance['number'] = (int) $new_instance['number']; 764 768 $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false; 765 769 $this->flush_widget_cache(); … … 776 780 } 777 781 778 782 public function form( $instance ) { 779 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; 780 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; 781 $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false; 783 $cpt_args = apply_filters( 'widget_posts_cpt_args', array( 784 'public' => true, 785 '_builtin' => false, 786 ) ); 787 788 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; 789 $current_cpt = isset( $instance['cpt'] ) ? $instance['cpt'] : 'post'; 790 $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; 791 $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false; 792 $has_cpts = !empty( get_post_types( $cpt_args ) ) ? true : false; 782 793 ?> 783 794 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 784 795 <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> 785 796 797 <?php // Show post type selector if site has CPT's 798 if( apply_filters( 'widget_posts_cpt_selector', $has_cpts ) ): ?> 799 <p><label for="<?php echo $this->get_field_id('cpt'); ?>"><?php _e('Post type of posts to show:') ?></label> 800 <select class="widefat" id="<?php echo $this->get_field_id('cpt'); ?>" name="<?php echo $this->get_field_name('cpt'); ?>"> 801 <option value="any" <?php selected('any', $current_cpt) ?>><?php _e( 'All' ); ?></option> 802 <option value="post" <?php selected('post', $current_cpt) ?>><?php _e( 'Posts' ); ?></option> 803 <?php foreach ( get_post_types( $cpt_args, 'objects' ) as $post_type => $cpt ) : 804 if ( empty($cpt->labels->name) ) 805 continue; 806 ?> 807 <option value="<?php echo esc_attr($post_type) ?>" <?php selected($post_type, $current_cpt) ?>><?php echo $cpt->labels->name; ?></option> 808 <?php endforeach; ?> 809 </select></p> 810 <?php endif; ?> 811 786 812 <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label> 787 813 <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p> 788 814