Make WordPress Core

Opened 3 weeks ago

Closed 11 days ago

Last modified 11 days ago

#65234 closed enhancement (fixed)

Abilities API: Expand `core/get-user-info` with profile fields and filtering

Reported by: gziolo's profile gziolo Owned by: gziolo's profile gziolo
Milestone: 7.1 Priority: normal
Severity: normal Version: 6.9
Component: Abilities API Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Two additive changes to core/get-user-info (shipped in 6.9):

  1. Expand the response with five standard profile fields: first_name, last_name, nickname, description, user_url.
  2. Add an optional fields input parameter that filters the response to a subset of properties, mirroring the pattern already used by core/get-site-info.

Field naming follows WP-CLI conventions: wp_users columns keep their user_ prefix (user_url); user-meta fields are unprefixed (first_name, last_name, nickname, description).

Proposed shape

Default response (no fields parameter) after the change:

{
  "id": 1,
  "display_name": "Jane Doe",
  "user_nicename": "jane-doe",
  "user_login": "jane",
  "roles": ["administrator"],
  "locale": "en_US",
  "first_name": "Jane",
  "last_name": "Doe",
  "nickname": "Jane",
  "description": "Site administrator and contributor.",
  "user_url": "https://example.com"
}

Filtered response with fields: ["display_name", "first_name", "last_name"]:

{
  "display_name": "Jane Doe",
  "first_name": "Jane",
  "last_name": "Doe"
}

Behavioral rules

  • Included by default, opt-out via fields. Omitting fields returns all properties, matching core/get-site-info. Passing fields: ["display_name"] filters down to just that property.
  • Schema-validated field names. Each entry in fields must be one of the declared output properties; invalid names are rejected by JSON Schema enum validation.
  • Capability check unchanged: is_user_logged_in().
  • Annotations unchanged: readonly: true, destructive: false, idempotent: true.

Acceptance criteria

  • core/get-user-info returns the five additional fields (first_name, last_name, nickname, description, user_url) alongside the existing 6.9 fields.
  • core/get-user-info accepts an optional fields input parameter that filters the response to the requested subset.
  • When fields is omitted, the response includes all properties.
  • Invalid field names in fields are rejected via schema validation before execution.
  • JSON Schema documents each new field with title and description so adapters (MCP, WebMCP) can surface them.
  • Unit test coverage in tests/phpunit/tests/abilities-api/ for: expanded read output, fields filtering with valid subset, schema rejection of invalid field names, and unauthenticated denial.

Change History (5)

#1 @gziolo
3 weeks ago

  • Owner set to gziolo

This ticket was mentioned in PR #11830 on WordPress/wordpress-develop by @sukhendu2002.


3 weeks ago
#2

  • Keywords has-patch added

#3 @gziolo
11 days ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 62419:

Abilities API: Expand core/get-user-info with profile fields

Extends the core/get-user-info ability with additional profile fields (first_name, last_name, nickname, description, user_url) and a new optional fields input parameter that lets callers limit the response to a specific subset.

The output schema now documents each property with a title and description, mirroring the user profile form labels where they apply and aligning the descriptions with the WP REST API user schema voice.

Also ensures roles is encoded as a JSON array regardless of the underlying PHP array keys.

Props sukhendu2002, apermo, gziolo.
Fixes #65234.

This ticket was mentioned in Slack in #core-ai by gziolo. View the logs.


11 days ago

#5 @gziolo
11 days ago

  • Keywords has-unit-tests added
Note: See TracTickets for help on using tickets.