Skip to content

Docs: Describe the shape of post type, taxonomy and capability data - #13220

Open
swissspidy wants to merge 1 commit into
WordPress:trunkfrom
swissspidy:claude/phpstan-wordpress-typing-f9zirv
Open

Docs: Describe the shape of post type, taxonomy and capability data#13220
swissspidy wants to merge 1 commit into
WordPress:trunkfrom
swissspidy:claude/phpstan-wordpress-typing-f9zirv

Conversation

@swissspidy

@swissspidy swissspidy commented Aug 21, 2026

Copy link
Copy Markdown
Member

Documents the types of several values that are currently only described as array, stdClass or bool[], so their contents are visible both to anyone reading the docs and to static analysis. Docblock changes only, no behavior change.

Three of these look like genuine documentation bugs rather than gaps:

  • get_taxonomy_labels() omits two labels its object always carries. _get_custom_object_labels() always sets name_admin_bar, and both label builders add menu_name to the defaults before merging. Core itself reads $taxonomy->labels->menu_name in wp-admin/menu.php. get_post_type_labels() documents menu_name, but not name_admin_bar, and not template_name either, which its own @since 6.6.0 line mentions.
  • Labels that can be null are documented as string. WP_Post_Type::get_default_labels() and WP_Taxonomy::get_default_labels() are both typed (string|null)[][], and for eight taxonomy labels and one post type label the default really is null for one of the two hierarchies: popular_items on a hierarchical taxonomy, parent_item_colon on a non-hierarchical post type, and so on. Those become string|null.
  • get_registered_settings() omits the group key. register_setting() always stores it through its defaults. The same docblock, and register_setting() itself, describe sanitize_callback as callable when its default is null.

Alongside those:

  • get_post_type_labels() describes its return value with the same hash notation get_taxonomy_labels() already uses, instead of a prose list, so the two read alike.
  • WP_Taxonomy::$cap lists the four capabilities it holds, mirroring the capabilities argument of register_taxonomy(). WP_Post_Type::$cap gains a @see get_post_type_capabilities(), where its own list already lives.
  • WP_User::$caps, WP_User::$allcaps and WP_Role::$capabilities are keyed by capability name, so array<string, bool> rather than bool[].

Verified with composer phpstan, at the configured level 5 with the existing baselines and reportUnmatchedIgnoredErrors: true: no new errors, and no baseline drift.

Trac ticket: https://core.trac.wordpress.org/ticket/65817

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Used for: comparing the existing docblocks against the code that builds these objects, and drafting the documentation changes in this pull request.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Documents the types of several values that are currently only described as
`array`, `stdClass` or `bool[]`, so static analysis can see their contents:

- `get_post_type_labels()` returns its labels in the hash notation already used
  by `get_taxonomy_labels()`, instead of a prose list. Two labels the returned
  object always carries were missing from that list: `name_admin_bar`, always
  set by `_get_custom_object_labels()`, and `template_name`, added in 6.6.0.
- `get_taxonomy_labels()` gains the same two, `menu_name` and `name_admin_bar`,
  which are always present but were never documented. Core reads `menu_name`
  off a taxonomy in `wp-admin/menu.php`.
- Labels whose default is `null` for one of the two hierarchies, as recorded in
  `WP_Post_Type::get_default_labels()` and `WP_Taxonomy::get_default_labels()`,
  are documented as `string|null` rather than `string`.
- `WP_Taxonomy::$cap` lists the four capabilities it holds, mirroring the
  `capabilities` argument of `register_taxonomy()`, and `WP_Post_Type::$cap`
  points at `get_post_type_capabilities()`, where its own list already lives.
- `WP_User::$caps`, `WP_User::$allcaps` and `WP_Role::$capabilities` are keyed
  by capability name, so `array<string, bool>` rather than `bool[]`.
- `register_setting()` and `get_registered_settings()` document
  `sanitize_callback` as `callable|null`, which is its default, and the latter
  adds the `group` key that `register_setting()` always stores.

Docblock changes only, no behavior change.

Refs szepeviktor/phpstan-wordpress#274

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0122HqysjDiq2jSHebbSSu6A
@github-actions

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.

@swissspidy
swissspidy marked this pull request as ready for review August 21, 2026 10:40
Copilot AI lite review requested due to automatic review settings August 21, 2026 10:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @claude.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

Core Committers: Use this line as a base for the props when committing in SVN:

Props westonruter, swissspidy.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@swissspidy
swissspidy requested a review from westonruter August 21, 2026 10:43
* @since 4.6.0
* @var stdClass $cap
*/
public $cap;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really want to figure out a way to type this.

* @type string $edit_terms Capability to edit terms. Default 'manage_categories'.
* @type string $delete_terms Capability to delete terms. Default 'manage_categories'.
* @type string $assign_terms Capability to assign terms. Default 'edit_posts'.
* }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add the PHPStan type as well, as otherwise this cannot help with static analysis.

@westonruter

Copy link
Copy Markdown
Member

Correcting the WP dev docs is good, but what would be greater is adding the PHPStan types. Or, I wonder if we could add an extension that would teach PHPStan how to interpret the WordPress flavor of phpdoc.

@swissspidy

Copy link
Copy Markdown
Member Author

Good point. To a degree it's possible. Normally the WP flavor is transformed into PHPStan types in the wordpress-stubs project, that's how I use it. But adding PHPStan types directly would help both internally and externally. And an extension could be reusable too and help reduce docs duplication.

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.

4 participants