Make WordPress Core

Ticket #27538: 27538.5.patch

File 27538.5.patch, 4.1 KB (added by westonruter, 11 years ago)

Restore accidental removal of global $comments, $comment

  • src/wp-includes/default-widgets.php

    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 { 
    660660        }
    661661
    662662        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                }
    664667
    665                 if ( !is_array($cache) )
     668                if ( ! is_array( $cache ) ) {
    666669                        $cache = array();
     670                }
    667671
    668                 if ( ! isset( $args['widget_id'] ) )
     672                if ( ! isset( $args['widget_id'] ) ) {
    669673                        $args['widget_id'] = $this->id;
     674                }
    670675
    671676                if ( isset( $cache[ $args['widget_id'] ] ) ) {
    672677                        echo $cache[ $args['widget_id'] ];
    class WP_Widget_Recent_Posts extends WP_Widget { 
    723728
    724729                endif;
    725730
    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                }
    728737        }
    729738
    730739        function update( $new_instance, $old_instance ) {
    class WP_Widget_Recent_Comments extends WP_Widget { 
    807816        function widget( $args, $instance ) {
    808817                global $comments, $comment;
    809818
    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 ) ) {
    813824                        $cache = array();
     825                }
    814826
    815827                if ( ! isset( $args['widget_id'] ) )
    816828                        $args['widget_id'] = $this->id;
    class WP_Widget_Recent_Comments extends WP_Widget { 
    865877                $output .= $after_widget;
    866878
    867879                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                }
    870885        }
    871886
    872887        function update( $new_instance, $old_instance ) {
  • src/wp-includes/widgets.php

    diff --git src/wp-includes/widgets.php src/wp-includes/widgets.php
    index 5f2ea1b..2384f37 100644
    class WP_Widget { 
    163163                return array($this, 'form_callback');
    164164        }
    165165
     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
    166179        /** Generate the actual widget content.
    167180         *      Just finds the instance and calls widget().
    168181         *      Do NOT over-ride this function. */
    class WP_Widget { 
    189202                         * @param array     $args     An array of default widget arguments.
    190203                         */
    191204                        $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                        }
    194217                }
    195218        }
    196219
    class WP_Widget { 
    241264
    242265                                $old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array();
    243266
     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
    244272                                $instance = $this->update($new_instance, $old_instance);
    245273
     274                                if ( $this->is_preview() ) {
     275                                        wp_suspend_cache_addition( $was_cache_addition_suspended );
     276                                }
     277
    246278                                /**
    247279                                 * Filter a widget's settings before saving.
    248280                                 *