• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

RocketGeek

Home of WP-Members, The Original WordPress Membership Plugin

  • WordPress Plugins
    • WP-Members
      • FAQs
      • Quick Start
      • Documentation
      • Extensions
    • Advanced Options
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Download Protect
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Invite Codes
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • MailChimp Integration
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • PayPal Subscriptions
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Salesforce Web-to-Lead
    • Security
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Text Editor
      • Purchase the Plugin
      • Get the Pro Bundle
    • User List
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • User Tracking
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Memberships for WooCommerce
    • WordPass
  • Blog
    • Basics
    • Tips and Tricks
    • Filters
    • Actions
    • Code Snippets
    • Shortcodes
    • Design
    • Release Announcements
  • Store
    • Cart
    • Checkout
  • Contact
  • Log In
  • Show Search
Hide Search
Home » Plugins » WP-Members » Documentation » Filter Hooks » wpmem_fields

wpmem_fields

Description

This filter allows you to make changes to the fields settings array before the fields are passed to the form building functions.  This allows you to add/subtract fields from different forms and/or on different pages.

For example, you may wish to display fields on the user profile update that are not included in registration.  This function allows you to make those changes in one place so that you do not have to worry about filtering the fields out of the form and then also filtering them for processing.  Both are handled by this filter.

Parameters

$fields
(array) (required) The form fields settings array.

$tag
(string) (optional) Indicates the process for the form (register|profile|register_wp|profile_dashboard|profile_admin).

Examples

Remove default address/phone fields from the WP-Members registration form, but not the user profile update form:

/**
 * This example removes the WP-Members default address/phone fields
 * from the form if it is being displayed for registration, but
 * would leave them in for user profile update or any other 
 * process.
 */
add_filter( 'wpmem_fields', 'my_remove_reg_fields_filter', 10, 2 );
function my_remove_reg_fields_filter( $fields, $tag ) {
 
    if ( 'register' == $tag ) {
        unset( $fields['billing_address_1'] );
        unset( $fields['billing_address_2'] );
        unset( $fields['billing_city']      );
        unset( $fields['billing_state']     );
        unset( $fields['billing_postcode']  );
        unset( $fields['billing_country']   );
        unset( $fields['billing_phone']     );
    }
     
    return $fields;
}

Similar to the above example, but uses an array of meta keys, removing from the registration form any field whose meta key is in the array.

/**
 * Remove fields from the registration form using and array of
 * meta keys. Loops through the array to remove (unset) fields 
 * found in the array from the settings.
 */
add_filter( 'wpmem_fields', 'my_remove_reg_fields_by_array', 10, 2 );
function my_remove_reg_fields_by_array( $fields, $tag ) {
 
    if ( 'register' == $tag ) {
     
        $remove_meta = array ( 'billing_address_1', 'billing_address_2', 'billing_postcode', 'billing_country' );
         
        foreach ( $remove_meta as $meta ) {
            unset( $fields[ $meta ] );
        }
    }
     
    return $fields;
}

An example of removing a field from the user profile update form but not the registration:

/**
 * This example removes a field (in this example - phone1) from
 * the user profile update. That way, the user cannot update 
 * or change this field after registration.
 */
add_filter( 'wpmem_fields', function ( $fields, $tag ) {
 
    if ( 'profile' == $tag || 'profile_dashboard' == $tag ) {
        unset( $fields['phone1'] );
    }
     
    return $fields;
}, 10, 2 );


/**
 * Same as above for several field meta keys in an array.
 */
add_filter( 'wpmem_fields', function ( $fields, $tag ) {
    
    // Only remove if we're on the profile or profile_dashboard view.
    if ( 'profile' == $tag || 'profile_dashboard' == $tag ) {
 
        // An array of field meta keys to remove.
        $remove_fields = array( 'my_field1', 'my_field2', 'my_field3' );
        
        // Loop through the array and unset the key from the $fields array.
        foreach ( $remove_fields as $remove_field ) {
            unset( $fields[ $remove_field ] );
        }
    }
     
    return $fields;
}, 10, 2 );

Notes

The array key for each field in the array is its meta key. Each field in the array is an array of setting values as noted below.

All fields must include the following:

  • label (string) The text for the field’s label.
  • name (string) The field’s meta key. This is what will be stored in the database (wp_usermeta for non-native fields). Avoid spaces and hyphens (recommended: all lowercase characters, numbers, and underscores only).
  • type (string) The field type:
    • text
    • email
    • select
    • multiselect
    • checkbox
    • multicheckbox
    • radio
    • textarea
    • url
    • number
    • date
    • password
    • file
    • image (a “file” input type, but handles images specifically)
    • hidden
    • option (subset of “select”)
    • membership
  • register (bool|int) 1 if included in registration form, 0 if admin only
  • required (bool|int) 1 if required
  • profile (bool|int) For future development
  • native (bool|int) 1 if a native WP field

The following values are supported by all fields, but are optional (the above are required)

  • id (string) (optional) The “id” attribute of the HTML5 tag. Defaults to the field meta key if not specified.
  • class (string) A custom CSS class name (defaults to “textbox” if no class is given)

The following values are supported by text, url, email, and password field types.

  • placeholder (string) Placeholder text for an empty field
  • title (string)
  • pattern (string) A regular expression (regex) pattern as supported by HTML5

The following values are supported by the number field type:

  • placeholder (string) Placeholder text for an empty field
  • title (string)
  • min
  • max

The following values are supported by the date field type:

  • placeholder (string) Placeholder text for an empty field
  • title (string)
  • pattern (string) A regular expression (regex) pattern as supported by HTML5
  • min
  • max

The following values are supported by the checkbox field type:

  • checked_value (string) The value to save if the checkbox is checked.
  • checked_default (bool|int) If the checkbox should be loaded as checked by default (1|true)
  • checkbox_label (int) Defines if the checkbox label is added before or after the HTML input for the checkbox. 1 loads after (to the right). Defaults to 0 (loads label first/to the right).

Changelog

Introduced in version 3.1.7

Source

wpmem_fields is located in includes/api/api-forms.php

Not sure what to do with this code?

You're not a "coder" and don't know what to do? Don't worry! Code Snippets are the basic building blocks of WordPress customization, and once you know the basics, they are simple to use.

Here are some free articles to get you started:

  • Using Code Snippets from the Site
  • Using a code snippets plugin
  • The functions.php File
  • Create a plugin file for custom functions
  • Create a child theme
  • Do not modify plugin files!

For "hands on" help, consider a plugin support subscription or the Pro Bundle.

  • Getting Started
  • Recommended WordPress® Settings
  • Plugin Settings
    • Options
    • Fields
    • Dialogs
    • Emails
    • New Feature Settings
  • Managing Content
    • Restricting Posts
    • Restricting Pages
    • Show Excerpts
    • Custom Post Types
  • Managing Users
    • Import Users
    • Export Users
    • Edit Users
    • Search Users
  • Login
  • Registration
    • Choosing Fields
    • Create a Registration Page
    • Moderating Registration
    • Using CAPTCHA
    • Removing Registration Options
  • User Profile
  • Memberships
    • Membership Properties
    • Membership Levels
  • Menus
    • Individual Menu Items
    • Logged In Menus
    • Login/Logout Menu Link
  • Customizing Emails
    • Email Address
    • Email Content
    • Email Format
    • Email Shortcodes
    • Email Troubleshooting
  • Customizing Forms
    • Create a Custom Stylesheet
    • Using the WordPress Customizer
    • Login Form HTML
    • Registration Form HTML
    • Widget Login Form HTML
  • Translation and Localization
    • Maintain a custom translation file
    • Filter untranslated strings
    • Multi-language Considerations
  • Shortcodes
    • Pages and Forms
    • Login Status
    • User Fields
    • Memberships
    • Email
    • Other Shortcodes
  • WP-CLI Commands
  • API Functions
  • Filter Hooks
  • Action Hooks
  • FAQs
    • Email troubleshooting
    • Passwords are not being included in Emails
    • The plugin isn’t blocking my content
    • Are files protected?
    • How can I prevent registration spam?
    • How to add a shortcode
    • How to apply login redirects
    • Why can’t users log in?
    • Why does reCAPTCHA v3 fail?
    • Troubleshooting Really Simple Captcha
    • Why do I get a 403 error?
    • How do I use code snippets?
    • My changes aren’t showing up
    • How to hide the “Admin Bar”
    • How to add a forgot password link
    • Password reset doesn’t show any fields
    • Domain not included in the password reset link
    • There was an error processing the form
    • Hidden vs. Restricted
  • Demo Videos
  • How to Request Support
  • Copy Settings for Support
  • Hosting Recommendations

Ready to get started?

Join Today!

© 2025 · butlerblog.com · RocketGeek is built using WordPress, WP-Members, and the Genesis Framework

  • butlerblog.com
  • WP-Members Support Subscription
  • Terms of Service
  • Privacy Policy
  • Refund Policy