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:
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:
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.