Opened 22 months ago
Closed 7 months ago
#18461 closed defect (bug) (fixed)
adding a capability to a non-existing role gives warnings
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.5 |
| Component: | Role/Capability | Version: | 3.2.1 |
| Severity: | normal | Keywords: | has-patch |
| Cc: |
Description
When a plugin does something like this:
global $wp_roles;
$wp_roles->add_cap('a_nonexistent_role', 'any_capability');
no error (about the non-existance of the role) is displayed.
However, each subsequent page request produces this errormessage:
Notice: Undefined index: name in /mnt/web7/...../wordpress/wp-includes/capabilities.php on line 113
Debug is on: define('WP_DEBUG', true); in wp-config.php
Attachments (2)
Change History (7)
SergeyBiryukov — 22 months ago
comment:1
SergeyBiryukov — 22 months ago
- Keywords has-patch added
SergeyBiryukov — 21 months ago
comment:3
SergeyBiryukov — 21 months ago
18461.2.patch introduces isset() checks for add_cap() and remove_cap().
I don't think we should automatically remove an invalid role here. It can be removed with remove_role(), in the same way it was added.
comment:4
wonderboymusic — 8 months ago
- Milestone changed from Awaiting Review to 3.5
This is small / useful / avoids PHP notice

This patch i invented myself already.
I would like a solution to add_cap(), and a way to remove the invalid (nameless) role i seem to have created.