Bypass Email Requirement
-
This is a subject that’s been talked about off and on in Buddypress history. We all know that it’s handy to have a user’s email address for many reasons, but in general, people prefer to be asked less questions when signing up at a new website.
I hired someone for help with this a couple years ago, and the code they gave me still works (only with the legacy template pack though!) Here’s the code:
/** * Generate Random, unused email from the username * * @param string $username * * @return string random email */ function hello_generate_random_email( $username ) { $domain = '@metalheadswebsite.com'; $username = sanitize_user( $username ); $email = $username . $domain; while( email_exists( $email ) ) { //try another random email by appending some digit $email = $username . random_int( 1, 99999 ) . $domain;// there is vary low chance of having 100K users with same name anyway } return $email; } function hello_updatre_email() { // If the username is not given, let us not worry much if ( empty( $_POST['signup_username'] ) ) { return ; } //Also, if an email is already given by the user, do not generate one if ( ! empty( $_POST['signup_email'] ) ) { return ; } //now generate a random email and save it $email = hello_generate_random_email( $_POST['signup_username'] ); $_POST['signup_email'] = $email; } add_action( 'bp_signup_pre_validate', 'hello_updatre_email' );
This code works perfectly with the legacy template pack. The user signs up, and the function takes the given username & appends @metalheadswebsite.com to it, and submits it with the form. I’ve been using this code since 2017.
My problem is that now I want to switch to the Nouveau template pack, but this code does not work with it; it fails; users are prompted for the email address after hitting “Submit.”
I don’t understand how the nouveau registration works; the markup in that file is harder for me to understand than the one in legacy. Is it something simple that I need to do? Does anything stand out based on the code I provided?
PS) As I mentioned, I know this has been talked about in the past. I’ve read the suggestions people have given, but those suggestions are dusty now; the plugin called “Optional Email” does not work with Buddypress (Nouveau), at least not as of today.
The person who created the custom code for me is no longer doing this type of work. 🙁
- You must be logged in to reply to this topic.