2

Is there anyway I can remove all instances of the username in all WP emails, or swap our the username for the email address?

I have some code in my functions.php file that removes the username from the registration and uses the email as the login, but it makes it so the username is randomly generated; that means all emails going out to the user that contain a username field will get username: random-string-of-letters, which I'm trying to remove/swap.

Below is code removing the username from registration:

add_action( 'bp_core_validate_user_signup', 'custom_validate_user_signup' );

function custom_validate_user_signup($result)
{
  unset($result['errors']->errors['user_name']);

  if(!empty($result['user_email']) && empty($result['errors']->errors['user_email']))
  {
    $result['user_name'] = md5($result['user_email']);
    $_POST['signup_username'] = $result['user_name'];
  }

  return $result;
}
3
  • Not sure if this is really close worthy. Is this about Buddypress alone or about WordPress? In other words: Can you remove Buddypress from the question? – kaiser May 27 '16 at 20:37
  • @kaiser I guess if it's WP that requires the username you can remove BP from the question. – vytfla May 27 '16 at 21:59
  • Then please do so. Unless one can replicate your problem without installing Buddypress or any other plugin, I will have to close that question. – kaiser May 27 '16 at 22:27
1

I think you just need to take the md5() out of this line:

$result['user_name'] = md5($result['user_email']);

I'm not that familiar with buddy press but if empty($result['errors']->errors['user_email']) being true means a user was succesfully registered I'd use something like

wp_update_user( array( 'ID' => $user_id, 'name' => $result['user_email'] ) );
2
  • Remove the code inside the if statement with wp_update_user( array( 'ID' => $user_id, 'name' => $result['user_email'] ) );? – vytfla May 27 '16 at 21:17
  • taking out the md5() worked, thanks a lot! – vytfla May 27 '16 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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