Adding Custom Fields in WP-Members™

Note: With the introduction of WP-Members™ 2.6, users can now create new fields and delete exiting ones using the plugin’s admin panel.  That feature renders this methodology unnecessary for most users, unless you have a reason to set up custom fields at install.

The single most common question I receive about the WP-Members™ plugin is how to add custom fields (or change the fields that are installed).  Changing the fields that are installed is a very simple process, as you will see. 

The fields are stored in the WordPress database in the options table.  They are stored as a single array (so that we don’t bulk up the database with multiple entries unnecessarily).  This array is written to the database when the plugin is installed.  It is recommended that if you are customizing the fields, you begin with a clean install.  (That means that if the plugin is already installed, you should not only deactivate it, but delete it via the plugin manager in the WP admin panel.  This will clean out any database entries the plugin has made.)

The install script is in the file wp-members-install.php. As with any plugin, the plugin files can be found in the WordPress plugins folder.  This is found in:
/your-wordpress-folder/wp-content/plugins/
WP-Members™ stores all of its files in its own folder in the plugin folder, and that is where you will find the install file:
 /your-wordpress-folder/wp-content/plugins/wp-members/wp-members-install.php

As an alternative, if the plugin is already installed on your system, you can use the Plugin Editor in the WordPress admin panel.  In the WP Admin Menu, go to:
Plugins > Editor
In the upper right hand corner of the Plugin Editor there is a dropdown menu.  Select WP-Members™ from the list.  Then select wp-members/wp-members-install.php from the list of files, make the appropriate changes, then save by clicking “update file.”

In wp-members-install.php, look for $wpmem_fields_options_arr near the top.  This is where the array values are defined.  Change these accordingly based on the following:

  • Order: Not used yet, but will be in the future.  This will define at what point in the display order the field will appear.  Since this is not used presently, you must keep the fields in the array in the order you want to display them.
  • Label: This is what will display in the form next to the field.
  • Optionname: This is used by the script to pass values to the script.  The important thing to remember here is that you CANNOT use spaces in your definition; i.e. ‘field_name’ NOT ‘field name’.  Note: this does not display to the user.
  • Input type: Defines the field type.  At present, fields must be text.  Checkbox is being tested and should be considered experimental.
  • Display: This sets the default setting upon install whether this field is displayed or not.  y = yes, it is displayed, n = no it is not.  Once you install, you can change this value for each field via the plugin’s admin panel.
  • Required: Sets whether the field is required or not based on the same principle as above.
  • Native: Not really important.  The defaults are all set to tell you which fields are natively part of WP and which are not.  Any custom fields you create are obviously not, but setting them to ‘y’ is not going to break the script.

You should find this fairly intuitive, just basically copy the process as it is already in the installation.

If you have already installed and activated the plugin on your system, you will also need to force the new field array into the database.  This is done with a toggle at the top of the install file:

$chk_force = false;

Change this to:

$chk_force = true;

Then save the file and using the plugin admin panels, deactivate then reactivate the plugin.  This will force your changes into the database.  Following this procedure, it is recommended that you change the toggle back to “false” and also check your WP-Members™ settings for anything you may have set back to the default options through this process.

Some important notes:

While I do not think this process is that difficult, you should use these steps at your own peril – especially if you are clueless when it comes to php.  If you choose to customize your installation and break it, please do not come to me and ask me how to fix it.

Also, it is highly recommended that you not change any of the WordPress native fields.  Without getting into too much necessary detail, most of these are stored a certain way and the plugin makes assumptions based on names and locations in the database for these.  It doesn’t mean you have to use them, and certain ones are non-essential, but do not change their optionname.

About Chad

Chad Butler is both a freelance writer and web developer. He has developed several popular WordPress plugins and his writing has appeared on forbes.com, sfomag.com, and investopedia.com.
This entry was posted in WP-Members and tagged , , . Bookmark the permalink.

Related Posts:

76 Responses to Adding Custom Fields in WP-Members™

  1. Kristy says:

    Hi! First – great plugin! 2nd, as a follow-up question: When you change the custom fields in the array, do you have to make any additional changes to any other files? My issue is the custom fields appear, but when users click the Edit my Information link – the custom fields I put in, do not echo back the previously entered data.

    For example – Custom field is Allergies. At registration, user enters SEAFOOD in the allergies field. This shows in the User dashboard in WP Admin.. But when user login and wants to update the profile — Allergies field is empty and does not show the previous value.

    Is this due to something I messed up? Or are other adjustments needed?

    Thanks in advance!

    • Chad says:

      Kristy – I’ll need to do some testing, but the first thing to check is to make sure you do not have any spaces in the value for optionname. Labels can have spaces, but not the optionname.

      • Mike says:

        Did this get resoloved as I am interested in you plugin but the user needs to be able to change there information and see the information they used at registration…? Thanks!

        • Chad says:

          Mike – thanks for your question, users have always been able to see the information they used at signup and also update it. How to set this up is clearly outlined in both the Users Guide and the Quick Start Guide, both of which are linked to on http://butlerblog.com/wp-members. That would be a good place for you to start.

  2. Maja says:

    Thanks for the wonderful plugin. But i haven’t been able to change the form’s labels. I did tried to change $wpmem_fields_options_arr but i couldn’t get it done. I went further changing the values on the database, but too couldn’t give me anything. Anything i’m missing here?

  3. Karl W says:

    Is there any way to have the login widget direct a valid login to another (protected) page? It is now on an unblocked static landing page & I would prefer to have it open to the “Members Area” page on login rather than stay on the landing page.

    Thanks.

    • Chad says:

      Karl,

      The widget only logs in to itself. You could tweak the code, but then you do create problems in the event of an upgrade (you would have to re-do any changes you made).

  4. Will Chapman says:

    I’ve looked at a lot of member management and WP-Members is the closest to what I need – thanks!

    Until I read this thread I had two issues – this thread answers the first – thanks again!

    I note from an earlier post that you are looking at different field types – does that include a multiple selection drop-down (or check boxes)?

    Also do you have any plans to include profile fields that have been added by other plugins/themes (e.g. BuddyPress has a Profile Field feature that is picked up by some other plugins)?

    • Chad says:

      Hi Will – thanks for the comments!

      Yes, I want to add drop downs to the field types. And here’s a secret – check box support is actually there, it’s just untested from the standpoint of end users customizing the fields install. I should probably add that to this post.

      I like the idea you mentioned about picking up additional profile fields from other plugins. At this stage I’m not sure how I would do it, considering the way WP-Members handles it’s fields (stored in a single array). I’ve considered some other ways of doing it, but for now, this seems to be working. But I like the idea, especially with the more popular plugins like BuddyPress. I will definitely add it to the wish list.

      • Sam says:

        Hi Chad.

        Did you ever implement support for Select form elements? I don’t see it on the newest release and wonder what happened to this.

        Thanks!

        • Chad says:

          Hi Sam – it is on the project list. I am working on an incremental release 2.6.3 and it might be squeezed into that.

          • Sam says:

            Great. Something (else) to consider is allowing a multiple-select, as opposed to a single value. I am specifically using this plugin in conjunction with Salesforce and have done a bit of modification to capture the registration post into Salesforce at time it is entered. So far, I have just had to modify some of the files manually, but it is mostly doing what we want it to do.

            In other news, I changed the “forgot password” routine to just ask for an email rather than email+username. I replaced
            $user = get_userdatabylogin($username);
            with
            $user = get_user_by_email($email);

            and carried on normally after that. Do you see any issues with this?

            Thanks.

          • Chad says:

            Thanks Sam – I’ll consider that going forward. It will probably start with a simple dropdown just to get it in there, but will expand from there.

            With the password reset, if the array keys returned for get_user_by are the same as get_userdatabylogin (and I think they are), you should be fine. But I would double check to make sure.

  5. Jamie Cutler says:

    Is there any way of adding a new field without having to delete everything and start over? I don’t want to have to loose the members I already have.

    • Chad says:

      It is important to point out that when you delete the plugin via the WP admin panel, you do not delete any users that have registered. The process only deletes any settings that are in the options table (the fields, the plugin options, etc). Users are in the users and user_meta table and plugin deletion does not touch those.

      However, if you add/remove fields, your existing users will not have data for these new fields unless they actively change it via editing on the members page (or you add it through the user admin). This won’t effect their ability to login, but they will have empty data until it is updated.

  6. Hi Chad, thanks for the plugin! I did go ahead and experiment with the custom checkbox on registration and it works just fine, as far as I can tell. One issue that doesn’t work quite right is when a user is allowed to edit their info via the “/members-area/?a=edit” page, the checkbox value switches to whatever it had NOT been previously. So, if someone registers on the website with the box checked, then goes to edit their info, they will see the box unchecked. My concern is that members will unwittingly opt-out of our marketing option because of this, but maybe I can find a fix. If you have suggestions, please share! I’m guessing you’re nearly ready to release this as a built-in feature anyway. Thanks again for the great plugin.

  7. Chad says:

    Joe,

    I’d like to introduce checkbox as an officially supported feature, but I’ve got a lot of considerations as far as how to make it customizable and scalable without making things too confusing or making the admin too bulky.

    For now, yes, there is an easy fix. The default value that the wpmem_create_formfield function will set is either “on” (when checked) or null (or “”, when not checked). You might have noticed there is a fourth value that can be passed to the wpmem_create_formfield function, $valtochk. The default of this value is null as it is only used in the creating of a checkbox or option field (for dropdowns). When this is present, the function has two values to compare and uses the function wpmem_selected to determine if it should be checked (or selected, if it’s a dropdown).

    So, here is the fix: the file wp-members-dialogs.php has a function called wpmem_inc_registration which generates the registration form and also the user update form. If you go down to where the form field is created (in the current version 2.3.2, this is line 179) you can add $valtochk to the end of the function call like this:

    wpmem_create_formfield($wpmem_fields[$row][2],$wpmem_fields[$row][3],$val,$valtochk);

    Then, right before this, you can define $valtochk if the checkbox is “on” with this:

    if ($wpmem_fields[$row][3] == 'checkbox') { $valtochk = "on"; }

    The limitation here that I have now realized for scalability purposes is that the auto-generated checkbox does not allow for defining what the check value is, such as “checked”, true, or “y”. So keep in mind that unless you make a modification to the wpmem_create_formfield, the checked value is “on”. Somewhere along the line, I am going to have to change this. So, while I try to consider workarounds that I’ve talked about when I do an upgrade, I’m not sure if that will be a scalable solution with any present customizations – so just keep that in mind.

    Also, I haven’t discussed here the admin panel, which doesn’t account for field types (it doesn’t use wpmem_create_formfield at present). While I probably will upgrade the admin panel to use wpmem_create_formfield, if you want to handle that now, you could look at wp-members-admin.php and review the wpmem_admin_fields function, which is where any custom fields are placed at the bottom of the user edit panel. It’s not totally necessary, but keep in mind that based on the above mentioned workaround, any edits to a user here would need to use “on” as a checked value in the text field, or blank for unchecked.

    Hope that helps!!

  8. Jan says:

    Hi,
    I am trying to add custom fields and i ran into some problems. After a while I figured out that I was not able to use local Swedish characeters (i.e. åäöÅÄÖ) in the description of the new field. I.e. field description ‘båt’ was not possible but field description ‘bat” was. Option table was not updated correctly. Funny thing 1. Field “First name” is translated by the localized version of WP to “Förnamn” and is stored in that way in the wpmembers_fileds option entry. But if i try to change to swedish character directly in the wpmembers_fileds entry for any non-standard WP field even then the plug-in will not work (no fields displayed at all in settings or user admin). Is this a plug-in issue or an issue with my installation? I am using Swedish WP 3.0.2 and everything else related to local characters seem to work. Any other way I can localize the plug-in. I saw in 2.4.0 that you are working on localization support.

    • Chad says:

      Hi Jan, thanks for the comments. Yes, I am working on localization support for the 2.4 release and the fields in the install process are going to be the biggest challenge. I am not totally positive that special characters are 100% compatible with the process that is in place for the fields array so I am looking into some different possibilities. Since I don’t have this totally worked out yet, I’m sorry I don’t have a better answer for you at this point, but hopefully I’ll have this worked out and resolved soon.

  9. alan says:

    Hi,
    I successfully installed and added 2 custom fields but they don’t show in the Edit User admin? what am I missing?

    thanks

    • Chad says:

      If you are looking at a registered user that you know has filled out data in these fields, then you may not have a successful install. Double check to see if they are showing in the WP-Members settings (the place where you set required fields). If they show up there, you are ok. My guess is that you might be looking at the edit user for yourself (the admin user)? If that’s the case, it is likely you won’t see these (or any) of the extra fields unless you’ve added data to them (on a new site, you’d need to do this via the front-end for yourself).

  10. Helena B says:

    Hi Chad

    Thank you for a great plugin!

    I have two questions for you.

    1. When I try to change the label for a form field (from State to County) the form breaks. I’ve changed the label in both the DB and Install.php – not sure what I’d doing wrong. Definitely only changing the label bit.

    2. Where can I track down how the forms are constructed? I’m one of those that doesn’t like tables in forms so I’d like to get rid of them if possible.

    Thanks.

    • Chad says:

      Hi Helena! Thanks for the comments.

      If you need to change a label, it is best to make the change to the array in the install, then re-install. BUT – and this is important – the install process, for a number of reasons, does not overwrite the settings you have if wpmembers_settings is there already. So you need a clean install. You can do this by either (1) delete the plugin using the WP admin panel, which clears out any settings the plugin has made, or (2) you could deactivate the plugin, delete the wpmembers_settings directly from the db, then activate.

      I agree with you – I hate tables for forms as well. Unfortunately, with a plugin that gets used in so many different applications, I had to develop something that fits the largest number of possible scenarios. You can edit the registration table found in wp-members-dialogs.php. However, this will make upgrading more tedious as you’ll need to reintroduce your changes. (And I do have a new version coming out soon.)

  11. Helena B says:

    Chad

    Thanks for your reply – I’ll give that a go. I look forward to your new version.

  12. Art Oswald says:

    We are a small nonprofit organization and would like to have a page for members only that has all of our contact information on it. does you plugin do that?

    • Chad says:

      Yes, Art, it does. Just set the defaults for pages and posts to be not blocked, then you can block the individual page(s) that you want restricted. The installation instructions cover this.

  13. Pop says:

    Hey Chad…. great plugin.. currently using the 2.3.2 version.. n will surely use it for testing and then to my new blog ;)

  14. Jess says:

    Chad – fantastic plug-in! I am currently messing around with the 2.4 beta 4 with the most current WordPress build and have had great success. One question though…

    I successfully added several custom fields including a checkbox for a newsletter and everything seems to be working except that the value for the newsletter checkbox isn’t getting stored properly (unless I am missing something). The email that is sent to the admin for new user registration lists the newsletter but it’s value is blank. It’s also blank if exported out through the plugin although, again the header for newsletter is listed. Any ideas? Any help would be greatly appreciated.

    • Chad says:

      Jess – thanks for the comments and thanks for trying out 2.4. Actually, the checkbox feature kind of sneaked in at the tail end of the development process and so it could be that there are some issues. I’ll take a look and see what I come up with.

  15. Jess says:

    Thank you for the help! And really this is turning into one hell of a plug-in.

  16. Jess says:

    So I figured out a round about way to fix the issue. If the variable for checkbox is stored in the $wpmem_fields_options_arr it breaks, nothing gets stored if the box is checked or not. However if that is left blank and the following is used in the wp-members-dialogues.php:

    if ($wpmem_fields[$row][3] == ‘checkbox’) {
    $valtochk = ‘true’;
    $val = ‘true’;
    }
    wpmem_create_formfield($wpmem_fields[$row][2],$wpmem_fields[$row][3],$val,$valtochk);

    It will default the checkbox to be “on” and will properly store the selection as “true”. AND it will show properly in the new user registration email and export. The only downside is if it isn’t checked it shows as blank or null.

    Hope this helps.

  17. vivek says:

    thanks a lot friend !!
    you saved my lot of time

  18. Hi,
    Thanks for the great plug-in.
    It was working fine all these days. I recently upgraded to Arras 1.5 and I noticed the members area is not working any longer. I deleted the old page and created a new one with the slug name Members-Area still not working. Deactivated and activated many times. Any help or direction?

    Regards

  19. Jess! You’re a life saver! Thanks so much for the wp-members-dialogues.php fix for checkboxes … it works for me now.

    $valtochk = ‘true’;
    $val = ‘true’;

    And, thanks Chad, for keeping up with this plugin … I’ve made a few modifications to fit VG’s needs but couldn’t have done it without you. Thanks!

  20. Dale says:

    I am still trying to get a handle on WordPress. So, if this seems like a simple question, I apologize. Where exactly is the wp-members-install.php file? I have looked everywhere that I could think of. Pointing me in the right directly would be greatly appreciated.

    Thanks

    • Chad says:

      Thanks Dale for your question – that may seem rudimentary to some, yet monumental to others, so I have updated the post accordingly.

  21. Dale says:

    OK. I have added custom text and checkbox fields. However, I need to make a couple adjustments in the way the fields are displayed.

    1) Add the question text before the checkbox options (for example)
    What color is the sky?
    Red
    Green
    Blue
    Yellow
    2) To put the question and options all on one row (for example)
    What color is the sky? Red Green Blue Yellow

    Are either of these possible? I tried messing with the php code a bit but did not get anywhere.
    Thanks for the help

    • Chad says:

      Dale – well, checkboxes are possible, but this example would be more suited to a radio button group. With checkboxes, more than one selection is possible, but with radio groups, only a single option can be chosen. I am working on radio button support, but at present, that’s not an option. Implementing checkboxes is commented in the install file. Putting it on a single row may be possible with some CSS.

      • Dale says:

        Chad.
        Thanks for the response. I have two different set of fields, one could use radio button option if it were available but the other needs the checkbox. However, checkbox can be used for both for now. I am not comfortable enough to mess with CSS yet so placing them in the same row will have to wait. The other element I am unclear about is how to integrate the actual question(s) text into the registration form before the checkbox options, i.e., the “What is the color of . . .” question. Suggestion?

  22. Chris says:

    Hi, is it possible to add an “Upload Resume” field on the registration page and how much do you charge for that? Just a simple add/remove features. And allows the admin to view/download the files when logged in.

    • Chad says:

      Hi Chris – I’ll need to get back to you on that as I’m not sure how I would go about putting the actual upload feature into the process.

  23. Ivan Bakran says:

    Hi
    I like your plugin, it is almost what I needed except for one thing:
    I’d like to add custom fields and let registered users have the ability to update their own information when they are logged in to the page.
    I managed to add a few custom fields. Then I registered a new user and populated the custom fields with data. But when I logged in to the site as the new user and went to the new users profile setting page the custom fields didn’t appear.
    Is this possible to fix?

    • Chad says:

      Sounds like you probably put a ‘y’ in the final value of the array which indicates to the plugin that it is a native WP field. For any custom fields, this final value should be ‘n’. The plugin does not display the native fields in the users profile page because they are already displayed there by WP.

      BTW, I just finished version 2.6 and am finalizing the testing. This new version adds capability to add/delete fields and change the field order (among other additional features).

  24. Ruthie says:

    Hi Chad
    Thank you for this plugin.
    Quick question: I include a description of what we want included in the Biography field. The way I do this is to go into wp-members-dialogs.php and through trial and error figure out where to put the description. Every time there is an update I naturally need to do this again. This tends to be a long and arduous process of trial and error. Especially with the change from table to php format (actually both were arduous).
    This is the site
    http://www.nlccenter.com/blog/?page_id=6
    I was using the TOS but I couldn’t figure out how to get the description under the Bio field and above the the TOS so I just removed it. Any suggestions for a better way of doing this. I am getting reluctant to update to a new version of the plugin.

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *.
Comments are moderated. Please submit only once.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>