Make WordPress Core

Opened 14 years ago

Closed 12 years ago

#18461 closed defect (bug) (fixed)

adding a capability to a non-existing role gives warnings

Reported by: opajaap's profile opajaap Owned by: dd32's profile dd32
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.2.1
Component: Role/Capability Keywords: has-patch
Focuses: 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 14 years ago.
18461.2.patch (864 bytes) - added by SergeyBiryukov 14 years ago.

Download all attachments as: .zip

Change History (7)

#1 @SergeyBiryukov
14 years ago

  • Keywords has-patch added

#2 @opajaap
14 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
14 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 13 years ago by SergeyBiryukov (previous) (diff)

#4 @wonderboymusic
13 years ago

  • Milestone changed from Awaiting Review to 3.5

This is small / useful / avoids PHP notice

#5 @dd32
12 years ago

  • 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.