WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#15404 closed defect (bug) (wontfix)

Allow to target the different list items via CSS in the Admin Bar

Reported by: defries Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Administration Keywords: has-patch
Focuses: Cc:

Description

For the My Site menu in the Admin Bar there's no way currently to remove certain list items of the specific site.

If you have more than 20 sites in the dropdown you would have to manually look up 20 css classes to target the list items. For instance, if you don't want your visitor to directly go to the Dashboard you would need 20 css statements set to display:none.

Via a simple CSS change one would be able to target a specific list item via a display:none statement.

Attachments (3)

admin_bar_patch.patch (2.2 KB) - added by defries 3 years ago.
15404.diff (2.3 KB) - added by nacin 3 years ago.
15404.patch (2.4 KB) - added by ocean90 3 years ago.

Download all attachments as: .zip

Change History (17)

defries3 years ago

comment:1 follow-up: nacin3 years ago

  • Component changed from Accessibility to Administration
  • Milestone changed from Awaiting Review to 3.1

The CSS change looks fine, that said, there are remove_node and remove_menu methods for the WP_Admin_Bar class, that ideally you would then leverage to remove specific ones.

Obviously you also will want to make sure that you are actually denying users access to these pages via capability checks, unless of course this is only about usability and simplicity, versus access.

comment:2 in reply to: ↑ 1 defries3 years ago

Replying to nacin:

The CSS change looks fine, that said, there are remove_node and remove_menu methods for the WP_Admin_Bar class, that ideally you would then leverage to remove specific ones.

Obviously you also will want to make sure that you are actually denying users access to these pages via capability checks, unless of course this is only about usability and simplicity, versus access.

It's more about usability and simplicity. Just to have some easy control over what is shown in that particular menu.

comment:3 follow-up: nacin3 years ago

  • Keywords needs-patch added; admin bar removed

Looking at the code some more, the add_menu() method wants an 'id' to be a sanitized value. We shouldn't overload it.

That's fine, because add_menu also takes a 'meta' argument, which can take the form of array( 'class' => 'more classes here' ).

comment:4 follow-up: nacin3 years ago

Those additional classes should probably be namespaced the way the ids are. I'd suggest ab-blog-, i.e. ab-blog-dashboard.

comment:5 in reply to: ↑ 4 defries3 years ago

Replying to nacin:

Those additional classes should probably be namespaced the way the ids are. I'd suggest ab-blog-, i.e. ab-blog-dashboard.

With the dash con-catting it to one class there's no way to target them. Or am I missing the point?

comment:6 in reply to: ↑ 3 defries3 years ago

Replying to nacin:

That's fine, because add_menu also takes a 'meta' argument, which can take the form of array( 'class' => 'more classes here' ).

I see that now too, no clue how to do that, but I understand what you mean.
Basically I was looking for an easy CSS hack to change for instance a list item to display:none, but also to change a background and/or color and such.

comment:7 defries3 years ago

  • Cc defries added

nacin3 years ago

comment:8 nacin3 years ago

Patch, untested, attached.

comment:9 garyc403 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

comment:10 johnpbloch3 years ago

  • Keywords needs-refresh added; needs-testing removed

These patches no longer apply cleanly because the surrounding code has changed.

ocean903 years ago

comment:11 ocean903 years ago

  • Keywords needs-refresh removed

I have nacin's updated. It's a good idea but we shouldn't change the ID because then we have duplicate IDs which wouldn't be valid.

comment:12 nacin3 years ago

Devil's advocate: What's the use case here? Instead of display:none, why not loop through and individually remove those nodes in PHP?

comment:13 nacin3 years ago

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

comment:14 nacin3 years ago

You can also use attribute selectors here, specifically [att$=val].

Note: See TracTickets for help on using tickets.