It is very common for users of Restrict Content Pro to want to add custom fields to the registration and profile forms so that members can enter and store additional information, perhaps for their location, profession, or personal interests (or anything else). I have shown how to add these kind of fields before, but the method is a bit out of date and not fully developed, so I’d like to walk through the process again so that you can easily add new fields to the registration form, the profile editor, and also the member edit screen in the admin section of Restrict Content Pro.

We will be adding the fields shown in the images below:

Step 1 – Add fields to the registration and profile forms

Adding fields to the registration and profile forms is simply a matter of writing a function that outputs the HTML for the fields and is connected to the proper actions. For the registration form, we need to use the rcp_after_password_registration_field action, and for the profile form we need to use the rcp_profile_editor_after action. Note, there are other action hooks you may use but these are the most likely ones you will want.

Our function is very simple:

We have simply setup the HTML and used get_user_meta() to retrieve the saved information for the currently logged-in user. If you put this code into your theme or an active plugin, the fields should now show up on the registration and profile forms. They won’t save any information yet, but they will show up.

Step 2 – Adding the Edit Member screen fields

Once we are finished, we want site admins to be able to edit the member details, just like they are able default user fields (name, email, etc). To do this, we need to add our new fields to the Edit Member screen in Restrict Content Pro. Adding the fields is nearly identical to adding them to the registration and profile forms. The only difference is the hook name we use and the structure of the HTML.

You should now have the Profession and Location fields showing up on Edit Member screen. Now it’s time to process and save the data during form submission.

Step 3 – Checking for errors during registration

In the case that we want to make our fields required (so they cannot be left blank during registration), we need to hook into the error checking process of Restrict Content Pro and determine if our custom fields validate. To do that, we can use the rcp_form_errors hook to determine if our fields have valid data entered in them. For this example, we’re simply going to assume that Profession and Location both need to be filled out, but we don’t really care what kind of information is entered in them. If you are adding a phone number field, for example, you would probably want to ensure the value entered matched a valid phone number.

The empty() function does exactly what it sounds like: it checks to see if the specified field is empty. If either field is empty, we call rcp_errors()->add() in order to register a new registration error. Restrict Content Pro will not allow the registration form to be submitted until all errors checks pass.

Step 4 – Saving the user fields on registration

Once we have confirmed that the custom user fields have proper information entered in them, we need to save the data to the member’s user meta. To do this, we use the rcp_form_processing hook and the update_user_meta() function:

This will store the entered value for both fields into the usermeta database so that we can retrieve it at anytime. Now it’s time to save data when submitting the profile form and also the edit member form.

Step 5 – Saving the user fields during member edit and profile edit

This process is identical to how we save the fields during user registration except the hook and the parameters passed to the hook are a little different, but everything else is exactly the same.

And that’s it! We now have fully functional custom registration fields that can also be edited by both site admins and member’s themselves from the profile editor.

Going further and adding more or different fields

All of the code provided in this tutorial is meant as an example. Since it is unlikely that these two fields will fit your exact needs, here are a few tips for how to modify it to fit your needs:

  • Fields are primarily identified by their name and id attributes. If you wish to change “profession” to “job”, search for “rcp_profession” and replace it with “rcp_job” (or add a second set of fields and then update the names/ids).
  • Field data submitted should be validated to ensure it matches the expected and desired format.
  • When adding additional fields, do not duplicate functions, instead duplicate existing code inside of the functions. This applies to all functions shown in this tutorial.
  • If you have problems, ask for help, I’m more than happy to assist!

You can view the complete example plugin here or you can download it as a zip file that is ready to be uploaded to your WordPress site as a plugin.

  1. Barbara Schendel

    This is EXACTLY what I was looking for. You are the best. Thank you!!!

    • Pippin

      I am not, sorry.

  2. Barbara Schendel

    Hi Pippin, This plugin is actually not working for me. I downloaded and installed the exact sample that you provided and it and while it does show the two new fields on the registration page, it still does not display them in back on the edit member (or edit user) page. Even tried deactivating all other plugins and switching to twentyfourteen. Any ideas?

    • Pippin

      Does it show everything correctly on the frontend?

    • Barbara Schendel

      The fields show up correctly on the front end, but not in the admin. Edit member screen just has all the usual info. I even tried the exact plugin you posted.
      All I need is one field, website_url. Here’s my modified plugin: http://pastebin.com/ifp1yD8M

  3. Jon

    I followed the tutorial to integrate this with Jobify. This is the code: http://pastebin.com/e9Fipp9T

    Goal #1: display extra fields. Achieved.
    Goal #2: display errors when fields are not filled in. Achieved.
    Goal #3: allow users/admins to edit their extra info in their profiles. Not achieved.

    Issue #1: On WordPress I go to Restrict > Members > Edit. Extra fields – Job Title, Company Name, Telephone, Address – appear, but they’re empty.
    Issue #2: logged in as a user I go to My Account > Edit Account. Extra fields – Job Title, Company Name, Telephone, Address – do NOT appear, therefore cannot be edited/updated.

    Any ideas?

    • Pippin

      Have those fields already been populated for the user that you are viewing?

    • Jon

      The user has filled in the details when registering. This suggests that they weren’t saved.

    • Pippin

      If you update a user after they have registered, do the fields get saved then?

  4. Jon

    I can only access user’s new fields through wp-admin as an administrator. I filled in the fields, clicked update, a little green note appears, saying that it’s been updated, but the fields are empty again. So, I assume that the data doesn’t get saved.

    • Pippin

      Could you paste your complete plugin code to pastebin.com and then share the link so I can look at it and test it?

    • Pippin

      Whoops, I missed that, sorry. I’m looking at it now.

    • Jon

      Woohoo! It works! Thanks!

    • Pippin

      Great!

  5. Alastair Willey

    I’ve just updated from an old version of RCP to the latest version and have followed these instructions to update my custom fields from the old tutorial.

    I’ve managed to get it working on the signup form, but the fields are not appearing on the “Edit my profile” screen.

    Here is the code I’ve used http://pastebin.com/N4HsWfx4

    Is there anything I’ve missed?
    Thanks,

    • Pippin

      Which edit profile screen? The standard one provided by WordPress or the frontend version added by RCP?

  6. Alastair Willey

    Sorry the wordpress edit profile screen.

  7. Alastair Willey

    I didn’t realise there was a short code for front end profile details, maybe this wasn’t in the plugin when we first created the site.

    The short code works perfect so ignore the previous issue.

  8. Sky Resendez

    Hi PIppin,

    Is there a way we can export the information in these additional fields in addition to the basic information that’s included in the members CSV?

    • Rachel

      I’d love to know this too!

  9. Sky Resendez

    Hello Pippin,

    Our subscribers are getting errors to fill in the requested fields when renewing their subscription; however, because they have existing accounts, the normal registration fields don’t appear when upgrading/renewing their subscription, but the errors still appear, prompting them to fill in the fields: http://imgur.com/2hL8NMN

    Can you point me in the right direction of how I can correct this?

    Thank you

    • Pippin

      As long as they log in before attempting to renew their subscription, it should work just fine. Since they are logged in, some of the fields will not be displayed as they are not needed.

    • Fredrik Hedelund

      We had the same problem. What you can do is to delete everything under the section: “Determines if there are problems with the registration data submitted”

      This means that the fields won’t be required, but at least people can start upgrading their membership again.

  10. Sky

    Hi again Pippin,

    Unfortunately I’m still having the same issue when our subscribers try to renew their subscriptions.

    As you can see here, when logged in, the fields do not display because they are not needed, as you mentioned earlier: http://imgur.com/wDKV17q

    After choosing a subscription level and filling in the credit card information, the subscriber will receive these errors (note: they’re still logged in): http://imgur.com/xzPQW4R

    The only way for a subscriber to get past this hurdle is by deactivating the plugin and reactivating it after they have submitted their payment.

    I simply modified the fields area of the script that was posted up: http://pastebin.com/qFiwE6HQ

    Have you had any other reports of this issue?

    Thanks in advance for your help.

  11. Fredrik Hedelund

    Hi Pippin, and thanks for the great tutorial!

    I got one question though, The code works fine for actually creating the fields and also have them recorded in the database. However I can only see the data if actually visiting each members profile in wp-admin>Restrict>Members>Member Profile.

    How can I get the information to be displayed when viewing all members (in the members table)?

    • Pippin

      You will need to register a custom column and then call get_user_meta() to display it. Take a look at the members-page.php file in includes/admin/. It has some actions that you can use to add a new column.

    • Fredrik Hedelund

      Thanks for that info, I will go ahead and try to implement it.

    • Fredrik Hedelund

      I guess I just create two more columns in the member-page.php

      ID); ?>

      But is this the right way to call it?

    • Fredrik Hedelund

      php echo rcp_get_user_meta($member->ID)

    • Fredrik Hedelund

      php echo rcp_get_user_meta $member->ID

    • Fredrik Hedelund

      echo rcp_get_user_meta $member->ID

    • Pippin

      Sorry your comments got flagged as spam.

      Did that work out for you?

  12. Tim

    Hi,

    I’m struggling a lot with this. When members register, I want them to fill in extra information such as address, company name etc. That bit is fine.

    BUT

    I want logged in members to be able to edit their own info – eg address, company name etc. As this does not appear on their membership profile page, this is an issue.

    How can I get round this?

    • Pippin

      That’s already supported with this sample code.

  13. Matt

    I’m trying to use this for the user’s country to help determine the correct shipping amount. I’ve used the most up to date code, but I need to figure out how to get it to update the EDD FES user country.

    Is there a tutorial for that?

    Thanks,

    Matt

    • Pippin

      Not that I know of, sorry.

  14. David Randulfe

    Can be posible add the fields only to Edit Profile shortcode ? I dont want on the registration form.

    Thanks

Error: Please enter a valid email address

Error: Invalid email