Skip to content

docs: document required category field for abilities#224

Merged
galatanovidiu merged 3 commits into
trunkfrom
docs/abilities-category-requirement
Jul 9, 2026
Merged

docs: document required category field for abilities#224
galatanovidiu merged 3 commits into
trunkfrom
docs/abilities-category-requirement

Conversation

@galatanovidiu

Copy link
Copy Markdown
Contributor

What?

Closes #135

Documents the required category field for WordPress abilities across the docs, and clarifies what actually happens when it's missing.

Why?

In #135, wp_register_ability() returned NULL for a user and they couldn't tell why. They suspected a load-order conflict with WooCommerce's bundled Abilities API. It wasn't that.

The real cause: core requires a category, and every registration example in our docs omitted it. So copy-pasting our docs reproduced the failure. @justlevine flagged this as a recurring DX/docs stumbling block, which is what this PR addresses.

I verified the behavior against WordPress 6.9 core source (wp-includes/abilities.php, default-filters.php) rather than trusting the issue thread:

  • category is required.
  • Core registers exactly two default categories: site and user (via wp_register_core_ability_categories(), hooked on wp_abilities_api_categories_init). No plugin code needed to use them.
  • On a missing or unregistered category, wp_register_ability() returns null with no WP_Error, but does call _doing_it_wrong(). That notice only surfaces with WP_DEBUG on, so on production it looks completely silent. That's why it's so easy to misdiagnose.

How?

  • Added 'category' to every ability-registration example across the docs (site, or user for the user-data resource example).
  • Added a dedicated "Ability categories (required)" section in creating-abilities.md covering the core defaults, registering a custom category with wp_register_ability_category(), and the wp_abilities_api_categories_init vs wp_abilities_api_init hook ordering.
  • Added a top callout in basic-examples.md.
  • Added a troubleshooting entry in common-issues.md for the null return, including the tip to enable WP_DEBUG and check the log for Ability category "..." is not registered.
  • Worded the failure accurately: returns null, no WP_Error, _doing_it_wrong() notice only with WP_DEBUG on (not truly "silent").

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Drafting the doc edits and verifying the core-behavior claims (default categories, null-on-failure path) against WordPress core source. All claims were checked against wordpress-develop 6.9/trunk and reviewed and edited by me.

Testing Instructions

Docs-only change, no code paths touched.

  1. Rendered-docs check: confirm the new "Ability categories (required)" section renders and the cross-links from basic-examples.md and common-issues.md resolve to it.
  2. (Optional) Confirm the documented behavior on a WP 6.9 site:
    # Without a category -> registration fails (returns null)
    wp eval 'var_dump( wp_register_ability( "demo/x", [ "label"=>"X", "description"=>"d", "execute_callback"=>"__return_true", "permission_callback"=>"__return_true" ] ) );'
    
    # With a core category -> registers
    wp eval 'var_dump( (bool) wp_register_ability( "demo/y", [ "label"=>"Y", "description"=>"d", "category"=>"site", "execute_callback"=>"__return_true", "permission_callback"=>"__return_true" ] ) );'

Changelog Entry

Developer - Documented the required category field for abilities, the core site/user categories, registering custom categories, and the null-on-missing-category failure mode.

`wp_register_ability()` requires a `category` and returns `null` silently
when it is missing or unregistered (issue #135). Every doc example omitted
the field, so copy-pasting them reproduced the failure.

Add the field to all registration examples, add a dedicated "Ability
categories (required)" section covering core categories and the
`wp_abilities_api_categories_init` hook, and add a troubleshooting entry
for the silent `null` return.
Copilot AI review requested due to automatic review settings June 26, 2026 10:45
@github-actions

github-actions Bot commented Jun 26, 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: @flodufour, @stefanolissa, @gelakhubutia.

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

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: flodufour, stefanolissa, gelakhubutia.

Co-authored-by: galatanovidiu <ovidiu-galatan@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: karthikeya-io <karthikeya01@git.wordpress.org>
Co-authored-by: mathetos <webdevmattcrom@git.wordpress.org>
Co-authored-by: justlevine <justlevine@git.wordpress.org>

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the documentation to reflect that wp_register_ability() requires a registered category, and explains the observed failure mode when category is missing/unregistered (returning null with only a _doing_it_wrong() notice in debug).

Changes:

  • Adds an “Ability categories (required)” section explaining core site/user categories and how to register custom categories on wp_abilities_api_categories_init.
  • Updates ability-registration examples across docs to include a category field (site or user as appropriate).
  • Adds a callout and troubleshooting guidance for the null return behavior when category is missing/unregistered.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
docs/troubleshooting/common-issues.md Adds a troubleshooting entry for wp_register_ability() returning null due to missing/unregistered category.
docs/guides/default-server.md Updates the default server example ability registration to include category.
docs/guides/creating-abilities.md Adds a new “Ability categories (required)” section and updates examples to include category.
docs/getting-started/README.md Updates the getting-started example to include category.
docs/getting-started/installation.md Updates the installation tutorial’s registration snippet to include category.
docs/getting-started/basic-examples.md Adds a top-level callout about required categories and updates examples to include category.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/troubleshooting/common-issues.md Outdated
Comment thread docs/getting-started/basic-examples.md
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.86%. Comparing base (90252e7) to head (f32c7c0).

Additional details and impacted files
@@            Coverage Diff            @@
##              trunk     #224   +/-   ##
=========================================
  Coverage     87.86%   87.86%           
  Complexity     1245     1245           
=========================================
  Files            53       53           
  Lines          4037     4037           
=========================================
  Hits           3547     3547           
  Misses          490      490           
Flag Coverage Δ
unit 87.86% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Clarify that WP_DEBUG_LOG (not just WP_DEBUG) is needed to capture the
_doing_it_wrong() notice in debug.log. Mark the partial edit-post snippet
in transport-permissions.md as incomplete and name the required fields,
so it isn't copy-pasted into the same null failure.

@gziolo gziolo left a comment

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.

This is an accurate, well-scoped docs fix.

@galatanovidiu galatanovidiu merged commit 1882eba into trunk Jul 9, 2026
29 of 31 checks passed
@galatanovidiu galatanovidiu deleted the docs/abilities-category-requirement branch July 9, 2026 08:09
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.

wp_register_ability returns NULL when called from plugin during wp_abilities_api_init

3 participants