Cache the Dashboard RSS Widgets HTML output to reduce the memory footprint of including SimplePie. Fixes #16927
git-svn-id: http://svn.automattic.com/wordpress/trunk@18228 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
bf9c99e1fa
commit
5df56d4bba
|
@ -1031,29 +1031,34 @@ function wp_dashboard_plugins_output() {
|
||||||
*/
|
*/
|
||||||
function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
|
function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
|
||||||
$loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
|
$loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
|
||||||
|
$doing_ajax = ( defined('DOING_AJAX') && DOING_AJAX );
|
||||||
|
|
||||||
if ( empty($check_urls) ) {
|
if ( empty($check_urls) ) {
|
||||||
$widgets = get_option( 'dashboard_widget_options' );
|
$widgets = get_option( 'dashboard_widget_options' );
|
||||||
if ( empty($widgets[$widget_id]['url']) ) {
|
if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) {
|
||||||
echo $loading;
|
echo $loading;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$check_urls = array( $widgets[$widget_id]['url'] );
|
$check_urls = array( $widgets[$widget_id]['url'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once ABSPATH . WPINC . '/class-feed.php';
|
$cache_key = 'dash_' . md5( $callback . implode(',', $check_urls) );
|
||||||
foreach ( $check_urls as $check_url ) {
|
if ( false !== ( $output = get_transient( $cache_key ) ) ) {
|
||||||
$cache = new WP_Feed_Cache_Transient('', md5($check_url), '');
|
echo $output;
|
||||||
if ( ! $cache->load() ) {
|
return true;
|
||||||
echo $loading;
|
}
|
||||||
return false;
|
|
||||||
}
|
if ( ! $doing_ajax ) {
|
||||||
|
echo $loading;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $callback && is_callable( $callback ) ) {
|
if ( $callback && is_callable( $callback ) ) {
|
||||||
$args = array_slice( func_get_args(), 2 );
|
$args = array_slice( func_get_args(), 2 );
|
||||||
array_unshift( $args, $widget_id );
|
array_unshift( $args, $widget_id );
|
||||||
|
ob_start();
|
||||||
call_user_func_array( $callback, $args );
|
call_user_func_array( $callback, $args );
|
||||||
|
set_transient( $cache_key, ob_get_flush(), 43200); // Default lifetime in cache of 12 hours (same as the feeds)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* @subpackage Administration
|
* @subpackage Administration
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
define('DOING_AJAX', true);
|
||||||
|
|
||||||
/** Load WordPress Bootstrap */
|
/** Load WordPress Bootstrap */
|
||||||
require_once( './admin.php' );
|
require_once( './admin.php' );
|
||||||
|
|
||||||
|
@ -18,19 +20,19 @@ send_nosniff_header();
|
||||||
switch ( $_GET['jax'] ) {
|
switch ( $_GET['jax'] ) {
|
||||||
|
|
||||||
case 'dashboard_incoming_links' :
|
case 'dashboard_incoming_links' :
|
||||||
wp_dashboard_incoming_links_output();
|
wp_dashboard_incoming_links();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'dashboard_primary' :
|
case 'dashboard_primary' :
|
||||||
wp_dashboard_rss_output( 'dashboard_primary' );
|
wp_dashboard_primary();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'dashboard_secondary' :
|
case 'dashboard_secondary' :
|
||||||
wp_dashboard_secondary_output();
|
wp_dashboard_secondary();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'dashboard_plugins' :
|
case 'dashboard_plugins' :
|
||||||
wp_dashboard_plugins_output();
|
wp_dashboard_plugins();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue