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,6 +108,9 @@ class Ability_Command extends WP_CLI_Command {
106108 * [--namespace=<prefix>]
107109 * : Filter abilities by namespace prefix (e.g., 'core' for 'core/*' abilities).
108110 *
111+ * [--public=<bool>]
112+ * : Filter abilities by the high-level client exposure flag.
113+ *
109114 * [--show-in-rest=<bool>]
110115 * : Filter abilities by REST API exposure.
111116 *
@@ -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.
@@ -164,6 +176,12 @@ class Ability_Command extends WP_CLI_Command {
164176 * # List abilities exposed to REST API.
165177 * $ wp ability list --show-in-rest=true
166178 *
179+ * # List abilities meant to be available to clients.
180+ * $ wp ability list --public=true
181+ *
182+ * # Find abilities that opt out of REST despite being public.
183+ * $ wp ability list --public=true --show-in-rest=false
184+ *
167185 * # List abilities as JSON.
168186 * $ wp ability list --format=json
169187 *
@@ -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 = $ this ->parse_bool_filter ( $ assoc_args , 'public ' );
185204 $ show_in_rest = $ this ->parse_bool_filter ( $ assoc_args , 'show-in-rest ' );
186205
187206 $ items = [];
@@ -203,6 +222,14 @@ 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 ) {
208235 $ ability_rest = '1 ' === $ ability_data ['show_in_rest ' ];
@@ -214,6 +241,8 @@ public function list_( $args, $assoc_args ): void {
214241 $ items [] = $ ability_data ;
215242 }
216243
244+ $ this ->maybe_debug_inert_public_flag ( $ items );
245+
217246 $ formatter = $ this ->get_formatter ( $ assoc_args , $ this ->default_fields );
218247 $ formatter ->display_items ( $ items );
219248 }
@@ -245,6 +274,8 @@ public function list_( $args, $assoc_args ): void {
245274 *
246275 * ## AVAILABLE FIELDS
247276 *
277+ * These fields will be displayed by default:
278+ *
248279 * * name
249280 * * label
250281 * * category
@@ -254,8 +285,22 @@ public function list_( $args, $assoc_args ): void {
254285 * * readonly
255286 * * destructive
256287 * * idempotent
288+ * * public
257289 * * show_in_rest
258290 *
291+ * These fields are optionally available:
292+ *
293+ * * meta
294+ *
295+ * The `public` field reports the high-level client exposure flag as declared
296+ * by the ability. As of WordPress 7.1 it seeds the default for channel-specific
297+ * flags such as `show_in_rest`, which take precedence when set explicitly.
298+ * On earlier versions the flag is stored but has no effect, so `public` and
299+ * `show_in_rest` may disagree.
300+ *
301+ * The `meta` field renders the raw metadata as JSON. It is the only way to
302+ * inspect channel-specific settings registered by plugins, such as `mcp`.
303+ *
259304 * ## EXAMPLES
260305 *
261306 * # Get details of a specific ability.
@@ -272,9 +317,14 @@ public function list_( $args, $assoc_args ): void {
272317 * | readonly | 1 |
273318 * | destructive | 0 |
274319 * | idempotent | 1 |
320+ * | public | 1 |
275321 * | show_in_rest | 1 |
276322 * +---------------+----------------------+
277323 *
324+ * # Inspect channel-specific settings that have no field of their own.
325+ * $ wp ability get my-plugin/my-ability --field=meta
326+ * {"annotations":{"readonly":true,"destructive":false,"idempotent":null},"mcp":{"public":false},"show_in_rest":true,"public":true}
327+ *
278328 * # Get ability as JSON.
279329 * $ wp ability get core/get-site-info --format=json
280330 *
@@ -295,6 +345,8 @@ public function get( $args, $assoc_args ): void {
295345
296346 $ ability_data = $ this ->format_ability_for_get ( $ ability );
297347
348+ $ this ->maybe_debug_inert_public_flag ( [ $ ability_data ] );
349+
298350 $ formatter = $ this ->get_formatter ( $ assoc_args , $ this ->get_fields );
299351 $ formatter ->display_item ( $ ability_data );
300352 }
@@ -649,6 +701,7 @@ private function format_ability_for_list( $ability ) {
649701 'readonly ' => $ this ->format_annotation ( $ annotations ['readonly ' ] ),
650702 'destructive ' => $ this ->format_annotation ( $ annotations ['destructive ' ] ),
651703 'idempotent ' => $ this ->format_annotation ( $ annotations ['idempotent ' ] ),
704+ 'public ' => $ ability ->get_meta_item ( 'public ' , false ) ? '1 ' : '0 ' ,
652705 'show_in_rest ' => $ ability ->get_meta_item ( 'show_in_rest ' , false ) ? '1 ' : '0 ' ,
653706 ];
654707 }
@@ -661,6 +714,7 @@ private function format_ability_for_list( $ability ) {
661714 */
662715 private function format_ability_for_get ( $ ability ) {
663716 $ annotations = $ this ->get_annotations ( $ ability );
717+ $ meta = $ ability ->get_meta ();
664718
665719 return [
666720 'name ' => $ ability ->get_name (),
@@ -672,7 +726,9 @@ private function format_ability_for_get( $ability ) {
672726 'readonly ' => $ this ->format_annotation ( $ annotations ['readonly ' ] ),
673727 'destructive ' => $ this ->format_annotation ( $ annotations ['destructive ' ] ),
674728 'idempotent ' => $ this ->format_annotation ( $ annotations ['idempotent ' ] ),
729+ 'public ' => $ ability ->get_meta_item ( 'public ' , false ) ? '1 ' : '0 ' ,
675730 'show_in_rest ' => $ ability ->get_meta_item ( 'show_in_rest ' , false ) ? '1 ' : '0 ' ,
731+ 'meta ' => ! empty ( $ meta ) ? wp_json_encode ( $ meta ) : '{} ' ,
676732 ];
677733 }
678734
@@ -716,6 +772,33 @@ private function parse_bool_filter( $assoc_args, $flag ) {
716772 return $ parsed ;
717773 }
718774
775+ /**
776+ * Emits a debug note when the `public` meta flag is declared but inert.
777+ *
778+ * WordPress only resolves `public` into channel-specific flags such as
779+ * `show_in_rest` as of 7.1. On earlier versions the flag is stored as
780+ * declared but has no effect on client exposure, so `public` and
781+ * `show_in_rest` can disagree for no visible reason.
782+ *
783+ * @param array<int,array<string,mixed>> $items The formatted abilities.
784+ * @return void
785+ */
786+ private function maybe_debug_inert_public_flag ( $ items ) {
787+ if ( ! Utils \wp_version_compare ( '7.1 ' , '< ' ) ) {
788+ return ;
789+ }
790+
791+ foreach ( $ items as $ item ) {
792+ if ( isset ( $ item ['public ' ] ) && '1 ' === $ item ['public ' ] ) {
793+ WP_CLI ::debug (
794+ 'The `public` meta flag is only resolved into channel-specific flags such as `show_in_rest` as of WordPress 7.1. On this version it is reported as declared but has no effect on client exposure. ' ,
795+ 'ability '
796+ );
797+ return ;
798+ }
799+ }
800+ }
801+
719802 /**
720803 * Formats an annotation value for output.
721804 *
0 commit comments