Make WordPress Core

Opened 13 years ago

Closed 10 years ago

#18671 closed enhancement (duplicate)

Allow themes to set default widgets

Reported by: viper007bond's profile Viper007Bond Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3
Component: Widgets Keywords:
Focuses: Cc:


Rather than having to use a hard-coded fallback HTML sidebar, it'd be cool if a theme could set up default widgets.

#17979 will somewhat remove the need for this but it could still be useful.

Change History (8)

#1 follow-up: @ocean90
13 years ago

Without testing: Is it not possible via update_option( 'sidebars_widgets', array() )?

I mean we do it in core too, see [18643].

#2 in reply to: ↑ 1 @westi
13 years ago

Replying to ocean90:

Without testing: Is it not possible via update_option( 'sidebars_widgets', array() )?

I mean we do it in core too, see [18643].

It's possible but you have to know the structure of an "internal" option.

Ideally we should have a function a theme can call / or an extention of register_sidebar() which says put these widgets in here when the sidebar is empty / new.

#3 @lancewillett
13 years ago

  • Cc lancewillett added

#4 @sabreuse
13 years ago

  • Cc sabreuse@… added

#5 @hanni
13 years ago

  • Cc hanni added

#6 @ryanduff
12 years ago

  • Cc ryan@… added

Definitely something that's needed. I see a use case for this with multisite installs where rolling out a new site should get a default set of widgets. Core basically updates the options table with a serialized array, while it can be duplicated, it's certainly not ideal.

It's something I'd like to jumpstart for 3.6 since it's too late to accomplish in the 3.5 cycle. Any core devs want to suggest an ideal approach to this before I start working on a patch?

Maybe something as simple as adding a 'contains' parameter to register_sidebar() which would include an array of widget names? That's one of the options Westi suggested and I think it makes the most sense.

#7 @markoheijnen
12 years ago

Several months ago I wrote something this hacky class: It's a little different approach.

With this code you can register a widget to a sidebar by code. To have a class/function for this you can easily pass settings to a widget. If you do this with register_sidebar() it's getting a mess and complicated.

#8 @ocean90
10 years ago

  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #16613.

Note: See TracTickets for help on using tickets.