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,11 @@ public function list_( $args, $assoc_args ): void {
203222 }
204223 }
205224
225+ // Filter by public if specified.
226+ if ( null !== $ public && $ public !== ( '1 ' === $ ability_data ['public ' ] ) ) {
227+ continue ;
228+ }
229+
206230 // Filter by show_in_rest if specified.
207231 if ( null !== $ show_in_rest && $ show_in_rest !== ( '1 ' === $ ability_data ['show_in_rest ' ] ) ) {
208232 continue ;
@@ -211,6 +235,8 @@ public function list_( $args, $assoc_args ): void {
211235 $ items [] = $ ability_data ;
212236 }
213237
238+ $ this ->maybe_debug_inert_public_flag ( $ items );
239+
214240 $ formatter = $ this ->get_formatter ( $ assoc_args , $ this ->default_fields );
215241 $ formatter ->display_items ( $ items );
216242 }
@@ -242,6 +268,8 @@ public function list_( $args, $assoc_args ): void {
242268 *
243269 * ## AVAILABLE FIELDS
244270 *
271+ * These fields will be displayed by default:
272+ *
245273 * * name
246274 * * label
247275 * * category
@@ -251,8 +279,22 @@ public function list_( $args, $assoc_args ): void {
251279 * * readonly
252280 * * destructive
253281 * * idempotent
282+ * * public
254283 * * show_in_rest
255284 *
285+ * These fields are optionally available:
286+ *
287+ * * meta
288+ *
289+ * The `public` field reports the high-level client exposure flag as declared
290+ * by the ability. As of WordPress 7.1 it seeds the default for channel-specific
291+ * flags such as `show_in_rest`, which take precedence when set explicitly.
292+ * On earlier versions the flag is stored but has no effect, so `public` and
293+ * `show_in_rest` may disagree.
294+ *
295+ * The `meta` field renders the raw metadata as JSON. It is the only way to
296+ * inspect channel-specific settings registered by plugins, such as `mcp`.
297+ *
256298 * ## EXAMPLES
257299 *
258300 * # Get details of a specific ability.
@@ -269,9 +311,14 @@ public function list_( $args, $assoc_args ): void {
269311 * | readonly | 1 |
270312 * | destructive | 0 |
271313 * | idempotent | 1 |
314+ * | public | 1 |
272315 * | show_in_rest | 1 |
273316 * +---------------+----------------------+
274317 *
318+ * # Inspect channel-specific settings that have no field of their own.
319+ * $ wp ability get my-plugin/my-ability --field=meta
320+ * {"annotations":{"readonly":true,"destructive":false,"idempotent":null},"mcp":{"public":false},"show_in_rest":true,"public":true}
321+ *
275322 * # Get ability as JSON.
276323 * $ wp ability get core/get-site-info --format=json
277324 *
@@ -292,6 +339,8 @@ public function get( $args, $assoc_args ): void {
292339
293340 $ ability_data = $ this ->format_ability_for_get ( $ ability );
294341
342+ $ this ->maybe_debug_inert_public_flag ( [ $ ability_data ] );
343+
295344 $ formatter = $ this ->get_formatter ( $ assoc_args , $ this ->get_fields );
296345 $ formatter ->display_item ( $ ability_data );
297346 }
@@ -646,6 +695,7 @@ private function format_ability_for_list( $ability ) {
646695 'readonly ' => $ this ->format_annotation ( $ annotations ['readonly ' ] ),
647696 'destructive ' => $ this ->format_annotation ( $ annotations ['destructive ' ] ),
648697 'idempotent ' => $ this ->format_annotation ( $ annotations ['idempotent ' ] ),
698+ 'public ' => $ ability ->get_meta_item ( 'public ' , false ) ? '1 ' : '0 ' ,
649699 'show_in_rest ' => $ ability ->get_meta_item ( 'show_in_rest ' , false ) ? '1 ' : '0 ' ,
650700 ];
651701 }
@@ -658,6 +708,7 @@ private function format_ability_for_list( $ability ) {
658708 */
659709 private function format_ability_for_get ( $ ability ) {
660710 $ annotations = $ this ->get_annotations ( $ ability );
711+ $ meta = $ ability ->get_meta ();
661712
662713 return [
663714 'name ' => $ ability ->get_name (),
@@ -669,7 +720,9 @@ private function format_ability_for_get( $ability ) {
669720 'readonly ' => $ this ->format_annotation ( $ annotations ['readonly ' ] ),
670721 'destructive ' => $ this ->format_annotation ( $ annotations ['destructive ' ] ),
671722 'idempotent ' => $ this ->format_annotation ( $ annotations ['idempotent ' ] ),
723+ 'public ' => $ ability ->get_meta_item ( 'public ' , false ) ? '1 ' : '0 ' ,
672724 'show_in_rest ' => $ ability ->get_meta_item ( 'show_in_rest ' , false ) ? '1 ' : '0 ' ,
725+ 'meta ' => ! empty ( $ meta ) ? wp_json_encode ( $ meta ) : '{} ' ,
673726 ];
674727 }
675728
@@ -713,6 +766,33 @@ private function parse_bool_filter( $assoc_args, $flag ) {
713766 return $ parsed ;
714767 }
715768
769+ /**
770+ * Emits a debug note when the `public` meta flag is declared but inert.
771+ *
772+ * WordPress only resolves `public` into channel-specific flags such as
773+ * `show_in_rest` as of 7.1. On earlier versions the flag is stored as
774+ * declared but has no effect on client exposure, so `public` and
775+ * `show_in_rest` can disagree for no visible reason.
776+ *
777+ * @param array<int,array<string,mixed>> $items The formatted abilities.
778+ * @return void
779+ */
780+ private function maybe_debug_inert_public_flag ( $ items ) {
781+ if ( ! Utils \wp_version_compare ( '7.1 ' , '< ' ) ) {
782+ return ;
783+ }
784+
785+ foreach ( $ items as $ item ) {
786+ if ( isset ( $ item ['public ' ] ) && '1 ' === $ item ['public ' ] ) {
787+ WP_CLI ::debug (
788+ '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. ' ,
789+ 'ability '
790+ );
791+ return ;
792+ }
793+ }
794+ }
795+
716796 /**
717797 * Formats an annotation value for output.
718798 *
0 commit comments