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. Built from https://develop.svn.wordpress.org/trunk@34464 git-svn-id: http://core.svn.wordpress.org/trunk@34428 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
a2914473cc
commit
ad2ddad259
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.4-alpha-34463';
|
||||
$wp_version = '4.4-alpha-34464';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
|
@ -20,10 +20,6 @@ class WP_Widget_Recent_Posts extends WP_Widget {
|
|||
$widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "Your site’s most recent Posts.") );
|
||||
parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
|
||||
$this->alt_option_name = 'widget_recent_entries';
|
||||
|
||||
add_action( 'save_post', array($this, 'flush_widget_cache') );
|
||||
add_action( 'deleted_post', array($this, 'flush_widget_cache') );
|
||||
add_action( 'switch_theme', array($this, 'flush_widget_cache') );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,26 +27,10 @@ class WP_Widget_Recent_Posts extends WP_Widget {
|
|||
* @param array $instance
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
$cache = array();
|
||||
if ( ! $this->is_preview() ) {
|
||||
$cache = wp_cache_get( 'widget_recent_posts', 'widget' );
|
||||
}
|
||||
|
||||
if ( ! is_array( $cache ) ) {
|
||||
$cache = array();
|
||||
}
|
||||
|
||||
if ( ! isset( $args['widget_id'] ) ) {
|
||||
$args['widget_id'] = $this->id;
|
||||
}
|
||||
|
||||
if ( isset( $cache[ $args['widget_id'] ] ) ) {
|
||||
echo $cache[ $args['widget_id'] ];
|
||||
return;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );
|
||||
|
||||
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
|
||||
|
@ -99,13 +79,6 @@ class WP_Widget_Recent_Posts extends WP_Widget {
|
|||
wp_reset_postdata();
|
||||
|
||||
endif;
|
||||
|
||||
if ( ! $this->is_preview() ) {
|
||||
$cache[ $args['widget_id'] ] = ob_get_flush();
|
||||
wp_cache_set( 'widget_recent_posts', $cache, 'widget' );
|
||||
} else {
|
||||
ob_end_flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,22 +91,9 @@ class WP_Widget_Recent_Posts extends WP_Widget {
|
|||
$instance['title'] = sanitize_text_field( $new_instance['title'] );
|
||||
$instance['number'] = (int) $new_instance['number'];
|
||||
$instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
|
||||
$this->flush_widget_cache();
|
||||
|
||||
$alloptions = wp_cache_get( 'alloptions', 'options' );
|
||||
if ( isset($alloptions['widget_recent_entries']) )
|
||||
delete_option('widget_recent_entries');
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @access public
|
||||
*/
|
||||
public function flush_widget_cache() {
|
||||
wp_cache_delete('widget_recent_posts', 'widget');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $instance
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue