I was sure that wp_update_user()
should do this.
It even gets user_login as param, but it looks like it ignores it, when you set this param.
So this code looks OK, but it doesn’t work as you wish it did 🙁 :
wp_update_user(
['ID' => $user_id, 'user_login' => $new_login]
);
You have to call custom SQL query to update user_login:
global $wpdb;
$wpdb->update(
$wpdb->users,
['user_login' => $new_user_login],
['ID' => $user_id]
);
It works OK and I don’t think it has any serious consequences, because WP uses users ID to assign posts/comments (and so on) to user.
The only problem I can think of is that when this user is currently logged in, he will be logged out after user_login change.
Related Posts:
- How to restrict access to uploaded files?
- Allowing users to edit only their page and nobody else’s
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- Hide Admin Menu for Specific User ID who has administrator Role
- Allowing an email as the username?
- Check if specific username is logged in
- Post list based on the user that is logged in
- Basic auth WordPress REST API dilemma
- LEFT JOIN, INNER OUTER JOIN, LEFT OUTER JOIN is driving me crazy. Please help?
- Copy a user from one WordPress site to another
- Search multiple meta keys at once
- Getting users who registered 360 days from current date
- Querying Email Addresses for a List of Users with Same Last Name?
- Front end user meta options for users
- How to customize wp_signon()
- Creating a Front-end based User Search
- Can I create users that have access to *some* other users posts instead of all other users posts?
- Set default page for user account in admin
- Exclude subscriber users from user list
- Share user table from WP with Drupal
- Log all users out of all locations after 24 hours
- Hide everything on site for visitors except specific page IDs
- Managing Users and Creating Groups [closed]
- show text If special user is logged
- Upgrade Nightmare – No Posts, Permissions Issues and Can’t Create a new post
- How to disable a specific page for a specific user
- Allow user access to Dashboard only!
- Restrict access of admin uploads to certain logged-in users?
- mysql query two database tables, users and usermeta and sort by custom meta int value
- wordpress user roles are not working
- Displaying different in-page content to cliente/admin
- Problem with automatic role change through cron job
- Reset Password policy
- How can I allow an User to publish only 5 posts per month?
- Where are $current_user->allcaps set?
- WordPress SQL Issue not returning correct reselts
- How to get last user with wpdb?
- How do you manage your pages or functions that require logged-in users?
- Querying specific table row by current user login
- Allow admins to login as other users
- Can I Create a Second Admin Level User Role?
- Delete a user from frontend
- Unique password to access a section site
- One Click Access To Users Account In WordPress?
- Using my own user table
- WordPress user role with create user capability?
- How to get image path from id using SQL
- Update user role for expired membership
- Insert user register into my own user table instead of wp own user
- How to use url formatter with integer
- Custom User Role: Can Edit Own Page, Cannot Create New
- WordPress install checking permissions of user id 0
- throttle/limit a logged in user’s http requests to specific page on a per day basis
- Allowing users to edit only their page and nobody else’s
- How to bulk change user role to “No role for this site”
- Restrict Access to the User Profile
- post acces for guests / unregistered users only
- New User ID not working in custom function with user_register hook
- Username has been exposed
- Ordering list of users by last name and then by first name
- view and update form only for registered users
- Control Category of each user can post
- Limit user access to installing/configuring a plugin?
- determine active user browser at the same time
- MySQL query to list users who never signed in
- Wordpres password as plain text in email
- WordPress password as plain text in email
- Change the Author Slug from Username to Nickname
- How can 2 blogs share the same users
- How to display custom user meta from registration in backend?
- Grouping users under parent user
- How to update user role without logout
- How we can get the user id by its display_name
- WP_User_Query with combined meta query – not working?
- Can you have multi-site WP and keep users separate?
- Is it possible to get a user with just the password field?
- How to add country drop down menu to the user profile?
- User ability to favorite or ‘like’ content
- Users roles, make a page belonging to multiple users
- stop login if user_status equal zero
- How do i make my wordpress website private?
- Is there a way to identify a user in a custom REST API method? [duplicate]
- Good way to block users within a multisite setup without deleting them?
- Profile page for user roles
- Search Function on a plugin WordPress User
- Force users to use password with specifications
- Give users alternative/second avatar that is rectangle sized
- Difference between is_user_logged_in and $_session[‘uname’]
- Using get_user in wordpress with sorting
- How to verify which WordPress user requested the API in ASP .NET Core?
- Custom Password Reset
- Can I add a unique code for each user based on the location?
- Is nicename the same as nickname in WP?
- How to update a user with REST API v2 knowing only the username?
- To save user info on the same page by form submiting
- Button for users to upgrade their user role + Button to show current user role!
- How do I Limit the number of pages a non-subscriber can see?
- Retrieve New user’s ID
- Restrict access to certain dashboard pages based on user id
- Set a minimal number for next user_id