Search code examples
phpmysqlwordpresscas

Update WordPress user ID with CAS server ID


I've setup a WordPress site and the authentication is done with a CAS server. I am using the WP Cassify plugin to connect with the CAS server.

Is it possible to update the wp_users ID from the default one, to the ID my server returns? If so, should i update with the new ID the wp_usermeta? Or should i create an extra column in the wp_users table? Are there any other tables that need to be updated?

The CAS server returns a string e.g."0A2B4C6D8EABCDEF1234567" which i want to use as ID for other services connected to my site.


Solution

  • The best way, as suggested in comment above, would be to implement it in the user meta - as the ID is the user table's primary key, so can't be changed.

    Add this line of code to save the CAS ID after the user is registered via WordPress:

    update_user_meta( $wordpress_user_id, 'cas_id', $cas_id_value );

    And then if you need to retrieve it afterwards touse:

    $cas_id = get_user_meta( $wordpress_user_id, 'cas_id' );