| 1 |
<?php |
| 2 |
/** |
| 3 |
* Ability: Convert a WDesignKit widget from one builder to another (not supported — guidance stub). |
| 4 |
*/ |
| 5 |
|
| 6 |
declare(strict_types=1); |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit(); |
| 10 |
} |
| 11 |
|
| 12 |
wp_register_ability('wdesignkit/convert-widget', [ |
| 13 |
'label' => __('Convert WDesignKit Widget Builder', 'wdesignkit'), |
| 14 |
'description' => __( |
| 15 |
'Converts a widget authored for one builder (e.g. Elementor) into a different builder (e.g. Gutenberg). NOTE: Automatic cross-builder conversion is not currently supported by the WDesignKit plugin. This ability returns a structured explanation and suggests the recommended manual workflow instead.', |
| 16 |
'wdesignkit', |
| 17 |
), |
| 18 |
'category' => 'wdesignkit', |
| 19 |
'input_schema' => [ |
| 20 |
'type' => 'object', |
| 21 |
'properties' => [ |
| 22 |
'builder' => [ |
| 23 |
'type' => 'string', |
| 24 |
'description' => 'Source builder type.', |
| 25 |
'enum' => ['elementor', 'gutenberg', 'gutenberg_core', 'bricks'], |
| 26 |
], |
| 27 |
'folder' => [ |
| 28 |
'type' => 'string', |
| 29 |
'description' => 'Source widget folder name (from wdesignkit/list-widgets).', |
| 30 |
], |
| 31 |
'target_builder' => [ |
| 32 |
'type' => 'string', |
| 33 |
'description' => 'Target builder type to convert to.', |
| 34 |
'enum' => ['elementor', 'gutenberg', 'gutenberg_core', 'bricks'], |
| 35 |
], |
| 36 |
], |
| 37 |
'required' => ['builder', 'folder', 'target_builder'], |
| 38 |
'additionalProperties' => false, |
| 39 |
], |
| 40 |
'output_schema' => [ |
| 41 |
'type' => 'object', |
| 42 |
'properties' => [ |
| 43 |
'supported' => ['type' => 'boolean'], |
| 44 |
'message' => ['type' => 'string'], |
| 45 |
'guidance' => ['type' => 'array', 'items' => ['type' => 'string']], |
| 46 |
], |
| 47 |
], |
| 48 |
'execute_callback' => 'wdesignkit_mcp_convert_widget', |
| 49 |
'permission_callback' => 'wdesignkit_mcp_permission_callback', |
| 50 |
'meta' => [ |
| 51 |
'public' => true, |
| 52 |
'show_in_rest' => true, |
| 53 |
'mcp' => ['public' => true], |
| 54 |
'annotations' => [ |
| 55 |
'instructions' => implode("\n", [ |
| 56 |
'Cross-builder widget conversion is NOT implemented in WDesignKit — the underlying AJAX layer has no convert handler.', |
| 57 |
'Calling this ability will return supported: false plus a step-by-step manual workaround.', |
| 58 |
'Do NOT retry or attempt to work around this limitation programmatically.', |
| 59 |
]), |
| 60 |
'readonly' => true, |
| 61 |
'destructive' => false, |
| 62 |
'idempotent' => true, |
| 63 |
], |
| 64 |
], |
| 65 |
]); |
| 66 |
|
| 67 |
function wdesignkit_mcp_convert_widget(array $input): array { |
| 68 |
$builder = sanitize_text_field((string) ($input['builder'] ?? '')); |
| 69 |
$folder = sanitize_file_name((string) ($input['folder'] ?? '')); |
| 70 |
$target_builder = sanitize_text_field((string) ($input['target_builder'] ?? '')); |
| 71 |
|
| 72 |
if ($builder === $target_builder) { |
| 73 |
return [ |
| 74 |
'supported' => false, |
| 75 |
'message' => 'Source and target builder are the same — no conversion needed.', |
| 76 |
'guidance' => [], |
| 77 |
]; |
| 78 |
} |
| 79 |
|
| 80 |
return [ |
| 81 |
'supported' => false, |
| 82 |
'message' => "Automatic cross-builder conversion ({$builder} → {$target_builder}) is not supported by WDesignKit. Each builder uses a fundamentally different widget format (PHP class for Elementor, block.json + JS for Gutenberg).", |
| 83 |
'guidance' => [ |
| 84 |
"1. Use wdesignkit/get-widget to read the source widget's code and JSON config from '{$builder}/{$folder}'.", |
| 85 |
"2. Use wdesignkit/create-widget to create a new widget targeting '{$target_builder}', providing the new builder-appropriate code.", |
| 86 |
"3. Manually adapt the PHP/JS logic: Elementor widgets extend Widget_Base; Gutenberg blocks use register_block_type() with block.json.", |
| 87 |
"4. Use wdesignkit/update-widget to refine the new widget's code iteratively.", |
| 88 |
"5. Once satisfied, use wdesignkit/delete-widget (dry_run first) to optionally remove the original.", |
| 89 |
], |
| 90 |
]; |
| 91 |
} |
| 92 |
|