As I mentioned in the WP-Members 3.1.7 announcement, there is a new filter hook that will allow greater flexibility of customizing form fields that are used when the registration form is displayed. One common request that this solves in a better way is how do I display fields for registration but not for user profile or vice versa.
I’ve isolated the filter so that rather than run the filter everywhere the wpmem_fields() function is used, it just exists within the wpmem_fields() function. This way, the fields that are in the fields array are filtered whenever they are requested.
The filter passes a “tag” (identified by the $tag variable) to identify what is being done using the fields. If there is no $tag, the default is for all fields to be loaded, so it’s not necessary to pass $tag when the function is used.
Suppose that we have the native WP-Members fields that are installed – first/last name, email, address information fields and phone, and we only want to display first/last name and email fields at registration but we want the additional fields included on the user profile.
Using wpmem_fields filter, we can remove those extra fields from the registration process by checking the $tag.
add_filter( 'wpmem_fields', 'remove_default_fields', 10, 2 ); function remove_default_fields( $fields, $tag ) { if ( 'register' == $tag ) { unset( $fields['addr1'] ); unset( $fields['addr2'] ); unset( $fields['city'] ); unset( $fields['thestate'] ); unset( $fields['zip'] ); unset( $fields['country'] ); unset( $fields['phone1'] ); } return $fields; }
Note that by checking for the tag “register” we are removing these fields from the array for both form display and processing. Suppose you gave opportunity to register without these fields but if the user was going to update their data, it would be required. You can now make those fields required in the Fields tab, but since they are removed from fields when the registration form is processed, you don’t have to jump through hoops to make sure processing is correctly handled in this case.
The tags for form display and processing are:
- register (WP-Members registration form)
- profile (WP-Members user profile form)
- register_wp (native WP registration)
- profile_dashboard (dashboard profile for user)
- profile_admin (admin profile for user)
Site members you are welcome to discuss in the forum below – non-site members you won’t see that forum because it’s only for premium support subscribers. You can use the contact form to give feedback or input, or better yet, join the site for full access.
UPDATE 2/6: As of the update released on 2/6 (commit 4067b2d), I shifted away from the “pairs” of tags and opted for a single tag for each registration or profile update process. This includes the WP-Members process. So instead of using “new” for the form display and “register” for the form processing, you can just use “register”. I just can’t see a need for maintaining separate tags through each process and I believe using a single tag to identify the process (form display and form processing) will make it easier to use.
UPTATEAs of the final release, the filter hook was changed to be “wpmem_fields” (not “wpmem_form_fields”). The information in the article above has been changed to reflect the hook as it is in the final release.