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:

102 Responses to Adding Custom Fields in WP-Members™

  1. Ivy says:

    Hi Chad,

    Thank you for this plugin, this really helps. I have one quick question. I want a dropdown field in my registration form, so I uncomment the lines about how to add dropdown in wp-members-install.php but it doesn’t show in the backend. Can you help me with this? Did I miss something?

    Thanks,
    Ivy

    • Chad says:

      So the question would be, is it showing on the front end? If it’s not showing on the front end or the back end, then it didn’t install correctly. If the plugin had been previously installed, you also need to follow the instructions above to force an install.

    • Rez says:

      Hi Ivy,
      Have you find the solution for the dropdown field? If you do, could you please tell me how you find it out.

  2. Angela says:

    Hi,

    I’m very excited to try this plugin! Wondering if it’s possible to add a custom field where someone has to enter an invitation code in order to register.

    In other words, I don’t want just anyone to be able register. This is a doctor only site and registration is by invite only… is there a way to have registrants enter a code that is given via email during the registration process? The “Membership” WP Plugin has this functionality… wondering if wp-Members does also…

    If not, can I use the Sabre plugin or some similar plugin in tandem with wp-Members to protect site registration?

    Thank you in advance for your time!

    ~ Angela

    • Chad says:

      Hi Angela – thanks for the comments. There is no allowance for an invitation code at this time, but that is a good idea that I’ll need to add to the project list. Unfortunately, I’m not familiar with the Sabre plugin so I can’t really give you any insight into integration (although the WP-Members registration process is self contained so without directly modifying the code, I don’t think that it will).

      • Angela says:

        Hi Chad,

        Thanks for your reply. The Sabre plugin didn’t work out the way I had hoped. It didn’t integrate smoothly with your WP-Members plugin. Unfortunately, registration by invite only (needing a special code to prevent just anyone from registering at the site) is critical for the site I’m building… I couldn’t find any plugins or combination of plugins that offered exactly what I needed and many didn’t even work! So I ended up scrapping WordPress and going with Drupal.

        If you ever do decide to offer an invitation code option as part of your plugin, please do let me know! I like everything else about the plugin you have to offer! It was just missing that invite code. =)

        Thanks again!

        ~ Angela

  3. Ash says:

    Hi,
    How can we change the password so that it is not auto generated, but it set up by the user in the form?
    Any Ideas?

    Ash

    • Chad says:

      After a successful registration, a user can login and set their password to whatever they want. The purpose for autogeneration is for validation – the registrant must provide at minimum a valid email.

      It could be changed from this process, but you need to make several modifications to the core which is not recommended.

  4. Victor says:

    When i click on register it doesnt take me anywhere. It’s like if the registration link is dead. What am i doing wrong? Please help.

    • Chad says:

      You haven’t really provided any information that would allow me to give you an answer. Where on the page is the link that you are referring to (is it part of the plugin)? What is the text of the link? What is the URL the link is pointing to? Have you set a registration page in the plugin settings? Has that page actually been created/setup? Do you have a link to an example of what you are describing?

      • Victor says:

        Hi Chad,

        I am new to this so I apologize for sounding like a noob.

        The website is thermgl.com

        I created a page for registration and under the wp-settings i where “register page url:” i put http://thermgl.com/registration.

        what do you mean what is the text link?

        Please help.

        Thanks in advance!

        • Chad says:

          Victor – it’s no problem sounding like a noob, but regardless of whether it’s WordPress or anything else, when asking for support, the more information you can provide at the outset, the better. It makes it much easier to give you some direction.

          I can see that you have set up a registration page. I can also see that you have this correct in the settings because when I look at the WP-Members sidebar widget on your home page and click “register,” it goes to the correct page. So that ultimately brings us back to the question what is the text of the link you are clicking that you are saying doesn’t take you anywhere. And what is the location that link is supposed to be directing you to (shown to you in the footer of your browser when you mouse over a link)? If it’s the forum that you are talking about, then you need to track that down in the forum. The only registration links that WP-Members puts in automatically are in the login forms that it generates and that link information comes from the setting we already mentioned that you have correct. Anything else would be outside of the plugin.

          • Victor says:

            Chad,

            i stayed up late last night reading your quick guide and figured out how to correctly install the plugin and create the page.

            The text link i was referring to was the “register” link. Now when i click on register it does take me to the register page but nothing is lined up and it looks horrible.

            Is there anyway to adjust the columns and make it look nice and clean?

            Thanks in advance!

          • Chad says:

            Hi Victor – I’m not sure how familiar you are with CSS, but that’s basically a styling issue. There may be some inherited elements from other stylesheets that you’ll need to define and create a custom stylesheet for the plugin. http://butlerblog.com/2011/07/25/customize-the-wp-members-stylesheet/ will get you started with how to set up a custom stylesheet for the plugin. As to how to customize it, because that can vary from user to user depending on your theme and other plugins, you will need to work on that.

            If that turns out to be too much of a challenge (depending on your familiarity with CSS), then you might just try changing to use the table-based legacy forms in the plugin’s settings. These are less customizable, but will generally work well in most situations.

  5. Pam says:

    I want to change the dialog message when a user tries to login with the incorrect username or password. I thought I had found it in the wp-members-dialogs.php file under “function wpmem_inc_loginfailed()” but when I changed, saved and uploaded there was no change to the message. I also changed the height of the dialog box thinking maybe it didn’t have room to display but that didn’t fix it either. This is a site that members already had registered but now need to establish new usernames & passwords. I want to add a message that they will need to re-register on the new site. Thanks for any help you can give me.

    • Chad says:

      The majority of the dialog messages are editable in the plugin’s admin panel. If you want the message to display where the login/registration goes, update the dialog for restricted posts (the first in the list) accordingly. I would highly advise against making changes directly to any of the core files.

  6. jeffry says:

    Hi Chad,

    first of all, your plugin saves me alot of sweat! it’s a really nice plugin. But i want to make a group of checkboxes, i already select the ‘checkbox’ type and insert the value, but how do i add the label for it?

    Say i want to make a group of ‘hobbies’, how do i make them like: ‘checkbox’ – sports, ‘checkbox’ – games, bla bla bla

    thanks for the enlightment Chad!

    • Chad says:

      Thanks for the comments. If they are checkboxes (there is not currently radio group support), then the best way to do it would be with CSS styling. Each form element gets an ID. Handling the layout with CSS would be the best way. Here is some insight on setting up a custom stylesheet to start.

      The other possibility would be to create your own form. If you are handy with PHP and/or HTML, you could plug the function wpmem_inc_registration_NEW (information on WP-Members pluggable functions here). Note that if you set your form elements and don’t plan on changing them, you could hard code most of the form into this function rather than using the php loop, etc. However, note that there are probably going to be some changes in this area of the plugin in the near future (2.7 won’t touch it, but possibly later) and even though pluggable functions help keep you from having to re-do such hacks, you do need to monitor the customized functions when new versions come out to make sure customizations are still compatible.

  7. Kevin says:

    Hi, great plugin, better than ones I paid a lot for.
    I’m wondering how I can change the titles of the login and registration boxes from Userlogin/New user registration to something custom. Thanks.

  8. Rob says:

    Hi Chad,

    Thank you for the plugin, it works great.

    People ask me if I can change the labels to Dutch (Voornaam First Name)

    Is this possible without reinstalling?

    Kind regards,
    Rob

  9. Rodwin says:

    Hi there! thank you so much for this wonderful plugin. Please help me with my problem regarding adding members. My client want me to add their existing 11 thousand members to wp-members database with information. How can i add BULK members in wp-members database with their corresponding information like age, gender, birthday etc. Is there a way i can add it as csv file to database or any recommended plugin. Please kindly help me.

    • Chad says:

      With a list that large, I would highly recommend a direct import via MySQL. You need to be familiar with the WordPress database structure (specifically the wp_users and wp_usermeta tables, http://codex.wordpress.org/Database_Description). You’ll need to know how to do SQL joins for the meta data. Also, you should be aware that you could run into challenges with passwords. WP stores passwords as PHPass hashed. If an MD5 hash is imported, that’ll work too, as WP will simply change it to PHPass when the user first logs in.

  10. Sarah Parisi says:

    Hi,

    I have been trying to use this plugin and this is a great plugin for blocking posts . I have a simple (maybe stupid) question. In my blog, are new users are created by me (upon user’s request email). I create a new user, but then I go back to his profile (to fill out his other details), but I see some fields under “WP-Members Additional Fields” . I don’t worry about TOS field, but what is the purpose of the field ” Activate this user?” ? Also, if I check this field, it sends out an email automatically to the user. How can I stop this email? Please let me know. Thank you for the great plugin.

    • Chad says:

      The activate user process is for if you want registrations to be approved by you. If you are handling registrations yourself, then you don’t need that. Just turn off registration (in the plugin options) and don’t set up a registration page.

  11. Marcelo Paoli says:

    Hi Chad, i’ve just noticed that in the back end the custom fields appears in the edit-user screen, but not in the add-new user screen. I’ve searched thru the website for a workaround, but didn’t find anything. Do you know of some way i could show the fields, or manually hack the fields in the user-new.php?

    Thanks.

    • Chad says:

      That’s actually something I’ve wanted to take care of for quite some time, but I don’t know of a way to hook into that page (there is nothing currently documented). I would highly advise against hacking the WP core page directly – you could either create problems or you’ll need to update in the event of an upgrade (and not keeping up with WP updates is a good way to get hacked these days). I would suggest that if you are adding users manually, that you either do it on the front end, or add them via the backend, then update fields on the user profile page.

      • Marcelo Paoli says:

        I was trying to create a menu item (like add new wp-member) in the back-end with a page that contains the wp-members front-end form, that way i would’nt need to hack WP, but instead create wp-members own add-new members. but i got stuck somewhere in the code. The problem is that when i’m logged, it doesn’t show the form, it returns the “You’re already logged in as ….”. Don’t know if that approach would work, as i also would like to set the users password manually.

  12. wasim says:

    Hi chad,
    I have my own custom field set for registration form, and now i want to extract the value of that custom field , how can i print the array?
    i want to record the url of the registration page and add it as a custom field, so when user is approved and try to login , after successfull login the user will be redirected to that url he signed up for.
    Thanks

  13. Phill says:

    Hi Chad,

    The plugin is amazing, great job!

    I’m wondering how I can change the text “Please indicate that you agree to the TOS”? (or add my own to a new checkmark)
    I would like it to say something like “Clicking ‘Agree to Needledrop’ signifies your acceptance to the terms of this Needledrop Agreement.”

    If possible I would also like to have people agree to our “NeedleDrop Agreement” first before proceeding to the registration page, and would not be able to access our registration form unless they click agree, is this possible?

    Thanks Chad!
    Phill

    • Chad says:

      Hi Phil – there is actually a new filter being added in the next release that will allow you to customize the TOS link. I know that doesn’t help you today, but if you look at the plugin upgrades, I tend to get something out with additional features every few months.

      As far as having them agree to the agreement before accessing the registration page, that’s something that could be done, but detailing it would be beyond explanation here. There are filter hooks for the login and registration forms, so you would need some knowledge on using WordPress hooks. Essentially, an outline of how you could use the filter wpmem_register_form would look something like this:

      <?php
      add_filter( 'wpmem_register_form', 'my_register_form_filter' );
      
      /**
       * Function to display terms or register form based
       * on whether terms were agreed to. Would need to also
       * build some process for handling the agreement to
       * terms outside of this function that would be 
       * triggered with a WP hook that happens prior to 
       * data being sent to the browser.
       */
      function my_register_form_filter( $form )
      {
      	
      	/**
      	 * Check for the presence of a cookie or some type
      	 * of meta indicating they have agreed to terms.
       	 */
      	
      	/**
      	 * Test if the above is true and display forms
      	 * accordingly.
       	 */
      	
      	if( $some_test == true ) {
      	
      		/**
      		 * if the test is true, they have 
      		 * agreed to terms, return the register
      		 * form unchanged.
      	 	 */
      		
      		return $form;
      	
      	} else {
      	
      		/**
      		 * otherwise build the process of 
      		 * displaying the terms for agreement
      		 * and allow them to agree.
      		 *
      		 * build this as $some_other_form
      	 	 */
      		 
      		$form = $some_other_form;
      	
      		return $form;
      		
      	}
      }
      ?>
      
      • Phill says:

        Wow Chad, Thank you very much for the detailed explanation, I will definitely be waiting for the next release with great anticipation.

        Thanks again!
        Phill

      • Phill says:

        Chad,

        For the mean time, until the next release is there any way possibly in the code to have the TOS link to a separate page I’ve created?
        unfortunately I need to add the current date PHP code to the TOS, in the dialogs setting section the TOS only supports simple html so I’ve created another page altogether, I just need to link to it.
        Is there any way?

        Also, has anyone had any problems with the lining up of the boxes that you know of? any suggestions on what I should take a look at in the CSS?

        Thanks Chad,
        Phill

        • Chad says:

          Yes, you can actually use the wp-members shortcode for that. The format for the TOS is [wp-members page="tos" url="http://yourdomain.com/your-tos-page"] and you would put this in the TOS dialog field in the plugin settings.

  14. Pam says:

    I can’t seem to figure out where to enter text for a dropdown list on a custom field. I have created the custom field, but where do I enter the options for user to select?

    • Chad says:

      That needs to be done at the time you create the field in the box provided (“For dropdown, array of values:”). There is a link to instructions for more information right next to the box.

  15. Brian L says:

    Hi Chad,
    Great Plugin, help keeps our users under control!!
    I am using two additional fields that are configured as dropdown, my question is, can the dropdown list be updated without having to delete the field and re enter a fresh list of options?
    We are using these two fields for holding version numbers of users software. I use dropdowns so it make filtering easier, and the data collected is consistent. Also if I do have to delete and start again with new items in the list, do I also loose all my previous data collected?

    Thanks in advance

    Brian L

    • Chad says:

      Hi Brian – at some point, I will get an edit option for custom fields. I haven’t gotten to that yet because it’s a significant amount of programming overhead. Before I added the dropdown option, it was just as easy to delete/add as it would have been to update. Now that I added the dropdown feature, for users that might be adding something to the list every so often, I really do need to add an edit feature, so that will be coming at some point in the near future.

      So… you do need to just delete and add new for now. However, that will NOT delete any data collected. Deleting the field will only delete the field itself, not any of the user meta that is stored.

      Hope that helps!

  16. emmanuel says:

    Hi Chad, you’ve done a really great job with this plugin its excellent so far, I only have one problem,
    I installed the plugin and its very good but the thing is when I created a user(subscriber) it gives the user access to my wp-admin dashboard and I dont want that, I created the members page and set the custom field as unblock and set the value to true but it still gives the user access to my wp-admin dashboard.
    Thanks

  17. emmanuel says:

    or could it be because I’m still running on localhost? I haven’t hosted the site online yet

  18. Report says:

    Hello, can I ask you how can you print in the .php template the value of an extra field added? Actually, if I have added the “Full address” / “full_address” field in the registration process, which is the variable to print it?
    Thank you!

  19. raja says:

    sir how 2 add date of birth Fields …

    • Chad says:

      There is not any built-in validation for that. There are ways to use custom validation, but unfortunately, I have not been able to write any documentation on that. when I do, it would be posted at rocketgeek.com (which is the support site for the plugin).

  20. Kevin Ross says:

    Hi Chad,

    I am using WP-Members plugin Version 2.7.7

    Can I re-align the Fields in the registration form. Currently I have 12 custom fields and they all appear one after another in separate rows. I want to have at-least two fields per row, can you explain how I can do that?

    Currently it appears..
    FirstName:——
    LastName:——
    City: ——
    State:——

    And I wanted them like..
    FirstName:—— LastName:——
    City:—— State:——

    Thank you
    Keviz

Comments for this post are now closed.
All support for WP-Members has moved to rocketgeek.com.