mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 07:40:07 +00:00
Ensure that role is not empty before adding it in add_role() function and methods.
Props MikeHansenMe, dannydehaan, michielhab. Fixes #23746. git-svn-id: https://develop.svn.wordpress.org/trunk@33967 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user