-
Notifications
You must be signed in to change notification settings - Fork 47
Feature: add categories system #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 47 commits
55d75fc
df4af2c
b97a258
579333e
8a7e62e
38a46aa
d2ac5cc
8490c39
59f6634
6a6b381
42c7ace
92a166e
3098037
1bac363
cd406da
ff86ae2
2a3bf05
9b17174
6e42f67
1f9e75c
b82607d
110d403
f8bcd0b
7e4e195
9de15dd
7a5047b
c093d32
308e62c
6bde79a
474dcc9
99a6eb8
5b8adbb
f19f0cb
2bb837d
cfe3c24
f3ae972
150461e
ebdcfb1
a573fd7
ab23e20
56ccd79
7a66dcf
88fe7a6
b96c89d
84c77e4
aee17c8
2e2992c
be1b20e
990e77a
2414c2f
b724ae7
48c3ba1
e69d69b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||||
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 😄