PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / modules / wp-abilities-api / Adapters / AbilitiesBridge.php

AbilitiesBridge.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at modules/wp-abilities-api/Adapters/AbilitiesBridge.php

79 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Publishes the registry's capabilities through the WordPress Abilities API
4 * (spec 044, FR-010/FR-012).
5 *
6 * This is an ADAPTER, not a source of truth. Before 044 the abilities were
7 * declared here (well, in MCP.php) and everything else read from them; now the
8 * registry holds the declarations and this bridge projects them outward. That
9 * inversion is what removes the Abilities API from the critical path — the
10 * native server works identically whether or not this bridge ever attaches.
11 *
12 * Attached ONLY when `wp_register_ability()` exists. Its absence is not an
13 * error and must produce no admin notice (FR-012): the overwhelming majority of
14 * sites running this plugin are below the WordPress version that ships the
15 * Abilities API, and the whole point of 044 is that they are fully supported.
16 *
17 * @package Templately\Modules\WpAbilitiesApi\Adapters
18 */
19
20 namespace Templately\Modules\WpAbilitiesApi\Adapters;
21
22 use Templately\Modules\McpCore\Registry\ToolRegistry;
23
24 class AbilitiesBridge {
25
26 const CATEGORY = 'templately';
27
28 /**
29 * Whether WordPress core's Abilities API is present (core 6.9+).
30 *
31 * Split from the old all-or-nothing `MCP::is_available()`: the Abilities API
32 * and mcp-adapter are INDEPENDENT optional consumers now, and neither gates
33 * the built-in server. Templately supports WordPress 5.0+, so on most sites
34 * this returns false and MCP still works fully.
35 *
36 * @return bool
37 */
38 public static function is_available(): bool {
39 return function_exists( 'wp_register_ability' );
40 }
41
42 public static function attach(): void {
43 add_action( 'wp_abilities_api_categories_init', [ self::class, 'register_category' ] );
44 add_action( 'wp_abilities_api_init', [ self::class, 'register_abilities' ] );
45 }
46
47 public static function register_category(): void {
48 if ( ! function_exists( 'wp_register_ability_category' ) ) {
49 return;
50 }
51
52 if ( function_exists( 'wp_has_ability_category' ) && wp_has_ability_category( self::CATEGORY ) ) {
53 return;
54 }
55
56 wp_register_ability_category(
57 self::CATEGORY,
58 [
59 'label' => __( 'Templately', 'templately' ),
60 'description' => __( 'Search, preview, and import Templately designs on this WordPress site.', 'templately' ),
61 ]
62 );
63 }
64
65 /**
66 * One ability per registry descriptor — no hand-maintained list (FR-011).
67 * test-RegistryAbilitiesParity.php asserts this set equals the registry's.
68 */
69 public static function register_abilities(): void {
70 if ( ! function_exists( 'wp_register_ability' ) ) {
71 return;
72 }
73
74 foreach ( ToolRegistry::get_instance()->all() as $descriptor ) {
75 wp_register_ability( $descriptor->id, $descriptor->to_ability_args() );
76 }
77 }
78 }
79