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
1 changed files with 6 additions and 0 deletions

View File

@ -206,6 +206,9 @@ class WP_Roles {
* @param bool $grant Optional, default is true. Whether role is capable of performing capability. * @param bool $grant Optional, default is true. Whether role is capable of performing capability.
*/ */
function add_cap( $role, $cap, $grant = true ) { function add_cap( $role, $cap, $grant = true ) {
if ( ! isset( $this->roles[$role] ) )
return;
$this->roles[$role]['capabilities'][$cap] = $grant; $this->roles[$role]['capabilities'][$cap] = $grant;
if ( $this->use_db ) if ( $this->use_db )
update_option( $this->role_key, $this->roles ); update_option( $this->role_key, $this->roles );
@ -221,6 +224,9 @@ class WP_Roles {
* @param string $cap Capability name. * @param string $cap Capability name.
*/ */
function remove_cap( $role, $cap ) { function remove_cap( $role, $cap ) {
if ( ! isset( $this->roles[$role] ) )
return;
unset( $this->roles[$role]['capabilities'][$cap] ); unset( $this->roles[$role]['capabilities'][$cap] );
if ( $this->use_db ) if ( $this->use_db )
update_option( $this->role_key, $this->roles ); update_option( $this->role_key, $this->roles );