Skip to content

Commit

Permalink
Update and enhance the docs for retrieve_widgets().
Browse files Browse the repository at this point in the history
Props zieladam, hellofromtonya.
Fixes #53811.

git-svn-id: https://develop.svn.wordpress.org/trunk@51842 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
azaozz committed Sep 21, 2021
1 parent 9269cbd commit d05ecf2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/wp-includes/widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,15 @@ function _wp_sidebars_changed() {
}

/**
* Look for "lost" widgets, this has to run at least on each theme change.
* Validates and remaps any "orphaned" widgets to wp_inactive_sidgets sidebar, and saves the widget settings.
* This has to run at least on each theme change.
*
* For example, let's say theme A has a "footer" sidebar, and theme B doesn't have one.
* After switching from theme A to theme B, all the widgets previously assigned to the footer would be inaccessible.
* This function detects this scenario, and moves all the widgets previously assigned to the footer under wp_inactive_widgets.
*
* Despite the word "retrieve" in the name, this function actually updates the database and the global $sidebars_widgets.
* For that reason it should not be run from the front end unless the param value is 'customize' (to bypass the database write).
*
* @since 2.8.0
*
Expand Down Expand Up @@ -1310,6 +1318,7 @@ function retrieve_widgets( $theme_changed = false ) {
$sidebars_widgets['wp_inactive_widgets'] = array_merge( $lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets'] );

if ( 'customize' !== $theme_changed ) {
// Update the widgets settings in the database.
wp_set_sidebars_widgets( $sidebars_widgets );
}

Expand Down

0 comments on commit d05ecf2

Please sign in to comment.