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

git-svn-id: http://svn.automattic.com/wordpress/trunk@19455 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2011-11-26 06:16:43 +00:00
parent 6da2f73c78
commit a55d901b12
2 changed files with 17 additions and 11 deletions

View File

@ -96,7 +96,7 @@ foreach ( $sidebars_widgets as $sidebar_id => $widgets ) {
if ( ! empty( $widgets ) ) { // register the inactive_widgets area as sidebar if ( ! empty( $widgets ) ) { // register the inactive_widgets area as sidebar
register_sidebar(array( register_sidebar(array(
'name' => __( 'Inactive Sidebar (not used)' ), 'name' => __( 'Inactive Sidebar (not used)' ),
'id' => 'orphaned_widgets-' . $sidebar_id, 'id' => $sidebar_id,
'class' => 'inactive-sidebar orphan-sidebar', 'class' => 'inactive-sidebar orphan-sidebar',
'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.' ), '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.' ),
'before_widget' => '', 'before_widget' => '',
@ -344,7 +344,7 @@ require_once( './admin-header.php' ); ?>
<?php <?php
foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) { foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) {
if ( 'wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) { if ( false !== strpos( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) {
$wrap_class = 'widgets-holder-wrap'; $wrap_class = 'widgets-holder-wrap';
if ( !empty( $registered_sidebar['class'] ) ) if ( !empty( $registered_sidebar['class'] ) )
$wrap_class .= ' ' . $registered_sidebar['class']; $wrap_class .= ' ' . $registered_sidebar['class'];
@ -376,7 +376,7 @@ foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) {
<?php <?php
$i = 0; $i = 0;
foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) { foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) {
if ( 'wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) if ( false !== strpos( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) )
continue; continue;
$wrap_class = 'widgets-holder-wrap'; $wrap_class = 'widgets-holder-wrap';

View File

@ -1157,22 +1157,21 @@ function _wp_sidebars_changed() {
if ( ! is_array( $sidebars_widgets ) ) if ( ! is_array( $sidebars_widgets ) )
$sidebars_widgets = wp_get_sidebars_widgets(); $sidebars_widgets = wp_get_sidebars_widgets();
retrieve_widgets(); retrieve_widgets(true);
} }
// look for "lost" widgets, this has to run at least on each theme change // look for "lost" widgets, this has to run at least on each theme change
function retrieve_widgets() { function retrieve_widgets($theme_changed = false) {
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;
$registered_sidebar_keys = array_keys( $wp_registered_sidebars ); $registered_sidebar_keys = array_keys( $wp_registered_sidebars );
$orphaned = 0;
$old_sidebars_widgets = get_theme_mod( 'sidebars_widgets' ); $old_sidebars_widgets = get_theme_mod( 'sidebars_widgets' );
if ( is_array( $old_sidebars_widgets ) ) { if ( is_array( $old_sidebars_widgets ) ) {
// time() that sidebars were stored is in $old_sidebars_widgets['time'] // time() that sidebars were stored is in $old_sidebars_widgets['time']
$_sidebars_widgets = $old_sidebars_widgets['data']; $_sidebars_widgets = $old_sidebars_widgets['data'];
remove_theme_mod( 'sidebars_widgets' ); remove_theme_mod( 'sidebars_widgets' );
$orphaned = 0;
foreach ( $_sidebars_widgets as $sidebar => $widgets ) { foreach ( $_sidebars_widgets as $sidebar => $widgets ) {
if ( 'wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) if ( 'wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) )
@ -1202,10 +1201,17 @@ function retrieve_widgets() {
unset( $sidebars_widgets['wp_inactive_widgets'] ); unset( $sidebars_widgets['wp_inactive_widgets'] );
foreach ( $wp_registered_sidebars as $id => $settings ) foreach ( $wp_registered_sidebars as $id => $settings ) {
$_sidebars_widgets[$id] = array_shift( $sidebars_widgets ); if ( $theme_changed ) {
$_sidebars_widgets[$id] = array_shift( $sidebars_widgets );
$orphaned = 0; } else {
// no theme change, grab only sidebars that are currently registered
if ( isset( $sidebars_widgets[$id] ) ) {
$_sidebars_widgets[$id] = $sidebars_widgets[$id];
unset( $sidebars_widgets[$id] );
}
}
}
foreach ( $sidebars_widgets as $val ) { foreach ( $sidebars_widgets as $val ) {
if ( is_array($val) && ! empty( $val ) ) if ( is_array($val) && ! empty( $val ) )