You can do that like this :
$my_user = new WP_User( $user_id );
$my_user->set_role( "editor" );
Related Posts:
- How to get a users list by who created them?
- Getting a List of Currently Available Roles on a WordPress Site?
- Editor can create any new user except administrator
- Is there way to rename user role name without plugin?
- How to create a clone role in wordpress
- How to add a Capability to a User Role?
- How can I get a list of users by their role?
- Remove Ability for Other Users to View Administrator in User List?
- How do I make a draft post accessible to everyone?
- Reset default roles and capabilities
- How do I programmatically set default role for new users?
- add_role() run only once?
- Groups of capabilities: users with multiple roles?
- User-edit role setting distinct from wp_capabilities? [closed]
- What do unfiltered_html and unfiltered_upload actually filter?
- Temporary capability for current_user_can()
- Allow roles below admin to add subscribers only
- How to let contributors to create a new revision(draft) editing their published posts
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- Add Custom User Capabilities Before or After the Custom User Role has Been Added?
- Temporarily give ‘manage_options’ capability
- How to update user role without logout
- How to check user role without using current_user_can()
- Hide specific admin users’ posts
- Allow authors to edit only certain users
- Do not allow users to create new posts and pages
- How to update role capabilities
- \WP_User Object | What’s the Difference Between {caps} and {allcaps}?
- Do custom user roles have any default capabilities?
- How to enable the theme editor cap for an editor role?
- How to assign capabilities to user NOT to User Role
- Prevent user creating new users with specific roles
- how to add custom user capabilities using add_user_meta or something else?
- Allow user to Publish, but not Edit or Delete
- Order users by custom user meta
- List total number of users that are authors
- Email notification for editors only
- How-to Delay The Capability To Publish Posts?
- Shold I manually add ‘cap’ to admin role ?
- How to restrict specific post types from being read or added by specific user roles (eg. author)?
- Allow users to publish child pages of the pages they have access to edit
- New Roles and Capabilities in WordPress
- Why is wp-login redirecting to the home page when I use this function?
- Allow contributor to view own scheduled post
- How to prevent users with “edit_others_posts” capability from editing admin posts
- Is there a simple way to manage capabilities per user?
- Author Role – Allow editing of Gallery images
- What is the difference between “create_users” and “add_users” capabilities?
- How to get all users with Author role capabilities?
- Can’t manage to make translate_user_role() work
- How to check if a role has a specific capability
- Locking Down WordPress Application Password Permissions / Capabilities
- Prevent custom user role to add new pages
- Allow user to edit specific user with meta key using map_meta_cap
- How to remove sticky post capability for a specific user role?
- User role permissions based on taxonomies
- Let new user role to ‘edit_others_posts’ of other user role, not of its own type
- How can I have different groups of editors only allowed to edit certain parent+subpages?
- The delete_posts capability?
- How to restrict access to specific pages on the back-end?
- Capabilites not working [closed]
- add_menu_page() for more than one user role
- Get User Role by ID not working
- Remove wordpress author’s capability to moderate comments on their own posts
- Getting users by specific capability, not role
- exclude roles from overview
- Can you set a role as author?
- get approved users only ( ultimate member plugin )
- Prevent Editors from Editing/Deleting Admin Accounts
- Query users which have same dynamically generated roles as the current user
- Where are the WordPress capabilities stored?
- Are User Levels Still Currently Used?
- Adding Capabilities to a WordPress User Account
- Adding an additional role to an Administrator
- Custom user roles for access to specific parts of the site
- Roles for Custom Post Types
- Pending status by default for a specific role
- How do I restrict user access to plugins?
- Remove Capabilities from WP admin for specific user role
- My subscriber has the “edit comment” capability but can’t edit comment
- Show metabox for a special role
- User Role Capabilities for WordPress Gutenberg Blocks
- Subscriber (with read permissions) cannot view Private posts
- How can I add a custom role capability to use in a custom plugin?
- bbPress plugin moderator roles
- Allowing user to edit posts based on the post status
- Disable user from updating certain posts
- Custom capabilities to add, edit, remove users of a particular role only?
- Add a role and give admin priviledges
- Where are $current_user->allcaps set?
- Stop users of author role from editing already pending posts
- add_role user capability not working
- Purpose of Adding Capability to Role But Not Grant?
- Menu page with list of users
- How can I promote a user to a network administrator?
- Reset Roles (or undo role changes on theme change)
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- Authorize users for specific pages and/or categories
- Custom Capabilities for CPT and Problem with current_user_can()
- Custom wordpress admin page/url “You do not have sufficient permissions to access this page.”