I’m working on a solution for you now, will respond again soon.
Copy the buddypress theme into your WordPress child theme, and then you can modify the register template if needed.
copy the buddypress theme into your child theme by pasting this path into your child theme folder
/wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress
path of file for registration fields is this:
/wp-content/themes/child-theme/buddypress/members/register.php
Then, add First and Last name fields under User>Profile Links in the WordPress Dashboard.
Currently there is a ‘Name’ field that is required, you can edit it to read ‘First Name’ then add another ‘Last Name’ field..
Then you need to process the data before it saves into the database, I’m kind of at a loss here… I would need more time to brainstorm on it but I did find this hook ‘bp_core_signup_user’
I believe this is the hook you are looking for:
// define the bp_core_signup_user callback
function action_bp_core_signup_user( $array, $int, $int ) {
// make action magic happen here...
};
// add the action
add_action( 'bp_core_signup_user', 'action_bp_core_signup_user', 10, 3 );
How about something like bp_signup_pre_validate
?
also ‘bp_signup_validate’
function bp_password_beefing() {
global $bp;
if ( !empty( $_POST['signup_password'] ) )
if ( strlen( $_POST['signup_password'] ) < 6 )
$bp->signup->errors['signup_password'] = __( 'Your password needs to be at least 6 characters', 'buddypress' );
}
add_action( 'bp_signup_validate', 'bp_password_beefing');
source:
http://wordpress.stackexchange.com/questions/160475/how-to-increase-password-requirements-for-registration
thanks for all the help. I ended up doing something like this in my functions.php child theme:
function assign_username() {
if ( isset( $_POST ) ) {
$_POST['signup_username'] = create_username();
}
}
add_action( 'bp_signup_pre_validate', 'assign_username' );
function create_username() {
$i = 0;
$username = $_POST['field_3'] . $_POST['field_4'];
while ( username_exists( $username ) ) {
$username = $username . ++$i;
}
return $username;
}
However, now I have some weird behavior that is asking me if I want to leave the page when submitting the form (typical window.onbeforeunload event when entering information: http://stackoverflow.com/questions/1119289/how-to-show-the-are-you-sure-you-want-to-navigate-away-from-this-page-when-ch) although I have no idea what is triggering it on my custom register.php (https://pantest.centralus.cloudapp.azure.com/register/).
So I think my code above solves my $_POST issue, but now I have another one. Going to run through some tests to debug it now.
Thanks again for the prompt help. Was hoping people still check out these forums.
If you comment out your action:
// add_action( 'bp_signup_pre_validate', 'assign_username' );
Do you still get the “Do you want to leave the page” message?
I’m not sure why the code you’ve pasted above would trigger a message like that.
Figured it out. Turns out that the button html element of the form was causing it. Fixed it by simply changing the button to <input type=”submit”>.
Thanks again!
Issue now is with the extra BP fields coming later in the DOM than my fields on my register.php. Even though I have the css set to display: none for the actual xprofile fields, my fields are not carrying through the $_POST values because display: none does not remove the fields from the DOM.
I guess I can try adding hidden fields after the xprofile fields and set them to the values being entered in my fields, but that seems kinda clumsy.
I added test code to check the $_POST values at where I can see the fields coming over as empty strings: https://pantest.centralus.cloudapp.azure.com/register/
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!