@@ -4,11 +4,11 @@ Client library for the WordPress Abilities API, providing a standardized way to
4
4
5
5
## Table of Contents
6
6
7
- - [ Installation] ( #installation )
8
- - [ Usage] ( #usage )
9
- - [ API Reference] ( #api-reference )
10
- - [ Development] ( #development )
11
- - [ Testing] ( #testing )
7
+ - [ Installation] ( #installation )
8
+ - [ Usage] ( #usage )
9
+ - [ API Reference] ( #api-reference )
10
+ - [ Development] ( #development )
11
+ - [ Testing] ( #testing )
12
12
13
13
## Installation
14
14
@@ -67,13 +67,13 @@ const { listAbilities, getAbility, executeAbility } = wp.abilities;
67
67
const abilities = await listAbilities ();
68
68
69
69
// Get a specific ability
70
- const ability = await getAbility ( ' my-plugin/my-ability' );
70
+ const ability = await getAbility (' my-plugin/my-ability' );
71
71
72
72
// Execute an ability
73
- const result = await executeAbility ( ' my-plugin/my-ability' , {
74
- param1: ' value1' ,
75
- param2: ' value2'
76
- } );
73
+ const result = await executeAbility (' my-plugin/my-ability' , {
74
+ param1: ' value1' ,
75
+ param2: ' value2' ,
76
+ });
77
77
```
78
78
79
79
### Using with React and WordPress Data
@@ -85,28 +85,28 @@ import { useSelect } from '@wordpress/data';
85
85
import { store as abilitiesStore } from ' @wordpress/abilities' ;
86
86
87
87
function MyComponent () {
88
- const abilities = useSelect (
89
- ( select ) => select ( abilitiesStore ).getAbilities (),
90
- []
91
- );
92
-
93
- const specificAbility = useSelect (
94
- ( select ) => select ( abilitiesStore ).getAbility ( ' my-plugin/my-ability' ),
95
- []
96
- );
97
-
98
- return (
99
- < div>
100
- < h2> All Abilities< / h2>
101
- < ul>
102
- { abilities .map ( ( ability ) => (
103
- < li key= { ability .name }>
104
- < strong> { ability .label }< / strong> : { ability .description }
105
- < / li>
106
- ) ) }
107
- < / ul>
108
- < / div>
109
- );
88
+ const abilities = useSelect (
89
+ ( select ) => select (abilitiesStore).getAbilities (),
90
+ []
91
+ );
92
+
93
+ const specificAbility = useSelect (
94
+ ( select ) => select (abilitiesStore).getAbility (' my-plugin/my-ability' ),
95
+ []
96
+ );
97
+
98
+ return (
99
+ < div>
100
+ < h2> All Abilities< / h2>
101
+ < ul>
102
+ { abilities .map (( ability ) => (
103
+ < li key= {ability .name }>
104
+ < strong> {ability .label }< / strong> : {ability .description }
105
+ < / li>
106
+ )) }
107
+ < / ul>
108
+ < / div>
109
+ );
110
110
}
111
111
```
112
112
@@ -120,46 +120,46 @@ Returns all registered abilities. Automatically handles pagination to fetch all
120
120
121
121
``` javascript
122
122
const abilities = await listAbilities ();
123
- console .log ( ` Found ${ abilities .length } abilities` );
123
+ console .log (` Found ${ abilities .length } abilities` );
124
124
```
125
125
126
126
#### ` getAbility(name: string): Promise<Ability | null> `
127
127
128
128
Returns a specific ability by name, or null if not found.
129
129
130
130
``` javascript
131
- const ability = await getAbility ( ' my-plugin/create-post' );
132
- if ( ability ) {
133
- console .log ( ` Found ability: ${ ability .label } ` );
131
+ const ability = await getAbility (' my-plugin/create-post' );
132
+ if (ability) {
133
+ console .log (` Found ability: ${ ability .label } ` );
134
134
}
135
135
```
136
136
137
137
#### ` executeAbility(name: string, input?: Record<string, any>): Promise<any> `
138
138
139
139
Executes an ability with optional input parameters. The HTTP method is automatically determined based on the ability's type:
140
140
141
- - ` resource ` type abilities use GET (read-only operations)
142
- - ` tool ` type abilities use POST (write operations)
141
+ - ` resource ` type abilities use GET (read-only operations)
142
+ - ` tool ` type abilities use POST (write operations)
143
143
144
144
``` javascript
145
145
// Execute a resource ability (GET)
146
- const data = await executeAbility ( ' my-plugin/get-data' , {
147
- id: 123
148
- } );
146
+ const data = await executeAbility (' my-plugin/get-data' , {
147
+ id: 123 ,
148
+ });
149
149
150
150
// Execute a tool ability (POST)
151
- const result = await executeAbility ( ' my-plugin/create-item' , {
152
- title: ' New Item' ,
153
- content: ' Item content'
154
- } );
151
+ const result = await executeAbility (' my-plugin/create-item' , {
152
+ title: ' New Item' ,
153
+ content: ' Item content' ,
154
+ });
155
155
```
156
156
157
157
### Store Selectors
158
158
159
159
When using with ` @wordpress/data ` :
160
160
161
- - ` getAbilities() ` - Returns all abilities from the store
162
- - ` getAbility(name) ` - Returns a specific ability from the store
161
+ - ` getAbilities() ` - Returns all abilities from the store
162
+ - ` getAbility(name) ` - Returns a specific ability from the store
163
163
164
164
## Development
165
165
@@ -201,7 +201,7 @@ npm run test:unit:debug
201
201
202
202
Tests are organized following WordPress conventions:
203
203
204
- - Unit tests are located in ` src/__tests__/ `
205
- - Store tests are located in ` src/store/__tests__/ `
206
- - Test files use ` .test.ts ` or ` .test.js ` extension
207
- - Tests use Jest with ` @wordpress/jest-preset-default ` configuration
204
+ - Unit tests are located in ` src/__tests__/ `
205
+ - Store tests are located in ` src/store/__tests__/ `
206
+ - Test files use ` .test.ts ` or ` .test.js ` extension
207
+ - Tests use Jest with ` @wordpress/jest-preset-default ` configuration
0 commit comments