0

I would like to ask if there's a WordPress plugin that can be used to modify the user ID of the user. Instead of 1 or 4, I will add a prefix like 387101 or 387104. If none, is there someone here in the group who can add a code for that? Thank you and good day!

2 Answers 2

0

simply change the autoincrement number in your table settings in phpmyadmin to 387100 and it will start and go ahead with 387101, 387102, and so on. As it automatically counts +1 when adding a user, this is the most efficiant and easy way to do it without changing any code.

0

you can use the user_register hook in WordPress to modify the user ID when a new user is registered.

function custom_prefix_user_id($user_id) {
    // Define your custom prefix
    $prefix = '38710';

    // Calculate the new user ID with the prefix
    $new_user_id = $prefix . $user_id;

    // Update the user ID in the database
    global $wpdb;
    $wpdb->update(
        $wpdb->users,
        array('ID' => $new_user_id),
        array('ID' => $user_id)
    );

    // Update usermeta tables with the new user ID
    $wpdb->update(
        $wpdb->usermeta,
        array('user_id' => $new_user_id),
        array('user_id' => $user_id)
    );

    // Return the modified user ID
    return $new_user_id;
}
add_filter('user_register', 'custom_prefix_user_id');

This code will change the user ID of newly registered users by adding the custom prefix to it.

Existing user IDs will not be affected

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.