Purpose
Lets sibling plugins inject extra fields into the user profile screen — both the in-app profile-completion form and the WP-admin user edit page. Pairs with mam_user_roles_save_addl_user_profile_field_{key} for per-field save logic.
Signature
$fields = apply_filters(
'mam_add_fields_to_user_profile',
array $fields,
int $user_id // 0 for new users / signup
);
| Parameter | Type | Description |
|---|---|---|
$fields |
array | Array of field definitions |
$user_id |
int | Current user’s id (0 for new-user / signup contexts) |
Returns: array — augmented fields list.
Field shape
array(
array(
'key' => 'my_plugin_loyalty_id', // usermeta key
'label' => 'Loyalty card ID',
'type' => 'text', // text | textarea | select | yes-no | number | image
'required' => false,
'placeholder' => 'e.g. ABC123',
'help' => 'Find this on the back of your card',
'options' => array( ... ), // for select type
'default' => '',
),
// ...
)
Example: register a custom profile field
add_filter( 'mam_add_fields_to_user_profile',
function ( array $fields, int $user_id ): array {
$fields[] = array(
'key' => 'my_plugin_loyalty_id',
'label' => 'Loyalty card ID',
'type' => 'text',
'required' => false,
'help' => 'Optional — link your existing loyalty card',
);
return $fields;
},
10, 2
);
// Per-field save logic:
add_filter( 'mam_user_roles_save_addl_user_profile_field_my_plugin_loyalty_id',
function ( $value, $user_id ) {
// Validate, normalize, persist.
$clean = preg_replace( '/[^A-Z0-9]/i', '', (string) $value );
update_user_meta( $user_id, 'my_plugin_loyalty_id', $clean );
return $clean;
},
10, 2
);
Where the field appears
- Mobile app: profile-completion form, profile-edit screen
- WP admin: user edit page (under the standard profile fields), via
Mam_Admin_User_Fields
The same field schema drives both surfaces.
Gotchas
keyis the usermeta key by convention. Prefix with your plugin slug to avoid collisions.- The two-hook pattern — register the field via this filter AND register a per-field save filter via
mam_user_roles_save_addl_user_profile_field_{key}. Without the save filter, the field renders but submissions don’t persist. $user_id = 0during the signup flow — the user doesn’t exist yet. Don’t try to read existing usermeta in that path.- Required fields block submission until populated. Use sparingly — a required field on the profile-completion form prevents users from proceeding.
- Unsupported
typevalues silently render as text. Verify against the supported list above.
Related articles
- Recipe: Customize onboarding
- Hook: mam_user_roles_save_addl_user_profilefield{key}
- Hook: mam_user_roles_after_create_user
- Hook: mam_user_roles_modify_user_profile_values_before_save
Metadata
| Field | Value |
|---|---|
| Article type | Hook Reference |
| Plugin slug | mam-main |
| Applies to plugin version | 2.1.11+ |
| Hook type | filter |
| Audience | PHP developer |
| Last verified | 2026-05-02 |
