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
This commit is contained in:
Dion Hulse 2012-10-31 23:18:33 +00:00
parent 2dc29f9587
commit 3d40fbad80

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