Make WordPress Core

Opened 15 years ago

Closed 14 years 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: Focuses:

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 15 years ago.
18461.2.patch (864 bytes ) - added by SergeyBiryukov 15 years ago.

Download all attachments as: .zip

Change History (7)

#1 @SergeyBiryukov
15 years ago

  • Keywords has-patch added

#2 @opajaap
15 years ago

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.

#3 @SergeyBiryukov
15 years 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.

Last edited 14 years ago by SergeyBiryukov (previous) (diff)

#4 @wonderboymusic
14 years ago

  • Milestone Awaiting Review3.5

This is small / useful / avoids PHP notice

#5 @dd32
14 years ago

  • Owner set to dd32
  • Resolutionfixed
  • Status newclosed

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.