WordPress.org

Make WordPress Core

Changeset 11161


Ignore:
Timestamp:
05/03/09 07:53:54 (5 years ago)
Author:
azaozz
Message:

Do not import sidebars by index after switching themes, props Denis-de-Bernardy, see #9695

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/widgets.php

    r11160 r11161  
    4141// look for "lost" widgets, this has to run at least on each theme change 
    4242function retrieve_widgets() { 
    43     global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets; 
     43    global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets; 
    4444 
    4545    $_sidebars_widgets = array(); 
    4646    $sidebars = array_keys($wp_registered_sidebars); 
     47 
     48    unset( $sidebars_widgets['array_version'] ); 
    4749 
    4850    $diff = array_diff( array_keys($sidebars_widgets), $sidebars ); 
    4951    if ( empty($diff) ) 
    5052        return; 
    51  
    52     unset( $sidebars_widgets['array_version'] ); 
    5353 
    5454    // Move the known-good ones first 
     
    6060    } 
    6161 
    62     // Assign to each unmatched registered sidebar the first available orphan 
    63     while ( ( $sidebar = array_shift( $sidebars ) ) && $widgets = array_shift( $sidebars_widgets ) ) 
    64         $_sidebars_widgets[ $sidebar ] = $widgets; 
    65  
    6662    // if new theme has less sidebars than the old theme 
    6763    if ( !empty($sidebars_widgets) ) { 
     
    7167        } 
    7268    } 
     69     
     70    // discard invalid, theme-specific widgets from sidebars 
     71    foreach ( $_sidebars_widgets as $sidebar => $widgets ) { 
     72        if ( !is_array($widgets) ) 
     73            continue; 
     74         
     75        $_widgets = array(); 
     76        foreach ( $widgets as $widget ) { 
     77            if ( isset($wp_registered_widgets[$widget]) ) 
     78                $_widgets[] = $widget; 
     79        } 
     80        $_sidebars_widgets[$sidebar] = $_widgets; 
     81    } 
    7382 
    7483    $sidebars_widgets = $_sidebars_widgets; 
    75     unset($_sidebars_widgets); 
     84    unset($_sidebars_widgets, $_widgets); 
    7685 
    7786    // find hidden/lost multi-widget instances 
     
    106115 
    107116    $sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']); 
    108     $sidebars_widgets['array_version'] = 3; 
    109117    wp_set_sidebars_widgets($sidebars_widgets); 
    110118} 
Note: See TracChangeset for help on using the changeset viewer.