I found when attempting similar I needed to clear the user cache to get the relogin to work (after much frustrating testing!):
wp_cache_delete($user_id, 'users');
wp_cache_delete($old_user_login, 'userlogins'); // maybe unnecessary?
$creds = array('user_login' => $user_login, 'user_password' => $user_password, 'remember' => true);
wp_signon($creds);
Note for this to work you may also need the user to change their password at the same time so that you can populate the $user_password
field with a plain text password to provide to wp_signon
Related Posts:
- Changing user_nicename
- How to Join two tables from separate databases within WordPress
- Would manually deleting the dumping data fix a “#1062 – Duplicate entry ‘1’ for key ‘PRIMARY'” phpMyAdmin error?
- How to track a users progress through pages by inserting data into WordPress Database?
- WPDB: how to get the value of a field in a custom database table
- How to generate page content from database the right way?
- phpMyAdmin displays error when importing database
- Transferring working local PHP site to wordpress – with database (MySQL)
- custom user role wordpress – grant guest access to edit.php without insert/update/delete
- Databases – Submitting data from inputs to database [closed]
- Is it best to avoid using $wpdb for security issues?
- Lost in trying to create user database system
- Filter results from a serialized string to use on statistics
- wordpress site – using custom database and PHP
- Change wordpress’ database data using ajax – how to get current user id?
- Storing huge number of users in wordpress
- add role on WordPress in PHP on a second database
- Front end/Database connection in WP
- direct query to post_meta table
- can’t delete a row from post_meta table
- How to set max users to 17.000
- Can not manually create a database ( db, user, pass ) for a plugin
- How to connect database table to each registered wordpress user.
- Querying multiple meta_keys in WordPress SQL query
- Let users register weight each day and save it in DB
- Retrieve data from external database and insert back in
- User management system similar to wordpress one?
- Importing Geo data into wordpress database
- Detect session/cookie variable in wordpress to prevent access to documents
- Show all posts by author
- $wpdb->update with multiple parameters gives error
- How to save checkbox values for logged in users?
- wp search-replace on database returns PHP fatal error: Array and string offset access syntax with curly braces is no longer supported
- Custom user login page by creating a plugin
- How does WordPress know wich language is chosen when there is a database connection error
- Programmatic Login from 3rd Party site
- Querying wpdb using PHP
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- How can I save unique user data on my site? [closed]
- Add New User, extra fields which are required?
- user_profile_update_errors hook not executing
- Is it possible to create a wordpress database with php code?
- Update results, Before deleting the related category [closed]
- Modify user profile data through scripting?
- Store a default value for a transient on plugin activation
- Get users that likes the post
- How WordPress reacts to a lack of memory of the server [closed]
- Split reads to a different connection string
- Execute long and heavy processes
- Dynamic content in template
- add_cap not working
- database sent to a JSON file
- Do not execute If User is login as Administrator or any Specific Role
- Archive post by meta value + 24hours
- inserting a post from an extern php file but post content doesn’t show on wp site
- wordpress archive a user
- Genesis framework comments broken?
- Best practice for show data to one specific user?
- $wpdb->insert() does not Insert record in a table
- Using custom tables for old posts
- Call to undefined function get_userdata() in plugin
- db converts decimal number wrong
- Not connecting to database in file with multiple MySQL connections
- get_users meta_query: REGEXP not working for matching new lines
- Change CSS based on is_user_logged_in
- How to show a users bio on a page
- Filtering a Database Query
- “operation successful” message
- Display Data in Table from External Database in WP using Shortcodes
- How can I import an excel column into wordpress database?
- Blob file download problem
- WordPress Block developer from exporting Database via PHP
- How to retrieve the data from the sever and displaying it in a page?
- php if username is role
- Execute a function every hour in the background
- Create page with custom php script and fetched data
- wpdb prepare insert table doesn’t work
- Should I use WordPress to skin a database website?
- How do I display offsite database info on my wordpress site?
- Creating Database Table vs. Adding MetaData to Post & User
- WordPress and MySQL: trying to print data using PHP from user_meta custom field data
- How do you create two separate Register pages?
- dynamic page using php from sql database
- Building a REST API for your web app exposes primary keys of DB records?
- Most commented posts by time period (last 12h, last 24h and etc)
- Use $wpdb or other PHP script method to find/replace in WP database
- How to Update post_modified of all wordpress post
- Correct PHP to output a single result of a Function with SQL Query
- Is it possible to create new user from external form using REST API?
- Foreach loop inside an array_merge
- How can I add a new row in a separate database when someone registers via WordPress?
- Saving data from custom form in wordpress database
- Show current user posts only
- How can I find the cause of a 500 server error?
- I can’t update my data through $wpdb
- wpdb Cannot Update column in Database
- Can’t successfully check if post with title exist in database
- Cant connect to database with php 7.3
- Change page password every day (predictable password ;) )
- PHP -> SQL Query with Summing