BuddyDev

Show BuddyPress User Registration form everywhere on your BuddyPress site

Are you running a WordPress & BuddyPress based social site? Do you need to put  custom user registration form on your site? If yes, in that case, this tutorial will help you.

By default, BuddyPress allows users to register from the Signup page( which you set in the BuddyPress settings ). There are times when you may want to display the registration form at other places, say you want to show BuddyPress registration form on home page or in the sidebar on all pages.

Today, In this tutorial I will show how to do that. We will learn two things in this tutorial.

  • How to showing BuddyPress user registration form anywhere?
  • and How to process user registration from any page?

Step 1:- Creating the registration form

For the sake of simplicity, I will just copy the registration form  from bp-default theme( buddypress/bp-themes/bp-default/registration/register.php  or buddypress/bp-templates/bp-legacy/buddypress/members/register.php )

I have copied the following code from it and saved it as register-form.php in my theme. You can do the same.

To show the form, include it anywhere(In the sidebar.php or anywhere you need it).

 

Now, if you go and see your page, you will see an error like this:-

error-registration-step

 

 

To make the form show, we need to add a line to initialize the registration step just before the form.

That line is

All we are doing here is telling BuddyPress that if the signup step is not set, please consider is as the request details step.

We can either put that code just above the form or in the code that includes the form.

Here is the updated code to include the form again.

Once you have updated the code, you can see the registration form. Here is what I see in my sidebar.

showing-registration-form

 

That's all for showing the registration form.

 

Continue reading if you don't want to redirect your users to the default signup page and need to process the registration on the same page.

To make sure that the user registration gets processed on the same page where it resides, we will need to check if the form is submitted via POST method and then redirect back to the original page from the  BuddyPress signup page.

Here is the code.

 

The above code checks if the form was submitted via POST method, then saves the post fields and   $bp->signup object,  and redirects back to the original page.

What we are actually doing here is letting BuddyPress do all the processing of the registration data and then redirect to the original page where the form is residing. We need to save the post fields for showing form input data on error and  we save $bp->signup for showing error or signup confirmation message.

In the code below, we process the saved data from our previous step to show error or confirmation message.

 

That's all. Now, the registration will be processed on the same page.

 

Here is a screenshot showing error:-

 

showing-registration-error

and here is the registration success screen.

on-successfull-registration

 

You can put the codes from this tutorial in your theme's functions.php or bp-custom.php.

I am hoping that the tutorial will help you to further improve your BuddyPress based social sites. Please do let me know if you want to see the above code/form as shortcode or widget? Looking forward to hear your suggestions & feedback 🙂

 

25 Responses to Show BuddyPress User Registration form everywhere on your BuddyPress site

  • Awesome! Make a plugin out of it with a shortcode. =)

    • Hi Renato,
      nice to see your comment after a long time.
      Will have it as a shortcode by the end of this week 🙂

  • If you could make this into a shortcode, that would be amazing.

    • Hi Derek,
      Thank you for the comment.

      Will certainly have it as a shortcode by the end of this week 🙂

  • Awesome tutorial. You just saved me a massive headache. I was looking for how to create multiple BuddyPress registration forms and couldn't find anything else useful anywhere.

    • Thank you Daniel,
      I am happy that you found it useful 🙂

  • Thanks again for an excellent tutorial. One issue that I am having… I have customised the form to include some XProfile fields. I can register using the form and the user account is created, however none of the XProfile fields are being populated.

    Do I need to edit your code to account for the extra fields? I have created a Gist here if you want to take a look.

    https://gist.github.com/ch1n3s3b0y/a3e6a06efaa15579799f

    • I've fixed my own problem. My custom form wasn't submitting the data so I just used the form you created above. My issue now is trying to set a user role during the registration process. Causing me a ton of issues at the moment.

  • Works great! Tried for hours to get a working registration from. Keep up the excellent work!

  • Hello, many thanks for this post it is exactly what I am trying to do !

    For the moment I still have an error to display the form.

    My code looks like the following:

    Can you see any error in line with the steps that you describe ?

    Thank you very much !!
    Thomas

    • Just to clarify: My question is mainly on the "To make the form show, we need to add a line to initialize the registration step just before the form." step in your tutorial as I have exactly the error that you mention before this step.

      What line has to be added and where (and why) ?

      Many thanks !!
      Thomas

      • Hi Thomas,
        I have updated the post again with the code. Please take a look and let me know if it works now or not? It seems that we had lost that section of code earlier while changing our Syntax highlighter plugin.

        • Hello Brajesh,

          Thank you so much !!!
          It is working now, you are amazing.

          I wish you an excellent day.
          Thomas

      • Hi Thomas,
        Glad that it is fixed now. happy to help. Have a great day to you too 🙂

        • Hello Brajesh,

          Following this first success with the registration page I would like to create a template for the "member profile" page (buddypress/members/single/home.php).

          The idea is to be able to display the user profile in 2 different pages. For example http://[site url]/members/user1 and http://[site url]/fr/membre/user1 would both be display the profile of user1 (or the edit profile page if the loggedin user is user1).

          Do you know if a similar technique as described in this post makes it possible ?

          Thank you !
          Thomas

  • Hi

    I have used the code above to redirect the user back to the page that the registration form is on, but it is redirecting the user back to the homepage. Do you know why this might be?

    • mee too.

      • Hi Lukid,
        I am sorry I could not reply in time to Daniel.
        Can you please post your code on pastebin and link me in our support forums?

        I will be happy to assist.
        Thank you
        Brajesh

  • It's not working anymore. I followed it until:

    "Continue reading if you don’t want to redirect your users to the default signup page and need to process the registration on the same page."

    Form looks ok but after registration user just doesn't exist, there is no any confirmation message too. Also missed password strenght meter.

    • Hi Mariusx,
      Please allow me to check it today. The password strength will not work(as BuddyPress only loads it on the Registration page). rest all should have.
      Are you using any custom plugin to manage registration? Is your site multisite or normal WordPress?

      • No custom plugin and it's a normal WP.

  • Very good tutorial. However, how do I make a page not reload.

    I want to add ajax admin, but I stop here.

    thanks.

Subscribe