WordPress – MySQL Auto Increment User ID

I am looking to run two instances of WordPress which sync on a regular basis.

The way I am going to do this is to have the auto increment offset on each different.

Read More

So for example on instance one the user IDs would be 1,3,5,7 etc. And on instance two the user IDs would be 2,4,6,8 etc.

Within WordPress there is the user function wp_insert_user which I would like to add a filter to for the database insert of a new user.

The issue is I cannot see a filter directly before or relating to the insert. So I am stuck on how I would achieve this.

The function is found in wp-includesuser.php file on line 1856 and within that on line 2060 is the insert statement for a new user:

$wpdb->insert( $wpdb->users, $data + compact( 'user_login' ) );
$user_id = (int) $wpdb->insert_id;

Could someone assist please? I just need pointing in the right direction as like I say I am not sure of the direction I need to take but want to ensure that the code I use is per the WordPress framework.

Related posts

1 comment

  1. Configure this in MySQL directly. I assume you are going to sync all tables, in which case you might want to always increment by two. You can change the global auto_increment interval with auto_increment_increment:

    SET GLOBAL auto_increment_increment=2;
    

    Then configure each instance to have a different auto_increment_offset:

    SET GLOBAL auto_increment_offset=1;
    SET GLOBAL auto_increment_offset=2;
    

Comments are closed.