Ability for creating or updating the custom field configuration shown on user profile pages.
native-custom-fields/save-user-meta-fields
Creates or updates the custom field configuration displayed on the user profile and edit pages. The configuration applies globally to all users — it is not per-user.
Input Schema
{
"type": "object",
"required": ["sections"]
}
Top-level Properties
| Property | Required | Type | Description |
|---|---|---|---|
sections | Yes | array | Field sections to display on the user profile/edit page |
Section Schema
{
"type": "object",
"required": ["section_name", "section_title"]
}
| Property | Required | Type | Default | Description |
|---|---|---|---|---|
section_name | Yes | string | — | Unique slug for the section |
section_title | Yes | string | — | Section title displayed on the user profile page |
section_icon | No | string | "" | Dashicon name without the dashicons- prefix (e.g. "admin-users") |
fields | No | array | [] | Fields inside this section (see field-schema.md) |
Output Schema
{
"status": true,
"message": "..."
}
| Field | Type | Description |
|---|---|---|
status | boolean | true on success, false on failure |
message | string | Result description or error message |
Internal Behaviour
section_nameis sanitized withsanitize_key().section_titleis sanitized withsanitize_text_field().- Builder slug is fixed:
native_custom_fields_user_meta_fields_builder_all_users - On success, the same values are also stored via
OptionService::saveOptions(). - Field values are stored at runtime in the
wp_usermetatable using the fieldnameas the meta key. - Sections are internally tagged with
fieldType: "section"before being passed toUserMetaService::saveUserMetaFieldsConfig().
Example
{
"sections": [
{
"section_name": "personal_info",
"section_title": "Personal Information",
"section_icon": "admin-users",
"fields": [
{
"fieldType": "text",
"name": "title",
"fieldLabel": "Title",
"field_custom_info": {
"placeholder": "Dr., Prof., etc."
}
},
{
"fieldType": "text",
"name": "phone",
"fieldLabel": "Phone Number"
},
{
"fieldType": "select",
"name": "department",
"fieldLabel": "Department",
"field_custom_info": {
"options": "Engineering:engineering, Design:design, Marketing:marketing, HR:hr"
}
}
]
},
{
"section_name": "social_media",
"section_title": "Social Media",
"section_icon": "share",
"fields": [
{
"fieldType": "input",
"name": "linkedin_url",
"fieldLabel": "LinkedIn Profile",
"field_custom_info": {
"type": "url",
"placeholder": "https://linkedin.com/in/..."
}
},
{
"fieldType": "input",
"name": "github_url",
"fieldLabel": "GitHub Profile",
"field_custom_info": {
"type": "url",
"placeholder": "https://github.com/..."
}
}
]
}
]
}
Success Response
{
"status": true,
"message": "User meta fields saved successfully."
}
Error Response
{ "status": false, "message": "sections is required." }
Accessing Saved Data
Field values saved to user meta are retrieved using the native WordPress function:
$title = get_user_meta( $user_id, 'title', true );
$department = get_user_meta( $user_id, 'department', true );
Permission
Requires the manage_options WordPress capability.
Related
- Field Schema — Shared schema for field definitions