BuddyPress registration form

Note: this guide only applies to the BuddyPress plugin, to create a WordPress user registration form see the Creating a user guide.

Step 1

Create the registration form using the form builder, then on your computer create a new file named register.php with the following content.

1
<?php echo do_shortcode('[quform id="1" name="Register form"]'); ?>
<?php echo do_shortcode('[quform id="1" name="Register form"]'); ?>
  • Replace the shortcode with the correct shortcode for your form which you can find on the Forms → Forms page

You’ll now need to upload this file to your site in your WordPress theme files inside a new directory named members, so that the file resides at:

wp-content/themes/YOUR_THEME/members/register.php

You can use FTP software to perform this step, see this page for more information.

Step 2

Add the following code to the WordPress theme functions.php file (or create a plugin for it).

12
3
4
5
6
7
8
9
1011
12
13
14
15
16
17
18
1920
21222324
25
26
272829
30
3132
33
34
35
36
37
38
add_filter('quform_element_valid_1_3', function ($valid, $value, Quform_Element_Field $element) {    if (username_exists($value)) {
        $element->addError('This username is already taken');
        $valid = false;
    }
 
    return $valid;
}, 10, 3);
 
add_filter('quform_element_valid_1_4', function ($valid, $value, Quform_Element_Field $element) {    if (email_exists($value)) {
        $element->addError('This email address is already registered');
        $valid = false;
    }
 
    return $valid;
}, 10, 3);
 
add_action('quform_post_process_1', function (array $result, Quform_Form $form) {    if (function_exists('bp_core_signup_user')) {
        $username = $form->getValueText('quform_1_3');        $email = $form->getValueText('quform_1_4');        $password = $form->getValueText('quform_1_5'); 
        // Profile fields
        $usermeta = array(
            'field_1' => $form->getValueText('quform_1_6'),            'field_2' => $form->getValueText('quform_1_7'),        );
 
        $usermeta['profile_field_ids'] = '1,2';        $usermeta['password'] = wp_hash_password($password);
 
        bp_core_signup_user($username, $password, $email, $usermeta);
    }
 
    return $result;
}, 10, 2);
add_filter('quform_element_valid_1_3', function ($valid, $value, Quform_Element_Field $element) {
    if (username_exists($value)) {
        $element->addError('This username is already taken');
        $valid = false;
    }

    return $valid;
}, 10, 3);

add_filter('quform_element_valid_1_4', function ($valid, $value, Quform_Element_Field $element) {
    if (email_exists($value)) {
        $element->addError('This email address is already registered');
        $valid = false;
    }

    return $valid;
}, 10, 3);

add_action('quform_post_process_1', function (array $result, Quform_Form $form) {
    if (function_exists('bp_core_signup_user')) {
        $username = $form->getValueText('quform_1_3');
        $email = $form->getValueText('quform_1_4');
        $password = $form->getValueText('quform_1_5');

        // Profile fields
        $usermeta = array(
            'field_1' => $form->getValueText('quform_1_6'),
            'field_2' => $form->getValueText('quform_1_7'),
        );

        $usermeta['profile_field_ids'] = '1,2';
        $usermeta['password'] = wp_hash_password($password);

        bp_core_signup_user($username, $password, $email, $usermeta);
    }

    return $result;
}, 10, 2);
  • On line 1, replace 1_3 with the Username element unique ID
  • On line 10, replace 1_4 with the Email element unique ID
  • On line 19, replace the number 1 with the form ID
  • On line 21, replace 1_3 with the Username element unique ID
  • On line 22, replace 1_4 with the Email element unique ID
  • On line 23, replace 1_5 with the Password element unique ID
  • On lines 27-28, configure the extra profile fields (see below)
  • On line 31, replace 1,2 with the comma separated list of all the profile field IDs (see below)

Configuring the profile fields

Add a new line to the $usermeta array for each of the profile fields that you want to include in the form. For example, in the line below:

1
'field_1' => $form->getValueText('quform_1_6'),
'field_1' => $form->getValueText('quform_1_6'),
  • The number 1 in field_1 is the profile field ID, which you can find in the browser address bar when editing the profile field e.g. the address bar will contain the part field_id=1 so the field ID is 1
  • The 1_6 part is the Quform element unique ID of the field you want to save into this profile field

Once you’ve added all of the profile fields to the array, you should change the line below.

1
$usermeta['profile_field_ids'] = '1,2';
$usermeta['profile_field_ids'] = '1,2';

Replace 1,2 with the list of all of the profile field IDs separated by commas, for example: 1,2,3,4,5

Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy