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
This commit is contained in:
azaozz 2011-09-08 19:25:20 +00:00
parent 6e68c7bfd9
commit b79223097c
2 changed files with 10 additions and 8 deletions

View File

@ -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();

View File

@ -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();