WordPress.org

Make WordPress Core

Changeset 19455


Ignore:
Timestamp:
11/26/11 06:16:43 (2 years ago)
Author:
azaozz
Message:

Check the sidebar class for orphaned sidebars, match sidebars by id while retrieving orphans and the theme has not changed, props SergeyBiryukov, fixes #19350

Location:
trunk
Files:
2 edited

Legend:

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

    r19454 r19455  
    9797            register_sidebar(array( 
    9898                'name' => __( 'Inactive Sidebar (not used)' ), 
    99                 'id' => 'orphaned_widgets-' . $sidebar_id, 
     99                'id' => $sidebar_id, 
    100100                'class' => 'inactive-sidebar orphan-sidebar', 
    101101                'description' => __( 'This sidebar is no longer available and does not show anywhere on your site. Remove each of the widgets below to fully remove this inactive sidebar.' ), 
     
    345345<?php 
    346346foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) { 
    347     if ( 'wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) { 
     347    if ( false !== strpos( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) { 
    348348        $wrap_class = 'widgets-holder-wrap'; 
    349349        if ( !empty( $registered_sidebar['class'] ) ) 
     
    377377$i = 0; 
    378378foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) { 
    379     if ( 'wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) 
     379    if ( false !== strpos( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) 
    380380        continue; 
    381381 
  • trunk/wp-includes/widgets.php

    r19340 r19455  
    11581158        $sidebars_widgets = wp_get_sidebars_widgets(); 
    11591159 
    1160     retrieve_widgets(); 
     1160    retrieve_widgets(true); 
    11611161} 
    11621162 
    11631163// look for "lost" widgets, this has to run at least on each theme change 
    1164 function retrieve_widgets() { 
     1164function retrieve_widgets($theme_changed = false) { 
    11651165    global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets; 
    11661166 
    11671167    $registered_sidebar_keys = array_keys( $wp_registered_sidebars ); 
     1168    $orphaned = 0; 
    11681169 
    11691170    $old_sidebars_widgets = get_theme_mod( 'sidebars_widgets' ); 
     
    11721173        $_sidebars_widgets = $old_sidebars_widgets['data']; 
    11731174        remove_theme_mod( 'sidebars_widgets' ); 
    1174   
    1175         $orphaned = 0; 
    11761175 
    11771176        foreach ( $_sidebars_widgets as $sidebar => $widgets ) { 
     
    12031202        unset( $sidebars_widgets['wp_inactive_widgets'] ); 
    12041203 
    1205         foreach ( $wp_registered_sidebars as $id => $settings ) 
    1206             $_sidebars_widgets[$id] = array_shift( $sidebars_widgets ); 
    1207  
    1208         $orphaned = 0; 
     1204        foreach ( $wp_registered_sidebars as $id => $settings ) { 
     1205            if ( $theme_changed ) { 
     1206                $_sidebars_widgets[$id] = array_shift( $sidebars_widgets ); 
     1207            } else { 
     1208                // no theme change, grab only sidebars that are currently registered 
     1209                if ( isset( $sidebars_widgets[$id] ) ) { 
     1210                    $_sidebars_widgets[$id] = $sidebars_widgets[$id]; 
     1211                    unset( $sidebars_widgets[$id] ); 
     1212                } 
     1213            } 
     1214        } 
    12091215 
    12101216        foreach ( $sidebars_widgets as $val ) { 
Note: See TracChangeset for help on using the changeset viewer.