Recently, I’m working on a pretty intresting project. It will be an e-healthcare site, or something like that.
And I’ve chosen BuddyPress as the foundation for that.
The fact, that we are not willing to create an online community, but we need, the fancy stuff like, user management, flexible profile data handling, extendability, and so forth.
But, as the site is forming in my mind, some methods will change during the developement, but one major thing won’t. And I’m very certain about that. This is the login method, and I want to use email based login, and forget about the login/username based method.
First of all I installed WP-Email-Login plugin to be able to login with not just username, but with email as well.
After that I realized, that I need rather an AJAX Login widget, so I installed AJAX Login Widget++ and rewritten it, to fulfill the needs of the project.
But, there came, the BuddyPress part. Which is the main story today.
As you know, on the register page, it asks for a login name.
As I realized I can’t just skip that, or remove username errors during the process. So I’ve choosen to generate an md5 hash as a login name, from the e-mail address, on the back of them. So they won’t see it, they won’t need it.
This “solution” only works, if you does not plan social functions, such as blogs, on “mentions” handling, where the login name shows up and looks really ugly. Really.
So, here how I did it, I added these to my own theme’s (yeah, a buddypress child theme) functions.php:
add_action( 'bp_core_validate_user_signup', 'my_theme_validate_user_signup' );
if(!empty($result['user_email']) && empty($result['errors']->errors['user_email']))
$result['user_name'] = md5($result['user_email']);
$_POST['signup_username'] = $result['user_name'];
If you don’t understand PHP, let me explain.
First, we add action, which runs, before the user adding process.
If the e-mail is correct, and right, this function removes the warnings according to the login. Then it removes login, and replace it, with the md5 hash of the email. After that, we fake as it was added by the user.
This last thing is essential, thus there’s a checking whether the login/username was really posted or not later in registration process, outside the BuddyPress user creation mechanism. That’s why we have to fake this :)
On the other hand, you have to wipe out the input form and stuff from the registration/register.php of your BuddyPress theme. So to be clear, you have to remove these lines:
<label for="signup_username"><?php _e( 'Username', 'buddypress' ) ?> <?php _e( '(required)', 'buddypress' ) ?></label>
<?php do_action( 'bp_signup_username_errors' ) ?>
<input type="text" name="signup_username" id="signup_username" value="<?php bp_signup_username_value() ?>" />
I know, this whole thing is a dirty solution.
I just can’t find any easier, and better one.
If you know one, please let me know ;)