Reputation: 333
I have been changing user roles name on wordpress how ever If i call
implode(', ', $user->roles)
I still get the original role names, Administrator, Subscriber, etc.
So, i figured something like this would be the correct way.
if(implode(', ', $user->roles) = "administrator"){
$role = "Site owner";
}
else{
$role = "User";
}
echo $role;
I am running this for each user,how ever this does not work. What should i be doing to change the names? the backend presents the name correctly. how ever i wish to have the names on the front end for the users accounts.
Upvotes: 1
Views: 929
Reputation: 853
More specifically, a user's role can be set by creating an instance of the WP_user
class, and calling the add_role()
or remove_role()
methods.
Example
Change a subscribers role to editor
// NOTE: Of course change 3 to the appropriate user ID
$u = new WP_User( 3 );
// Remove role
$u->remove_role( 'subscriber' );
// Add role
$u->add_role( 'editor' );
Hopefully that's more helpful than my initial response, which wasn't necessarily as helpful.
Upvotes: 1