From b79223097c91545999707ba5f5b70ea06fe34c0e Mon Sep 17 00:00:00 2001 From: azaozz Date: Thu, 8 Sep 2011 19:25:20 +0000 Subject: [PATCH] Use theme mods instead of transients for storing the previous theme's widgets config, props aaroncampbell, see #17979 git-svn-id: http://svn.automattic.com/wordpress/trunk@18654 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/theme.php | 6 +++++- wp-includes/widgets.php | 12 +++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 6404ee0ca6..c6d3b3cccd 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -1246,7 +1246,11 @@ function preview_theme_ob_filter_callback( $matches ) { * @param string $stylesheet Stylesheet name. */ function switch_theme($template, $stylesheet) { - global $wp_theme_directories; + global $wp_theme_directories, $sidebars_widgets; + + if ( ! is_array( $sidebars_widgets ) ) + $sidebars_widgets = wp_get_sidebars_widgets(); + set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $sidebars_widgets ) ); $old_theme = get_current_theme(); diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php index e759e67e89..c2ecd5d20a 100644 --- a/wp-includes/widgets.php +++ b/wp-includes/widgets.php @@ -1201,10 +1201,6 @@ function check_theme_switched() { if ( ! is_array( $sidebars_widgets ) ) $sidebars_widgets = wp_get_sidebars_widgets(); - $key = md5( $old_theme ); - // Store widgets for 1 week so we can restore if needed - set_transient( 'old_widgets_' . $key, $sidebars_widgets, 604800 ); - retrieve_widgets(); update_option( 'theme_switched', false ); } @@ -1214,9 +1210,11 @@ function check_theme_switched() { function retrieve_widgets() { global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets; - $key = md5( get_current_theme() ); - if ( false !== ( $_sidebars_widgets = get_transient( "old_widgets_{$key}" ) ) ) { - delete_transient( "old_widgets_{$key}" ); + $old_sidebars_widgets = get_theme_mod( 'sidebars_widgets' ); + if ( is_array( $old_sidebars_widgets ) ) { + // time() that sidebars were stored is in $old_sidebars_widgets['time'] + $_sidebars_widgets = $old_sidebars_widgets['data']; + remove_theme_mod( 'sidebars_widgets' ); } else { if ( ! is_array( $sidebars_widgets ) ) $sidebars_widgets = wp_get_sidebars_widgets();