Show the next user id in WordPress

In a recent project I have to show and use the next user_id as username ( I know it is a bad decision, but this is how the client wants it).
I would usually use
$wpdb->insert_id
but that works only if you already inserted a row before.

So I had to use MySQL SHOW TABLE STATUS :


// Get the latest ID from the users table and pad it with zeroes
$sqlstat = "SHOW TABLE STATUS WHERE name='wp_users'";
$user_login = str_pad($wpdb->get_row($sqlstat)->Auto_increment , 5, 0, STR_PAD_LEFT);

That is doing query to the wp_users table status, and I am getting back the value of the NEXT user_id (to be displayed later in the “Create a new user form”).

  1 comment for “Show the next user id in WordPress

  1. June 9, 2013 at 15:52

    Curious why you say this is a bad idea? Why is it bad to set the username to a sequential number based off the user ID number?

Leave a Reply

Your email address will not be published. Required fields are marked *