By default, WordPress uses $wp_object_cache
which is an instance of WP_Object_Cache
to save on trips to the database.
Trace back username_exists()
function, you will notice that get_user_by()
uses WP_User::get_data_by()
which return user data from $wp_object_cache
immediately without checking if that user exists in database. Note that $wp_object_cache
is stored in memory.
It means that if you deleted an user record directly in your database without cleaning up user cache, user data is still available. That’s the problem.
So what you’re missing?
-
Missing to delete user the right way.
-
Missing to clean user cache.