PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.3
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.3
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / wordpress / mcp-adapter / includes / Domain / Utils / AbilityArgumentNormalizer.php

AbilityArgumentNormalizer.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.3, at vendor/wordpress/mcp-adapter/includes/Domain/Utils/AbilityArgumentNormalizer.php

46 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Normalizes ability arguments for MCP protocol compatibility.
4 *
5 * @package McpAdapter
6 */
7
8 declare( strict_types=1 );
9
10 namespace WP\MCP\Domain\Utils;
11
12 /**
13 * Normalizes ability arguments between MCP and WordPress Abilities API.
14 *
15 * MCP clients send {} (empty object) for tools without arguments.
16 * PHP decodes this as [] (empty array).
17 * Abilities without input_schema expect null, not empty array.
18 *
19 * @since 0.5.0
20 */
21 class AbilityArgumentNormalizer {
22
23 /**
24 * Normalize parameters for an ability based on its input schema.
25 *
26 * If the ability has no input schema, empty arrays are converted to null.
27 * This ensures compatibility with abilities that don't accept parameters.
28 *
29 * @param \WP_Ability $ability The ability to normalize parameters for.
30 * @param mixed $parameters The parameters to normalize.
31 *
32 * @return mixed Normalized parameters (null if ability has no schema and params are empty).
33 * @since 0.5.0
34 *
35 */
36 public static function normalize( \WP_Ability $ability, $parameters ) {
37 $input_schema = $ability->get_input_schema();
38
39 if ( empty( $input_schema ) && is_array( $parameters ) && empty( $parameters ) ) {
40 return null;
41 }
42
43 return $parameters;
44 }
45 }
46