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: opajaap Owned by: dd32
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)

18461.patch (583 bytes) - added by SergeyBiryukov 22 months ago.
18461.2.patch (864 bytes) - added by SergeyBiryukov 21 months ago.

Download all attachments as: .zip

Change History (7)

  • Keywords has-patch added

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.

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.

Last edited 8 months ago by SergeyBiryukov (previous) (diff)
  • Milestone changed from Awaiting Review to 3.5

This is small / useful / avoids PHP notice

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

In 22354:

Fix a PHP Notice when attempting to Add or remove capabilities from nonexistant roles. Props SergeyBiryukov. Fixes #18461

Note: See TracTickets for help on using tickets.