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:
parent
6e68c7bfd9
commit
b79223097c
|
@ -1246,7 +1246,11 @@ function preview_theme_ob_filter_callback( $matches ) {
|
||||||
* @param string $stylesheet Stylesheet name.
|
* @param string $stylesheet Stylesheet name.
|
||||||
*/
|
*/
|
||||||
function switch_theme($template, $stylesheet) {
|
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();
|
$old_theme = get_current_theme();
|
||||||
|
|
||||||
|
|
|
@ -1201,10 +1201,6 @@ function check_theme_switched() {
|
||||||
if ( ! is_array( $sidebars_widgets ) )
|
if ( ! is_array( $sidebars_widgets ) )
|
||||||
$sidebars_widgets = wp_get_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();
|
retrieve_widgets();
|
||||||
update_option( 'theme_switched', false );
|
update_option( 'theme_switched', false );
|
||||||
}
|
}
|
||||||
|
@ -1214,9 +1210,11 @@ function check_theme_switched() {
|
||||||
function retrieve_widgets() {
|
function retrieve_widgets() {
|
||||||
global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
|
global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
|
||||||
|
|
||||||
$key = md5( get_current_theme() );
|
$old_sidebars_widgets = get_theme_mod( 'sidebars_widgets' );
|
||||||
if ( false !== ( $_sidebars_widgets = get_transient( "old_widgets_{$key}" ) ) ) {
|
if ( is_array( $old_sidebars_widgets ) ) {
|
||||||
delete_transient( "old_widgets_{$key}" );
|
// time() that sidebars were stored is in $old_sidebars_widgets['time']
|
||||||
|
$_sidebars_widgets = $old_sidebars_widgets['data'];
|
||||||
|
remove_theme_mod( 'sidebars_widgets' );
|
||||||
} else {
|
} else {
|
||||||
if ( ! is_array( $sidebars_widgets ) )
|
if ( ! is_array( $sidebars_widgets ) )
|
||||||
$sidebars_widgets = wp_get_sidebars_widgets();
|
$sidebars_widgets = wp_get_sidebars_widgets();
|
||||||
|
|
Loading…
Reference in New Issue