Skip to content

REST API: Add missing _links relations to endpoint responses - #14122

Draft
johnbillion wants to merge 3 commits into
WordPress:trunkfrom
johnbillion:rest-api-missing-links
Draft

johnbillion wants to merge 3 commits into
WordPress:trunkfrom
johnbillion:rest-api-missing-links

Conversation

@johnbillion

@johnbillion johnbillion commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Several REST API responses expose related resource identifiers without links to those resources, or omit basic self and collection links. This adds the missing relationships so clients can discover the corresponding endpoints without constructing URLs themselves.

Changes

  • Revisions and autosaves: add missing self, collection, parent, and author links as appropriate. Autosaves use their own routes. Make $parent_base protected where inherited link builders need it, with PHPStan baseline entries for template controllers that prepare links from WP_Block_Template objects.
  • Post types and taxonomies: add self and links between the descriptions of related REST-visible objects. Post types use wp:taxonomy with a taxonomy attribute; taxonomies use the new wp:post-type relation with a post_type attribute. The existing wp:post_type relation continues to identify filtered post collections on terms and users.
  • Post statuses and plugins: add missing self and/or collection links.
  • Application passwords: add collection and up to the owning user. User responses advertise wp:application-passwords only when application passwords are available for that user and the viewer can list_app_passwords for them.
  • Users: add wp:post_type links to author-filtered collections for REST-visible post types served by the posts controller and supporting authors.
  • Posts and templates: advertise wp:autosaves when a supported autosave controller exists and the viewer can edit the parent. Template links require a database-backed template. Posts build autosave URLs from the registered namespace, REST base, and ID, independently of filters on the post's self route.
  • Themes: add up for installed parent themes. Active themes advertise wp:theme-global-styles and wp:theme-style-variations; inactive themes do not advertise these active-theme-only endpoints.
  • Global styles and templates: global styles gain predecessor-version and wp:theme; templates gain author and links to installed themes. Theme-global-styles responses also link to their theme and style variations.
  • Icons and icon collections: add missing self, collection, up, and wp:items links.
  • Font faces and font families: add about.
  • Menu items: add up to the parent menu item stored in meta.
  • Hierarchical terms and posts: add children.
  • Abilities: add up to the category. Use the full https://api.w.org/action-run relation URI so it compacts and emits curies consistently.
  • Widgets: remove the trailing slash from the wp:sidebar URL.

The new WordPress-specific relations are URI extension relations under https://api.w.org/, compacted to wp: in responses. Their names and meanings are proposed API vocabulary for review.

For backward compatibility, retain the bare abilities relation on ability categories and the existing up/parent split between controllers.

Validation

  • Add or extend tests for relationships, identifier attributes, permission and visibility restrictions, active-theme restrictions, file-backed templates, and filtered post routes.
  • Regenerate wp-api-generated.js. Pin application-password availability and normalize autosave URLs to keep fixtures stable between runs.
  • Affected REST controller suites and subsequent regression checks pass locally. PHPStan, PHPCS, and git diff --check also pass.

Trac ticket: none yet.

Audits every REST controller for the standard link relations and adds the ones that were missing:

* Revisions: `self`, `collection`, and `author`; autosaves point these at the autosaves routes. Template revisions and autosaves gain `collection`. Global styles revisions gain `self`, `collection`, `parent`, and `author`.
* Post types and taxonomies: `self`. Post statuses: `self` and `collection`. Plugins: `collection`.
* Application passwords: `collection` and `up` to the owning user.
* Icons: `self`, `collection`, and `up` to the icon collection. Icon collections: `self`, `collection`, and `wp:items`.
* Global styles: `predecessor-version` and `wp:theme`. Templates: `author`. Font faces and font families: `about`.
* Menu items: `up` to the parent menu item, which lives in meta rather than `post_parent`.
* Terms in hierarchical taxonomies and posts in hierarchical post types: `children`.
* Users: `wp:application-passwords` and `wp:post_type`.
* Abilities: `up` to the category, and `wp:action-run` now uses the full `https://api.w.org/` URI so it compacts and emits `curies` like every other custom relation.
* Widgets: remove the trailing slash from the `wp:sidebar` href.

The `$parent_base` property on the revisions controllers is now protected so the inherited link builder sees the subclass value.
@johnbillion
johnbillion force-pushed the rest-api-missing-links branch from 1be0216 to c2590f5 Compare October 8, 2026 20:48
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant