Ensure that `role` is not empty before adding it in `add_role()` function and methods.

Props MikeHansenMe, dannydehaan, michielhab.
Fixes #23746.

Built from https://develop.svn.wordpress.org/trunk@33967


git-svn-id: http://core.svn.wordpress.org/trunk@33936 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-09-09 03:42:25 +00:00
parent 6d4442ba12
commit 7ef604c052
4 changed files with 10 additions and 2 deletions

View File

@ -471,6 +471,9 @@ function get_role( $role ) {
* @return WP_Role|null WP_Role object if role is added, null if already exists.
*/
function add_role( $role, $display_name, $capabilities = array() ) {
if ( empty( $role ) ) {
return;
}
return wp_roles()->add_role( $role, $display_name, $capabilities );
}

View File

@ -172,8 +172,9 @@ class WP_Roles {
* @return WP_Role|void WP_Role object, if role is added.
*/
public function add_role( $role, $display_name, $capabilities = array() ) {
if ( isset( $this->roles[$role] ) )
if ( empty( $role ) || isset( $this->roles[ $role ] ) ) {
return;
}
$this->roles[$role] = array(
'name' => $display_name,

View File

@ -439,6 +439,10 @@ class WP_User {
* @param string $role Role name.
*/
public function add_role( $role ) {
if ( empty( $role ) ) {
return;
}
$this->caps[$role] = true;
update_user_meta( $this->ID, $this->cap_key, $this->caps );
$this->get_role_caps();

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-33966';
$wp_version = '4.4-alpha-33967';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.