Ticket #27565: 27565.3.diff
File 27565.3.diff, 2.3 KB (added by , 9 years ago) |
---|
-
src/wp-includes/widgets/class-wp-widget-recent-posts.php
20 20 $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "Your site’s most recent Posts.") ); 21 21 parent::__construct('recent-posts', __('Recent Posts'), $widget_ops); 22 22 $this->alt_option_name = 'widget_recent_entries'; 23 24 add_action( 'save_post', array($this, 'flush_widget_cache') );25 add_action( 'deleted_post', array($this, 'flush_widget_cache') );26 add_action( 'switch_theme', array($this, 'flush_widget_cache') );27 23 } 28 24 29 25 /** … … 31 27 * @param array $instance 32 28 */ 33 29 public function widget( $args, $instance ) { 34 $cache = array();35 if ( ! $this->is_preview() ) {36 $cache = wp_cache_get( 'widget_recent_posts', 'widget' );37 }38 39 if ( ! is_array( $cache ) ) {40 $cache = array();41 }42 43 30 if ( ! isset( $args['widget_id'] ) ) { 44 31 $args['widget_id'] = $this->id; 45 32 } 46 33 47 if ( isset( $cache[ $args['widget_id'] ] ) ) {48 echo $cache[ $args['widget_id'] ];49 return;50 }51 52 ob_start();53 54 34 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' ); 55 35 56 36 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ … … 99 79 wp_reset_postdata(); 100 80 101 81 endif; 102 103 if ( ! $this->is_preview() ) {104 $cache[ $args['widget_id'] ] = ob_get_flush();105 wp_cache_set( 'widget_recent_posts', $cache, 'widget' );106 } else {107 ob_end_flush();108 }109 82 } 110 83 111 84 /** … … 118 91 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 119 92 $instance['number'] = (int) $new_instance['number']; 120 93 $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false; 121 $this->flush_widget_cache();122 123 $alloptions = wp_cache_get( 'alloptions', 'options' );124 if ( isset($alloptions['widget_recent_entries']) )125 delete_option('widget_recent_entries');126 127 94 return $instance; 128 95 } 129 96 130 97 /** 131 * @access public132 */133 public function flush_widget_cache() {134 wp_cache_delete('widget_recent_posts', 'widget');135 }136 137 /**138 98 * @param array $instance 139 99 */ 140 100 public function form( $instance ) {