admin管理员组

文章数量:1125044

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!

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!

Share Improve this question asked Dec 14, 2023 at 4:37 Fonacier Jr. BalateroFonacier Jr. Balatero 1
Add a comment  | 

2 Answers 2

Reset to default 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.

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

本文标签: Is there a way that we can change wordpress user id