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
- How to create a clone role in wordpress
- 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?
- 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 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?
- Order users by custom user meta
- List total number of users that are authors
- 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
- 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
- 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
- The delete_posts capability?
- Capabilites not working [closed]
- add_menu_page() for more than one user role
- Get User Role by ID not working
- 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
- Are User Levels Still Currently Used?
- Adding Capabilities to a WordPress User Account
- Adding an additional role to an Administrator
- 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
- 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?
- 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?
- 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.”
- Hiding custom theme functionality using capabilities
- user_can() not working for comment authors
- Which capabilities are available in Gravity Forms Salesforce plugin? [closed]
- How to write conditions based on user capabilities not on user role?
- What Capability is required to let a role RUN code in Edit Theme?
- Want to know parameters that can be passed to user_can() for access control by user capabilities
- Can I Create a Second Admin Level User Role?
- Create sub-administrator role that can do everything except use or see the code editor
- Redirect admin 403 “Cheatin uh?” admin pages
- Assigning multiple or additional capabilities to specific users or how to create additional roles like bbpress roles?
- how do I add role and capability after I create a new user
- User role editor – Add download files capability
- Why can my subscribers create new posts for review?
- Disabled delete_others_posts if post is from admin
- How to give plugin access to specific role(s)
- How to restrict subscriber editing other posts but read specific posts in backend
- Role and Capabilities: How do I allow user role to access theme options without enabling ‘manage_options’?
- fine-grained capabilities for user related capabilities
- Best practices to handle multilpe roles and capabilities?
- Enable plugins for a specific user role
- Groups roles & capabilities
- Why does user_can return false for a capability during plugin deactivation?
- A different role for each site in a multisite
- Force “submit for review” on update?
- Subscriber role – blank page
- Need to create admin user without capability to create user
- Grant access to admin menu?
- How might I enable a user to view Draft pages from a different Author, without the ability to edit?