This repository was archived by the owner on Feb 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Feature: add categories system #102
Merged
galatanovidiu
merged 53 commits into
WordPress:trunk
from
galatanovidiu:feature/add-categories-system
Oct 13, 2025
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
55d75fc
Implement ability categories in the Abilities API
galatanovidiu df4af2c
Refactor ability category registration and retrieval logic
galatanovidiu b97a258
Refactor(Abilities): Change ability category from an array to a singl…
galatanovidiu 579333e
Refactor(Abilities): Update registry for single category model
galatanovidiu 8a7e62e
Refactor(Abilities): Update REST API for single category model
galatanovidiu 38a46aa
Feat(Abilities): Validate that an ability's category is registered
galatanovidiu d2ac5cc
Fix: Correct PHPDoc type hints in WP_Abilities_Category_Registry
galatanovidiu 8490c39
Refactor: Rename abilities_category_registry_init hook for consistency
galatanovidiu 59f6634
Refactor: Improve ability filtering logic
galatanovidiu 6a6b381
Chore: Add missing newlines at end of files
galatanovidiu 42c7ace
test(abilities-api): Add tests for ability categories
galatanovidiu 92a166e
test(abilities-api): Update unit tests to use ability categories
galatanovidiu 3098037
test(rest-api): Update tests to use ability categories
galatanovidiu 1bac363
test(rest-api): Add tests for category filtering and schema
galatanovidiu cd406da
docs: Document Ability Categories feature
galatanovidiu ff86ae2
docs: Update examples to use Ability Categories
galatanovidiu 2a3bf05
docs: Document Category support in REST API
galatanovidiu 9b17174
Refactor ability category registration validation
galatanovidiu 6e42f67
Refactor tests to register ability categories on the init hook
galatanovidiu 1f9e75c
Rename category registration hook
galatanovidiu b82607d
Remove ability filtering by category
galatanovidiu 110d403
Improve tests for ability category validation
galatanovidiu f8bcd0b
Merge branch 'trunk' into feature/add-categories-system
galatanovidiu 7e4e195
Fix: Correct formatting and assertions in unit tests
galatanovidiu 9de15dd
Changes the version annotations from `0.3.0` to `n.e.x.t`
galatanovidiu 7a5047b
Update version annotations from `0.3.0` to `n.e.x.t` in abilities cat…
galatanovidiu c093d32
Revert version to 0.2.0
galatanovidiu 308e62c
Removes slug sanitization for ability categories
galatanovidiu 6bde79a
test: Replace conditional checks with assertions for non-existent cat…
galatanovidiu 474dcc9
Merge branch 'trunk' into feature/add-categories-system
galatanovidiu 99a6eb8
Fix: Add missing category to show_in_rest test abilities
galatanovidiu 5b8adbb
Added a comment to the __wakeup method to clarify that unserializatio…
galatanovidiu f19f0cb
Add meta support to ability categories
galatanovidiu 2bb837d
Remove validation for ability category slug format
galatanovidiu cfe3c24
Change WP_Ability_Category class to final
galatanovidiu f3ae972
Merge branch 'trunk' into feature/add-categories-system
galatanovidiu 150461e
Fix: Correct assertion in REST API ability get_item test
galatanovidiu ebdcfb1
Refactor: Improve ability category cleanup in tests
galatanovidiu a573fd7
Chore: Fix indentation in WP_Ability class
galatanovidiu ab23e20
Docs: Move category registration to a dedicated file
galatanovidiu 56ccd79
Harden: Prevent serialization of ability and registry classes
galatanovidiu 7a66dcf
docs: clarify category registration step
galatanovidiu 88fe7a6
Update translator comment and string to specify “Ability category” fo…
galatanovidiu b96c89d
Update translator comment and string to specify “Ability category” fo…
galatanovidiu 84c77e4
Update translator comment and string to specify “Ability category” fo…
galatanovidiu aee17c8
Docs: Remove documentation for category registration filter
galatanovidiu 2e2992c
Fix PHPStan annotations for category registration
galatanovidiu be1b20e
Update tests/unit/abilities-api/wpAbilityCategory.php
galatanovidiu 990e77a
Refactor category slug tests to use @dataProvider
galatanovidiu 2414c2f
Refactor test_get_all_categories to use register_category_during_hook
galatanovidiu b724ae7
Remove 'annotations' field from abilities schema and update required …
galatanovidiu 48c3ba1
Update required fields in abilities schema to include 'input_schema' …
galatanovidiu e69d69b
Add category property tests to abilities schema validation
galatanovidiu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,61 @@ | ||||
| # 7. Registering Categories | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jonathanbossenger, we really need to remove these numbers, as I would put this one next to registering categories as it fits better there. It's another instance where this ordering causes trouble 😅 Let's also make sure to list this new document in README somwhere next to: Line 23 in 4dc57b3
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the ordering aspect to a new issue here. |
||||
|
|
||||
| Before registering abilities, you must register at least one category. Categories help organize abilities and make them easier to discover and filter. | ||||
|
|
||||
| ## Function Signature | ||||
|
|
||||
| ```php | ||||
| wp_register_ability_category( string $slug, array $args ): ?\WP_Ability_Category | ||||
| ``` | ||||
|
|
||||
| **Parameters:** | ||||
| - `$slug` (`string`): A unique identifier for the category. Must contain only lowercase alphanumeric characters and dashes (no underscores, no uppercase). | ||||
| - `$args` (`array`): Category configuration with these keys: | ||||
| - `label` (`string`, **Required**): Human-readable name for the category. Should be translatable. | ||||
| - `description` (`string`, **Required**): Detailed description of the category's purpose. Should be translatable. | ||||
| - `meta` (`array`, **Optional**): An associative array for storing arbitrary additional metadata about the category. | ||||
|
|
||||
| **Return:** (`?\WP_Ability_Category`) An instance of the registered category if it was successfully registered, `null` on failure (e.g., invalid arguments, duplicate slug). | ||||
|
|
||||
| **Note:** Categories must be registered during the `abilities_api_categories_init` action hook. | ||||
|
|
||||
| ## Code Example | ||||
|
|
||||
| ```php | ||||
| add_action( 'abilities_api_categories_init', 'my_plugin_register_categories' ); | ||||
| function my_plugin_register_categories() { | ||||
| wp_register_ability_category( 'data-retrieval', array( | ||||
| 'label' => __( 'Data Retrieval', 'my-plugin' ), | ||||
| 'description' => __( 'Abilities that retrieve and return data from the WordPress site.', 'my-plugin' ), | ||||
| )); | ||||
|
|
||||
| wp_register_ability_category( 'data-modification', array( | ||||
| 'label' => __( 'Data Modification', 'my-plugin' ), | ||||
| 'description' => __( 'Abilities that modify data on the WordPress site.', 'my-plugin' ), | ||||
| )); | ||||
|
|
||||
| wp_register_ability_category( 'communication', array( | ||||
| 'label' => __( 'Communication', 'my-plugin' ), | ||||
| 'description' => __( 'Abilities that send messages or notifications.', 'my-plugin' ), | ||||
| )); | ||||
| } | ||||
| ``` | ||||
|
|
||||
| ## Category Slug Convention | ||||
|
|
||||
| The `$slug` parameter must follow these rules: | ||||
|
|
||||
| - **Format:** Must contain only lowercase alphanumeric characters (`a-z`, `0-9`) and hyphens (`-`). | ||||
| - **Valid examples:** `data-retrieval`, `ecommerce`, `site-information`, `user-management`, `category-123` | ||||
| - **Invalid examples:** | ||||
| - Uppercase: `Data-Retrieval`, `MyCategory` | ||||
| - Underscores: `data_retrieval` | ||||
| - Special characters: `data.retrieval`, `data/retrieval`, `data retrieval` | ||||
| - Leading/trailing dashes: `-data`, `data-` | ||||
| - Double dashes: `data--retrieval` | ||||
|
|
||||
| ## Other Category Functions | ||||
galatanovidiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
|
||||
| - `wp_unregister_ability_category( string $slug )` - Remove a registered category. Returns the unregistered category instance or `null` on failure. | ||||
| - `wp_get_ability_category( string $slug )` - Retrieve a specific category by slug. Returns the category instance or `null` if not found. | ||||
| - `wp_get_ability_categories()` - Get all registered categories as an associative array keyed by slug. | ||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outside of this PR, mostly note to myself and @jonathanbossenger, we are missing
abilities_api_initcovered here. That one is fundamental 😄