Thursday, October 6, 2022
HomeWordPress Developmentperson roles - Remove_role not working, offers "Name to undefined methodology stdClass::remove_role()"

person roles – Remove_role not working, offers “Name to undefined methodology stdClass::remove_role()”


I am making a particular baby theme template I will use to match customized roles to a person’s subscription. So, that is going to be for admin-only upkeep use.

I made a perform the place I go the person object, the brand new function (decided elsewhere), and the current function(s) for that person.

On this website, we require that every person have just one function.

Right here is my “function removing” perform.
variables:
$person is the person object for one person.
$this_role is the brand new function I wish to assign the person.
$user_roles is the array of all roles for that person.

/*
* This perform units the present person to the function specified, and removes all different roles.
* It's true that a number of roles are allowed, however for the needs of this web site, a number of roles
* is just not a fascinating factor.
*/
perform changeRole($person,$this_role,$user_roles){      
    if(! in_array($this_role,$user_roles) && ! in_array("administrator",$user_roles)){
        // If this person at the moment doesn't have the right function, set it right here.
        $user->set_role( $this_role );
    }
    foreach($user_roles as $function){
        if($function !== $this_role){
            // Delete all incorrect roles right here.
            $user->remove_role( $function ); // <- Offers me an error
        }
    }
}

The error I am getting is Uncaught Error: Name to undefined methodology stdClass::remove_role()

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments