2828 * +---------------------------+----------------------+----------+------------------------------------------+
2929 *
3030 * # Get details of a specific ability.
31- * $ wp ability get core/get-site-info --fields=name,label,category,readonly,show_in_rest
31+ * $ wp ability get core/get-site-info --fields=name,label,category,readonly,public, show_in_rest
3232 * +---------------+----------------------+
3333 * | Field | Value |
3434 * +---------------+----------------------+
3535 * | name | core/get-site-info |
3636 * | label | Get Site Information |
3737 * | category | site |
3838 * | readonly | 1 |
39+ * | public | 1 |
3940 * | show_in_rest | 1 |
4041 * +---------------+----------------------+
4142 *
@@ -92,6 +93,7 @@ class Ability_Command extends WP_CLI_Command {
9293 'readonly ' ,
9394 'destructive ' ,
9495 'idempotent ' ,
96+ 'public ' ,
9597 'show_in_rest ' ,
9698 ];
9799
@@ -106,8 +108,11 @@ class Ability_Command extends WP_CLI_Command {
106108 * [--namespace=<prefix>]
107109 * : Filter abilities by namespace prefix (e.g., 'core' for 'core/*' abilities).
108110 *
109- * [--show-in-rest=<bool>]
110- * : Filter abilities by REST API exposure.
111+ * [--public]
112+ * : Only list abilities flagged for client exposure. Pass --no-public to invert.
113+ *
114+ * [--show-in-rest]
115+ * : Only list abilities exposed to the REST API. Pass --no-show-in-rest to invert.
111116 *
112117 * [--field=<field>]
113118 * : Prints the value of a single field for each ability.
@@ -142,8 +147,15 @@ class Ability_Command extends WP_CLI_Command {
142147 * * readonly
143148 * * destructive
144149 * * idempotent
150+ * * public
145151 * * show_in_rest
146152 *
153+ * The `public` field reports the high-level client exposure flag as declared
154+ * by the ability. As of WordPress 7.1 it seeds the default for channel-specific
155+ * flags such as `show_in_rest`, which take precedence when set explicitly.
156+ * On earlier versions the flag is stored but has no effect, so `public` and
157+ * `show_in_rest` may disagree.
158+ *
147159 * ## EXAMPLES
148160 *
149161 * # List all abilities.
@@ -162,7 +174,13 @@ class Ability_Command extends WP_CLI_Command {
162174 * $ wp ability list --namespace=core
163175 *
164176 * # List abilities exposed to REST API.
165- * $ wp ability list --show-in-rest=true
177+ * $ wp ability list --show-in-rest
178+ *
179+ * # List abilities meant to be available to clients.
180+ * $ wp ability list --public
181+ *
182+ * # Find abilities that opt out of REST despite being public.
183+ * $ wp ability list --public --no-show-in-rest
166184 *
167185 * # List abilities as JSON.
168186 * $ wp ability list --format=json
@@ -182,6 +200,7 @@ public function list_( $args, $assoc_args ): void {
182200 $ abilities = wp_get_abilities ();
183201 $ category_slug = Utils \get_flag_value ( $ assoc_args , 'category ' );
184202 $ namespace = Utils \get_flag_value ( $ assoc_args , 'namespace ' );
203+ $ public = Utils \get_flag_value ( $ assoc_args , 'public ' );
185204 $ show_in_rest = Utils \get_flag_value ( $ assoc_args , 'show-in-rest ' );
186205
187206 $ items = [];
@@ -203,11 +222,18 @@ public function list_( $args, $assoc_args ): void {
203222 }
204223 }
205224
225+ // Filter by public if specified.
226+ if ( null !== $ public ) {
227+ $ ability_public = '1 ' === $ ability_data ['public ' ];
228+ if ( $ public !== $ ability_public ) {
229+ continue ;
230+ }
231+ }
232+
206233 // Filter by show_in_rest if specified.
207234 if ( null !== $ show_in_rest ) {
208- $ show_in_rest_bool = filter_var ( $ show_in_rest , FILTER_VALIDATE_BOOLEAN , FILTER_NULL_ON_FAILURE );
209- $ ability_rest = '1 ' === $ ability_data ['show_in_rest ' ];
210- if ( null !== $ show_in_rest_bool && $ show_in_rest_bool !== $ ability_rest ) {
235+ $ ability_rest = '1 ' === $ ability_data ['show_in_rest ' ];
236+ if ( $ show_in_rest !== $ ability_rest ) {
211237 continue ;
212238 }
213239 }
@@ -246,6 +272,8 @@ public function list_( $args, $assoc_args ): void {
246272 *
247273 * ## AVAILABLE FIELDS
248274 *
275+ * These fields will be displayed by default:
276+ *
249277 * * name
250278 * * label
251279 * * category
@@ -255,8 +283,22 @@ public function list_( $args, $assoc_args ): void {
255283 * * readonly
256284 * * destructive
257285 * * idempotent
286+ * * public
258287 * * show_in_rest
259288 *
289+ * These fields are optionally available:
290+ *
291+ * * meta
292+ *
293+ * The `public` field reports the high-level client exposure flag as declared
294+ * by the ability. As of WordPress 7.1 it seeds the default for channel-specific
295+ * flags such as `show_in_rest`, which take precedence when set explicitly.
296+ * On earlier versions the flag is stored but has no effect, so `public` and
297+ * `show_in_rest` may disagree.
298+ *
299+ * The `meta` field renders the raw metadata as JSON. It is the only way to
300+ * inspect channel-specific settings registered by plugins, such as `mcp`.
301+ *
260302 * ## EXAMPLES
261303 *
262304 * # Get details of a specific ability.
@@ -273,9 +315,14 @@ public function list_( $args, $assoc_args ): void {
273315 * | readonly | 1 |
274316 * | destructive | 0 |
275317 * | idempotent | 1 |
318+ * | public | 1 |
276319 * | show_in_rest | 1 |
277320 * +---------------+----------------------+
278321 *
322+ * # Inspect channel-specific settings that have no field of their own.
323+ * $ wp ability get my-plugin/my-ability --field=meta
324+ * {"annotations":{"readonly":true,"destructive":false,"idempotent":null},"mcp":{"public":false},"show_in_rest":true,"public":true}
325+ *
279326 * # Get ability as JSON.
280327 * $ wp ability get core/get-site-info --format=json
281328 *
@@ -650,6 +697,7 @@ private function format_ability_for_list( $ability ) {
650697 'readonly ' => $ this ->format_annotation ( $ annotations ['readonly ' ] ),
651698 'destructive ' => $ this ->format_annotation ( $ annotations ['destructive ' ] ),
652699 'idempotent ' => $ this ->format_annotation ( $ annotations ['idempotent ' ] ),
700+ 'public ' => $ ability ->get_meta_item ( 'public ' , false ) ? '1 ' : '0 ' ,
653701 'show_in_rest ' => $ ability ->get_meta_item ( 'show_in_rest ' , false ) ? '1 ' : '0 ' ,
654702 ];
655703 }
@@ -662,6 +710,7 @@ private function format_ability_for_list( $ability ) {
662710 */
663711 private function format_ability_for_get ( $ ability ) {
664712 $ annotations = $ this ->get_annotations ( $ ability );
713+ $ meta = $ ability ->get_meta ();
665714
666715 return [
667716 'name ' => $ ability ->get_name (),
@@ -673,7 +722,9 @@ private function format_ability_for_get( $ability ) {
673722 'readonly ' => $ this ->format_annotation ( $ annotations ['readonly ' ] ),
674723 'destructive ' => $ this ->format_annotation ( $ annotations ['destructive ' ] ),
675724 'idempotent ' => $ this ->format_annotation ( $ annotations ['idempotent ' ] ),
725+ 'public ' => $ ability ->get_meta_item ( 'public ' , false ) ? '1 ' : '0 ' ,
676726 'show_in_rest ' => $ ability ->get_meta_item ( 'show_in_rest ' , false ) ? '1 ' : '0 ' ,
727+ 'meta ' => ! empty ( $ meta ) ? wp_json_encode ( $ meta ) : '{} ' ,
677728 ];
678729 }
679730
0 commit comments