Make WordPress Core

Changeset 34464


Ignore:
Timestamp:
09/24/2015 12:16:16 AM (9 years ago)
Author:
wonderboymusic
Message:

Recent Posts Widget: remove HTML fragment caching. The cache currently doesn't work cross-scheme and causes mixed content issues for links. The widget was written pre-$split_the_query, after which post objects can be served from the cache.

Fixes #27565.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-recent-posts.php

    r34436 r34464  
    2121        parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
    2222        $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') );
    2723    }
    2824
     
    3228     */
    3329    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 
    4330        if ( ! isset( $args['widget_id'] ) ) {
    4431            $args['widget_id'] = $this->id;
    4532        }
    46 
    47         if ( isset( $cache[ $args['widget_id'] ] ) ) {
    48             echo $cache[ $args['widget_id'] ];
    49             return;
    50         }
    51 
    52         ob_start();
    5333
    5434        $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );
     
    10080
    10181        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         }
    10982    }
    11083
     
    11992        $instance['number'] = (int) $new_instance['number'];
    12093        $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 
    12794        return $instance;
    128     }
    129 
    130     /**
    131      * @access public
    132      */
    133     public function flush_widget_cache() {
    134         wp_cache_delete('widget_recent_posts', 'widget');
    13595    }
    13696
Note: See TracChangeset for help on using the changeset viewer.