Changeset 34464
- Timestamp:
- 09/24/2015 12:16:16 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/widgets/class-wp-widget-recent-posts.php
r34436 r34464 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 … … 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 47 if ( isset( $cache[ $args['widget_id'] ] ) ) {48 echo $cache[ $args['widget_id'] ];49 return;50 }51 52 ob_start();53 33 54 34 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' ); … … 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 … … 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 }129 130 /**131 * @access public132 */133 public function flush_widget_cache() {134 wp_cache_delete('widget_recent_posts', 'widget');135 95 } 136 96
Note: See TracChangeset
for help on using the changeset viewer.