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

git-svn-id: http://core.svn.wordpress.org/trunk@22354 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2012-10-31 23:18:33 +00:00
parent 163ef62822
commit f4976f40b3

View File

@ -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 );