diff --git src/wp-includes/default-widgets.php src/wp-includes/default-widgets.php
index 68048c3..8a803a4 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 { |
807 | 816 | function widget( $args, $instance ) { |
808 | 817 | global $comments, $comment; |
809 | 818 | |
810 | | $cache = wp_cache_get('widget_recent_comments', 'widget'); |
811 | | |
812 | | if ( ! is_array( $cache ) ) |
| 819 | $cache = array(); |
| 820 | if ( ! $this->is_preview() ) { |
| 821 | $cache = wp_cache_get('widget_recent_comments', 'widget'); |
| 822 | } |
| 823 | if ( ! is_array( $cache ) ) { |
813 | 824 | $cache = array(); |
| 825 | } |
814 | 826 | |
815 | 827 | if ( ! isset( $args['widget_id'] ) ) |
816 | 828 | $args['widget_id'] = $this->id; |
… |
… |
class WP_Widget_Recent_Comments extends WP_Widget { |
865 | 877 | $output .= $after_widget; |
866 | 878 | |
867 | 879 | echo $output; |
868 | | $cache[$args['widget_id']] = $output; |
869 | | wp_cache_set('widget_recent_comments', $cache, 'widget'); |
| 880 | |
| 881 | if ( ! $this->is_preview() ) { |
| 882 | $cache[ $args['widget_id'] ] = $output; |
| 883 | wp_cache_set( 'widget_recent_comments', $cache, 'widget' ); |
| 884 | } |
870 | 885 | } |
871 | 886 | |
872 | 887 | 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 | * |