How to use user ID as user login?

How to modify this function to use user ID (column 'ID' in wp_users table) as user login?

//Use the email address as user_login function oa_social_login_set_email_as_user_login ($user_fields) { if ( ! empty ($user_fields['user_email'])) { if ( ! username_exists ($user_fields['user_email'])) { $user_fields['user_login'] = $user_fields['user_email']; } } return $user_fields; } //This filter is applied to new users add_filter('oa_social_login_filter_new_user_fields', 'oa_social_login_set_email_as_user_login');

Best Answer

  • Claude_SchlesserClaude_SchlesserAdministratorOneAll Team
    Answer ✓
    Hello,

    this should do the trick:

    function oa_social_login_update_user($user_data, $identity) { wp_update_user (array( 'ID' => $user_data->ID, 'user_login' => $user_data->ID)); } //This action is called whenever Social Login adds a new user add_action ('oa_social_login_action_after_user_insert', 'oa_social_login_update_user', 10, 2);

    Please note that it also uses a different hook.

Answers

Welcome!

Please sign in to your OneAll account to ask a new question or to contribute to the discussions.

Please click on the link below to connect to the forum with your OneAll account.