WordPress.org

Make WordPress Core

#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:

Description

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 20 months ago.
Don't load widgets at all
no-widget-menu.diff (512 bytes) - added by greenshady 20 months ago.
Load widgets but no admin menu
21761.patch (486 bytes) - added by SergeyBiryukov 20 months ago.

Download all attachments as: .zip

Change History (12)

comment:1 nacin20 months 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.

comment:2 follow-up: greenshady20 months 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.

comment:3 in reply to: ↑ 2 ; follow-up: azaozz20 months ago

Replying to greenshady:

A tip: look here :)

greenshady20 months ago

Don't load widgets at all

greenshady20 months ago

Load widgets but no admin menu

comment:4 in reply to: ↑ 3 greenshady20 months 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 20 months ago by greenshady (next)

comment:5 sabreuse20 months 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.

comment:6 greenshady20 months 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 );

SergeyBiryukov20 months ago

comment:7 sabreuse20 months ago

Sergey's works for me -- thanks!

comment:8 nacin20 months 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.

comment:9 nacin20 months 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.