Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Add $_POST data before submitting registration

@gorbett

Participant

SOLUTION (finally)

Thanks @henrywright and @coffeywebdev for pointing me in the right direction. Here is what I ended up with.
1. Enable child theme and copy the BP register.php file to the child theme.
2. In the child theme’s style.css, I entered to remove the xprofile fields from the register.php page:
.editfield {
display: none;
}
3. In the child theme’s functions.php file I have this (again, reassign the xprofile fields ‘field_3’ and ‘field_4’ because of their position in the DOM:

add_action( ‘bp_signup_pre_validate’, ‘assign_username’ );

function assign_username(){
if ( isset( $_POST[‘first_name’] ) ) {
$_POST[‘field_3’] = $_POST[‘first_name’];
$_POST[‘field_4’] = $_POST[‘last_name’];
$_POST[‘signup_username’] = create_username();
foreach ($_POST as $key => $value) {
echo $key . “: “;
echo $value;
echo “<br>”;
}
exit();
}
}

function create_username() {
$i = 0;
$username = $_POST[‘field_3’] . $_POST[‘field_4’];
while (username_exists( $username )) {
$username = $username . ++$a;
}
return $username;
}

I am simply creating a username from first name and last name and then start to append a number when inevitably someone with the same name registers. I need to add more validation on the username to ensure that it is <= 50 characters, but this finally worked for me.

Thanks again to the community for pointing me in the right direction!

Skip to toolbar