Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#21761 closed enhancement (fixed)

Hide Appearance > Widgets menu when no sidebars are registered

Reported by: sabreuse Owned by: nacin
Milestone: 3.5 Priority: normal
Severity: normal Version:
Component: UI Keywords: has-patch
Focuses: Cc:


If a theme doesn't register any sidebars, the Appearance > Widgets menu is still shown and widgets.php displays

No Sidebars Defined

The theme you are currently using isn’t widget-aware, meaning that it has no sidebars that you are able to change. For information on making your theme widget-aware, please follow these instructions.

This is bad UX -- we're offering a menu for a feature the user doesn't meaningfully have access to, and the Widgetizing Themes instructions offered in the link are really meant for theme designers. We should hide the menu when the feature isn't registered, as we do for Headers and Backgrounds.

Attachments (3)

no-load-widgets.diff (611 bytes) - added by greenshady 3 years ago.
Don't load widgets at all
no-widget-menu.diff (512 bytes) - added by greenshady 3 years ago.
Load widgets but no admin menu
21761.patch (486 bytes) - added by SergeyBiryukov 3 years ago.

Download all attachments as: .zip

Change History (12)

#1 @nacin
3 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 3.5

This made sense back in 2.2 (rough guess). Not anymore, I agree.

#2 follow-up: @greenshady
3 years ago

  • Cc justin@… added

Just for reference to the discussion: http://lists.wordpress.org/pipermail/theme-reviewers/2012-August/010507.html

I'd love to see this happen. I'm off to see if I can dig up what needs to change.

#3 in reply to: ↑ 2 ; follow-up: @azaozz
3 years ago

Replying to greenshady:

A tip: look here :)

3 years ago

Don't load widgets at all

3 years ago

Load widgets but no admin menu

#4 in reply to: ↑ 3 @greenshady
3 years ago

I've uploaded two separate patches. I wasn't sure the best route to take there, so I tried two different options that I think would work.

We should probably also block access and add the "You do not have sufficient permissions to access this page." message to the widgets screen in the admin, which would be consistent with the background and header features.

Replying to azaozz:

Replying to greenshady:

A tip: look here :)

I thought I was going crazy their for a while. I swore I looked in every file in /wp-admin.

Version 0, edited 3 years ago by greenshady (next)

#5 @sabreuse
3 years ago

Both patches have the same problem for me - they hide the Widgets menu whether the theme supports widgets or not. I'll poke at them to see if I can get the check working. Pure speculation: I wonder if this is related to the fact that it's being added directly at _admin_menu rather than later with admin_menu & the API.

#6 @greenshady
3 years ago

I can confirm that as well. I should've checked that one can actually use widgets with the patches. This is because this the wp_maybe_load_widgets function is hooked to plugins_loaded:

add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );

That's too early for themes to control. I'm not sure if there are any plugins that this will affect if changed to a different hook.

Without testing, my guess is that it'd need to move to something like:

add_action( 'widgets_init', 'wp_maybe_load_widgets', 99 );

#7 @sabreuse
3 years ago

Sergey's works for me -- thanks!

#8 @nacin
3 years ago

  • Keywords has-patch added; needs-patch removed

We need to load the widgets because a theme might be calling the_widget() or something. Sidebars aren't the only way to use widgets.

#9 @nacin
3 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [21825]:

Don't show Appearance > Widgets if the theme has no sidebars defined. props SergeyBiryukov for the initial patch. fixes #21761.

Note: See TracTickets for help on using tickets.