Blog

How to add or update user profile fields using WordPress forms

Default WordPress User Profiles

If you administer a user membership website, you must already know how barebones WordPress’ default user profiles are. Out of the box, you get few basic fields which a user can only update by visiting WordPress dashboard; an option many are not comfortable with. Sorely, a front-end profile editing system is conspicuous by its absence. Not to mention, the basic fields are a non-starter for any modern user profile foundation. And if that were not enough, adding to the misery, there’s no built-in system allowing you to add more user fields which is fundamental to any niche user profiles website.
So how do you get yourself out of this bog? To be fair, it’s not that there is no system to build advance profiles within WordPress; On the contrary, there exists quite a robust structure under the hood to attach and maintain user data. It is called usermeta, short for User Metadata. All you need to know is some fancy bit of coding to unlock that. You can also use one of many available plugins which can help you construct great looking profiles. Our very own — ProfileGrid is one such example, which not only empowers you to build any type of profiles, but also add user groups among other neat little things.
The default profile fields are stark reminder of WordPress’ past as primarily a blogging tool. It is still the core around which user profiles are built. Ergo, you cannot modify or remove these default fields. But WordPress offers APIs to attach as many data-fields to users, as you want. It includes set of functions to add, retrieve and modify custom data to user accounts using usermeta key, value pairs. But creating a new usermeta key is not really synonymous to adding a new field to user profile. Usermeta is used to store all kinds of information about a user which includes options only for admin eyes. For example, WordPress uses usermeta key wp_capabilities to store access capabilities for a user. In short, profile fields are just one of the things usermeta can be used for.
That is why you will need a plugin that not only stores profile fields as usermeta, but also retrieves and publishes them on frontend as proper HTML. Since usermeta is WordPress’ preferred system for storing information about its users, it has added advantage of being secure and egalitarian, when it comes to sharing data among plugins. If one plugin stores user information using usermeta, another plugin can easily retrieve and use it. Therefore, it was a no brainer for us when it came to deciding if RegistrationMagic should work with usermeta. The question was how.

WordPress Usermeta with RegistrationMagic forms

Since RegistrationMagic is form-first system, we gave a deep thought to how WordPress usermeta should work with our forms. From the very beginning, we wanted to display all the forms submitted by a user inside his or her profile in admin area, but without actually going on to add every individual form fields as usermeta. If we did that, you can imagine the commotion it would have wrought! Honestly, it would not only create undue complications, but adding all form fields to user profile would be an overkill as not all form fields make sense as part of user profiles. So, we decided to give you the power to store what you want as usermeta, and what to keep aside as clerical chaff. In fact, we decided to allow you to not only add new usermeta, but update existing one created by one of your other plugins!
Let’s say you have a support form on your website powered by RegistrationMagic; and each time a user fills out that form, it’s fair to expect you would want it to automatically display inside his or her user profile in admin area. So when you check out user’s latest submission, you can also see quickly the past support requests by the same user. RegistrationMagic achieves this by adding an information table to default WordPress user pages in admin area where each table row corresponds to a form submission. This is reasonably concise way of attaching multiple form entries to a single user page.
Now let’s assume your support form has a field which you want to be actually part of the user profile and update it every time user submits the form. This is where RegistrationMagic’s usermeta field mapping feature comes in. RegistrationMagic field mapping allows you to bind one of the fields of your RegistrationMagic form to a user usermeta key. During the field creation process, you can select an existing usermeta key or create a new one and map it to the current field. You can also do this to multiple fields inside same form. Whenever a user submits the form, all fields mapped to usermeta will update the usermeta values from form values. As mentioned before, the form itself will be saved as separate object inside the user page in a table, which can be downloaded or edited (Premium only feature) by the admin.

Let us have a closer look at this process:

Open RegistrationMagic in your dashboard and hover above the form card in which you wish to map a field(s) with usermeta. Click on Fields button.
This will open a new page with fields manager. Click on Add Field and select a field type from popup. For sake of simplicity, we will select a plain text field. (If you plan on binding an existing field, please select Edit in front of that field.)
You will now reach Field Options view. Click on Advanced Settings right at the bottom. It will expand into more settings.
In these newly visible settings, scroll down until you see Add Field to WordPress User Profile:
By default, Do not add will be selected. Next two options are — Associate with Existing User Meta Keys and Define New User Meta Key. Select, Associate with Existing User Meta Keys. This will introduce a new dropdown with searchable options. The dropdown lists all existing usermeta keys registered with WordPress on your site. Since there are technical limitations on creation of usermeta keys (for example, there can be no spaces), they may look cryptic at first. If you are not sure what a specific usermeta key does, just leave it alone. There’s a reason this option is hidden inside advance settings. We assume, at this stage you are pretty sure which usermeta key you are looking for. Select it and save the field options.
You can also define your own (new) usermeta key by selecting Define New User Meta Key. That will display a new text box:
You will be asked to name a new usermeta key which will be registered with WordPress upon saving. Usual restrictions on naming applies.
This is how you create or map existing usermeta keys to your RegistrationMagic Form fields. As stated before, you can map multiple fields inside a RegistrationMagic to multiple usermeta keys. This essentially means you can use RegistrationMagic forms to allow your website users to update their profiles created with another plugin. But using this method, you will also have opportunity to add non-profile fields (like reason for updating) and turn each update into a report. Combine this with ProfileGrid and possibilities are endless. You can create single field forms to update specific field, save forms inside ProfileGrid tabs and more.

Important notes and things to take care of

But there are few things you should always remember while using this process:
  1. Be sure to check the expected values for the existing usermeta key. If another plugin expects the value to be number, you have to bind it to RegistrationMagic Number field and so on.
  2. There are restrictions on how you name a new usermeta key.
  3. Once a value is saved inside usermeta table, any other plugin can retrieve it.
  4. A usermeta key is registered for all users and not for single user. Although the value can be defined only for one.
  5. Avoid mapping with usermeta key used by WordPress to store options unless you are completely sure what you are doing.
  6. RegistrationMagic has in-built system to display form data on the front end. But to convert it into full fledged profiles and membership system, you will need a plugin like ProfileGrid.
  7. RegistrationMagic allows you to display a field from the form on frontend user area without registering it as usermeta key. Use this for simpler scenarios to avoid adding unnecessary keys to your system.
  8. Following keys are reserved for WordPress Core and cannot be used as part of usermeta system:
    1. user_login
    2. user_pass
    3. user_nicename
    4. user_email
    5. user_url
    6. user_registered
    7. user_activation_key
    8. user_status
    9. display_name
Another important thing to remember — some RegistrationMagic field types are pre-mapped to usermeta keys. Use them wherever possible instead of mapping to new generic field types. Pre-mapped fields are already configured to save and retrieve usermeta values in most suitable format. These fields are:
RegistrationMagic Field Type
Mapped to (usermeta key)
First Name
first_name
Last Name
last_name
Biographical Info
description
Nickname
nickname
Website
user_url
A word about WooCommerce – like other native WordPress plugins, WooCommerce too uses usermeta system to store information about customers. RegistrationMagic has three Field Types pre-mapped to composite WooCommerce usermeta keys. It means the values from RegistrationMagic WooCommerce fields will be interspersed to different WooCommerce usermeta keys automatically, billing phone number being an exception.
RegistrationMagic Field Type
Mapped to (usermeta key)
WooCommerce Billing Field
billing_last_name
billing_company
billing_address_1
billing_address_2
billing_city
billing_state
billing_postcode
billing_country
billing_email
WooCommerce Shipping Field
shipping_first_name
shipping_last_name
shipping_company
shipping_address_1
shipping_address_2
shipping_city
shipping_state
shipping_postcode
shipping_country
Billing Phone Number
billing_phone
We hope this guide will bring you one step closer to becoming WordPress power user. If we missed anything, or you want us to add new features to RegistrationMagic usermeta mapping system, do not forget to let us know in the comment section.

Leave a Comment

Your email address will not be published. Required fields are marked *

shares