Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#14256 closed defect (bug) (wontfix)

register_sidebar() loses track of its widgets when moved

Reported by: wjm's profile wjm Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Widgets Keywords:
Focuses: Cc:

Description

I have registered a sidebar container, setting a name,
for example

register_sidebar( array(
	'name' => __( 'Test Widget' ),
) );

if you move the order in which it gets registered (let's say, you register it first and then you decide to move it, and register second), all the widgets inside it will get lost.
this is due to the ID being generated by default based on its order number. so when you change the order, you change the ID, and everything is lost.

attached is a patch that: when given a title, it sets the id by default based on the title, and not on the ORDER NUMBER.

It only uses the order number when no title is given.

Attachments (1)

register_sidebar.patch (493 bytes) - added by wjm 14 years ago.
sets the id based on the title, not on the order it has been registered

Download all attachments as: .zip

Change History (5)

@wjm
14 years ago

sets the id based on the title, not on the order it has been registered

#1 @wjm
14 years ago

I left the prefix "sidebar-" for the ID when set by default, it can be removed, but it is good to have it so you know it has been set by default.

#2 @dangayle
14 years ago

  • Cc dangayle added

+1
I hate how WP screws up sidebars when you register a new one.

#3 @mdawaffe
14 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

This will break existing installations.

Just register your sidebar with an explicit ID.

register_sidebar( array(
	'name' => __( 'Test Widget' ),
	'id' => 'test-widget',
) );

#4 @mdawaffe
14 years ago

We could use an option to keep track of a mapping between sidebar titles and generated IDs. Whenever register_sidebar() is called without an explicit ID, check the map. If there's an entry, use it. If not, generate a unique ID and add it to the map. Not sure how to keep the map from exploding after lots of theme switches.

Note: See TracTickets for help on using tickets.