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:

[snippet slug=remove-fields-from-register-form-but-not-user-profile-update lang=php]

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.

[snippet slug=use-an-array-of-meta-keys-to-remove-fields-from-the-wp-members-registration-form lang=php]

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

[snippet slug=remove-a-field-from-the-profile-update-form-but-not-the-registration-form lang=php]

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