diff --git src/wp-includes/default-widgets.php src/wp-includes/default-widgets.php
index 68048c3..69f7261 100644
|
|
|
class WP_Widget_Recent_Posts extends WP_Widget { |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | function widget($args, $instance) { |
| 663 | | $cache = wp_cache_get('widget_recent_posts', 'widget'); |
| | 663 | $cache = array(); |
| | 664 | if ( ! $this->is_preview() ) { |
| | 665 | $cache = wp_cache_get( 'widget_recent_posts', 'widget' ); |
| | 666 | } |
| 664 | 667 | |
| 665 | | if ( !is_array($cache) ) |
| | 668 | if ( ! is_array( $cache ) ) { |
| 666 | 669 | $cache = array(); |
| | 670 | } |
| 667 | 671 | |
| 668 | | if ( ! isset( $args['widget_id'] ) ) |
| | 672 | if ( ! isset( $args['widget_id'] ) ) { |
| 669 | 673 | $args['widget_id'] = $this->id; |
| | 674 | } |
| 670 | 675 | |
| 671 | 676 | if ( isset( $cache[ $args['widget_id'] ] ) ) { |
| 672 | 677 | echo $cache[ $args['widget_id'] ]; |
| … |
… |
class WP_Widget_Recent_Posts extends WP_Widget { |
| 723 | 728 | |
| 724 | 729 | endif; |
| 725 | 730 | |
| 726 | | $cache[$args['widget_id']] = ob_get_flush(); |
| 727 | | wp_cache_set('widget_recent_posts', $cache, 'widget'); |
| | 731 | if ( ! $this->is_preview() ) { |
| | 732 | $cache[ $args['widget_id'] ] = ob_get_flush(); |
| | 733 | wp_cache_set( 'widget_recent_posts', $cache, 'widget' ); |
| | 734 | } else { |
| | 735 | ob_flush(); |
| | 736 | } |
| 728 | 737 | } |
| 729 | 738 | |
| 730 | 739 | function update( $new_instance, $old_instance ) { |
| … |
… |
class WP_Widget_Recent_Comments extends WP_Widget { |
| 805 | 814 | } |
| 806 | 815 | |
| 807 | 816 | function widget( $args, $instance ) { |
| 808 | | global $comments, $comment; |
| 809 | | |
| 810 | | $cache = wp_cache_get('widget_recent_comments', 'widget'); |
| 811 | | |
| 812 | | if ( ! is_array( $cache ) ) |
| | 817 | $cache = array(); |
| | 818 | if ( ! $this->is_preview() ) { |
| | 819 | $cache = wp_cache_get('widget_recent_comments', 'widget'); |
| | 820 | } |
| | 821 | if ( ! is_array( $cache ) ) { |
| 813 | 822 | $cache = array(); |
| | 823 | } |
| 814 | 824 | |
| 815 | 825 | if ( ! isset( $args['widget_id'] ) ) |
| 816 | 826 | $args['widget_id'] = $this->id; |
| … |
… |
class WP_Widget_Recent_Comments extends WP_Widget { |
| 865 | 875 | $output .= $after_widget; |
| 866 | 876 | |
| 867 | 877 | echo $output; |
| 868 | | $cache[$args['widget_id']] = $output; |
| 869 | | wp_cache_set('widget_recent_comments', $cache, 'widget'); |
| | 878 | |
| | 879 | if ( ! $this->is_preview() ) { |
| | 880 | $cache[ $args['widget_id'] ] = $output; |
| | 881 | wp_cache_set( 'widget_recent_comments', $cache, 'widget' ); |
| | 882 | } |
| 870 | 883 | } |
| 871 | 884 | |
| 872 | 885 | function update( $new_instance, $old_instance ) { |
diff --git src/wp-includes/widgets.php src/wp-includes/widgets.php
index 5f2ea1b..2384f37 100644
|
|
|
class WP_Widget { |
| 163 | 163 | return array($this, 'form_callback'); |
| 164 | 164 | } |
| 165 | 165 | |
| | 166 | /** |
| | 167 | * Determine if we're in the Customizer; if true, then the object cache gets |
| | 168 | * suspended and widgets should check this to decide whether they should |
| | 169 | * store anything persistently to the object cache, to transients, or |
| | 170 | * anywhere else. |
| | 171 | * |
| | 172 | * @return bool |
| | 173 | */ |
| | 174 | function is_preview() { |
| | 175 | global $wp_customize; |
| | 176 | return ( isset( $wp_customize ) && $wp_customize->is_preview() ) ; |
| | 177 | } |
| | 178 | |
| 166 | 179 | /** Generate the actual widget content. |
| 167 | 180 | * Just finds the instance and calls widget(). |
| 168 | 181 | * Do NOT over-ride this function. */ |
| … |
… |
class WP_Widget { |
| 189 | 202 | * @param array $args An array of default widget arguments. |
| 190 | 203 | */ |
| 191 | 204 | $instance = apply_filters( 'widget_display_callback', $instance, $this, $args ); |
| 192 | | if ( false !== $instance ) |
| 193 | | $this->widget($args, $instance); |
| | 205 | if ( false !== $instance ) { |
| | 206 | $was_cache_addition_suspended = wp_suspend_cache_addition(); |
| | 207 | if ( $this->is_preview() && ! $was_cache_addition_suspended ) { |
| | 208 | wp_suspend_cache_addition( true ); |
| | 209 | } |
| | 210 | |
| | 211 | $this->widget( $args, $instance ); |
| | 212 | |
| | 213 | if ( $this->is_preview() ) { |
| | 214 | wp_suspend_cache_addition( $was_cache_addition_suspended ); |
| | 215 | } |
| | 216 | } |
| 194 | 217 | } |
| 195 | 218 | } |
| 196 | 219 | |
| … |
… |
class WP_Widget { |
| 241 | 264 | |
| 242 | 265 | $old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array(); |
| 243 | 266 | |
| | 267 | $was_cache_addition_suspended = wp_suspend_cache_addition(); |
| | 268 | if ( $this->is_preview() && ! $was_cache_addition_suspended ) { |
| | 269 | wp_suspend_cache_addition( true ); |
| | 270 | } |
| | 271 | |
| 244 | 272 | $instance = $this->update($new_instance, $old_instance); |
| 245 | 273 | |
| | 274 | if ( $this->is_preview() ) { |
| | 275 | wp_suspend_cache_addition( $was_cache_addition_suspended ); |
| | 276 | } |
| | 277 | |
| 246 | 278 | /** |
| 247 | 279 | * Filter a widget's settings before saving. |
| 248 | 280 | * |