From 3d40fbad80c11fa3e248f6794d6bb88d94d6940f Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 31 Oct 2012 23:18:33 +0000 Subject: [PATCH] Fix a PHP Notice when attempting to Add or remove capabilities from nonexistant roles. Props SergeyBiryukov. Fixes #18461 git-svn-id: https://develop.svn.wordpress.org/trunk@22354 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/capabilities.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index b6a495c932..c8d730d53c 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -206,6 +206,9 @@ class WP_Roles { * @param bool $grant Optional, default is true. Whether role is capable of performing capability. */ function add_cap( $role, $cap, $grant = true ) { + if ( ! isset( $this->roles[$role] ) ) + return; + $this->roles[$role]['capabilities'][$cap] = $grant; if ( $this->use_db ) update_option( $this->role_key, $this->roles ); @@ -221,6 +224,9 @@ class WP_Roles { * @param string $cap Capability name. */ function remove_cap( $role, $cap ) { + if ( ! isset( $this->roles[$role] ) ) + return; + unset( $this->roles[$role]['capabilities'][$cap] ); if ( $this->use_db ) update_option( $this->role_key, $this->roles );