PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.4
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.4
3.4.4 3.4.3 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 All 197 releases
convertkit / vendor / wordpress / mcp-adapter / includes / Abilities / McpAbilityExposure.php

McpAbilityExposure.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.4, at vendor/wordpress/mcp-adapter/includes/Abilities/McpAbilityExposure.php

70 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Resolves whether an ability is exposed through the default MCP server.
4 *
5 * @package McpAdapter
6 */
7
8 declare( strict_types=1 );
9
10 namespace WP\MCP\Abilities;
11
12 use WP_Ability;
13
14 /**
15 * Class McpAbilityExposure
16 *
17 * Single source of truth for MCP exposure. Every read of the exposure flag must
18 * go through this class. Reading `meta.mcp.public` directly reintroduces the bug
19 * this class exists to prevent: exposure cannot be resolved while an ability is
20 * being registered, because `wp_register_ability_args` callbacks that run later
21 * can still change `meta.public`, and no filter priority is guaranteed to run
22 * last. Resolving from the stored ability instead happens after registration is
23 * complete, so the metadata is final.
24 *
25 * @since 0.6.0
26 */
27 final class McpAbilityExposure {
28
29 /**
30 * Determines whether an ability is exposed through the default MCP server.
31 *
32 * An explicit `meta.mcp.public` wins. When it is absent or null, exposure is
33 * inherited from the high-level `meta.public` flag. Malformed `meta.mcp`
34 * fails closed.
35 *
36 * @since 0.6.0
37 *
38 * @param \WP_Ability $ability The ability to check.
39 *
40 * @return bool True when the ability is exposed through MCP, false otherwise.
41 */
42 public static function is_public( WP_Ability $ability ): bool {
43 return self::is_meta_public( $ability->get_meta() );
44 }
45
46 /**
47 * Determines whether ability metadata resolves to MCP exposure.
48 *
49 * @since 0.6.0
50 *
51 * @param array<string, mixed> $meta Ability metadata.
52 *
53 * @return bool True when the metadata resolves to MCP exposure, false otherwise.
54 */
55 public static function is_meta_public( array $meta ): bool {
56 $mcp_meta = $meta['mcp'] ?? array();
57
58 // Fail closed when `meta.mcp` is malformed.
59 if ( ! is_array( $mcp_meta ) ) {
60 return false;
61 }
62
63 if ( isset( $mcp_meta['public'] ) ) {
64 return (bool) $mcp_meta['public'];
65 }
66
67 return true === ( $meta['public'] ?? false );
68 }
69 }
70