WordPress User getting added with id of 0

The ID column if the wp_users table is the Primary Key and auto-incremented. If your table isn’t set that way then something must’ve gone wrong while it was getting created. Try deleting all the tables from the database and re-installing WordPress.

How can I retrieve current user id within wordpress plugin?

You probably called it too early, get_current_user_id uses wp_get_current_user, so move all your code that’s at the top level of functions.php into the init hook or appropriate equivalent. The only thing that should be in the global scope in your functions file if you want maximum compatability and efficiency is add_action and add_filter calls

Can’t add users in admin after copying database

The key turned out to be that the wp_users table lost its AUTO_INCREMENT setting when it was imported, for unknown reasons; the server may have timed out, etc. I found this out from the wp-cli error in the debug log that said “WordPress database error Duplicate entry ‘1000075’ for key ‘PRIMARY’ for query INSERT INTO … Read more