| 1 |
<?php |
| 2 |
/** |
| 3 |
* Ability: Delete a saved WDesignKit cloud template. |
| 4 |
*/ |
| 5 |
|
| 6 |
declare(strict_types=1); |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit(); |
| 10 |
} |
| 11 |
|
| 12 |
wp_register_ability('wdesignkit/remove-template', [ |
| 13 |
'label' => __('Remove WDesignKit Template', 'wdesignkit'), |
| 14 |
'description' => __( |
| 15 |
'Deletes a user-saved WDesignKit cloud template by ID. Requires confirm: true to execute. Use dry_run: true to preview which template would be deleted.', |
| 16 |
'wdesignkit', |
| 17 |
), |
| 18 |
'category' => 'wdesignkit', |
| 19 |
'input_schema' => [ |
| 20 |
'type' => 'object', |
| 21 |
'properties' => [ |
| 22 |
'template_id' => [ |
| 23 |
'type' => 'string', |
| 24 |
'description' => 'Template ID to delete (from wdesignkit/list-templates or wdesignkit/find-template).', |
| 25 |
], |
| 26 |
'confirm' => [ |
| 27 |
'type' => 'boolean', |
| 28 |
'description' => 'Must be true to execute the deletion. Omitting or passing false returns an error requiring explicit confirmation.', |
| 29 |
], |
| 30 |
'dry_run' => [ |
| 31 |
'type' => 'boolean', |
| 32 |
'description' => 'When true, returns a preview of the call without making it.', |
| 33 |
], |
| 34 |
], |
| 35 |
'required' => ['template_id'], |
| 36 |
'additionalProperties' => false, |
| 37 |
], |
| 38 |
'output_schema' => [ |
| 39 |
'type' => 'object', |
| 40 |
'properties' => [ |
| 41 |
'success' => ['type' => 'boolean'], |
| 42 |
'dry_run' => ['type' => 'boolean'], |
| 43 |
'message' => ['type' => 'string'], |
| 44 |
'response' => ['type' => ['object', 'array']], |
| 45 |
], |
| 46 |
], |
| 47 |
'execute_callback' => 'wdesignkit_mcp_remove_template', |
| 48 |
'permission_callback' => 'wdesignkit_mcp_permission_callback', |
| 49 |
'meta' => [ |
| 50 |
'public' => true, |
| 51 |
'show_in_rest' => true, |
| 52 |
'mcp' => ['public' => true], |
| 53 |
'annotations' => [ |
| 54 |
'instructions' => implode("\n", [ |
| 55 |
'Permanently deletes a cloud template. There is no trash on the cloud side — the template is gone after this call.', |
| 56 |
'REQUIRED: confirm: true. Always preview with dry_run: true and surface the template details to the user before confirming.', |
| 57 |
'Requires WDesignKit login.', |
| 58 |
]), |
| 59 |
'readonly' => false, |
| 60 |
'destructive' => true, |
| 61 |
'idempotent' => false, |
| 62 |
], |
| 63 |
], |
| 64 |
]); |
| 65 |
|
| 66 |
function wdesignkit_mcp_remove_template(array $input): array { |
| 67 |
set_time_limit(90); |
| 68 |
|
| 69 |
$auth = wdesignkit_mcp_template_get_auth(); |
| 70 |
if (empty($auth['logged_in'])) { |
| 71 |
return ['success' => false, 'message' => $auth['message'] ?? 'Not logged in.']; |
| 72 |
} |
| 73 |
|
| 74 |
$template_id = sanitize_text_field((string) ($input['template_id'] ?? '')); |
| 75 |
$dry_run = !empty($input['dry_run']); |
| 76 |
$confirm = !empty($input['confirm']); |
| 77 |
|
| 78 |
if ($template_id === '') { |
| 79 |
return ['success' => false, 'message' => 'template_id is required.']; |
| 80 |
} |
| 81 |
|
| 82 |
if (!$dry_run && !$confirm) { |
| 83 |
return [ |
| 84 |
'success' => false, |
| 85 |
'message' => 'Deletion requires explicit confirmation. Re-send with confirm: true after previewing with dry_run: true.', |
| 86 |
]; |
| 87 |
} |
| 88 |
|
| 89 |
$args = [ |
| 90 |
'token' => $auth['token'], |
| 91 |
'template_id' => $template_id, |
| 92 |
]; |
| 93 |
|
| 94 |
if ($dry_run) { |
| 95 |
return [ |
| 96 |
'success' => true, |
| 97 |
'dry_run' => true, |
| 98 |
'message' => "Dry run — template_id '{$template_id}' would be removed.", |
| 99 |
'response' => ['endpoint' => 'template_remove', 'template_id' => $template_id], |
| 100 |
]; |
| 101 |
} |
| 102 |
|
| 103 |
$response = wdesignkit_mcp_template_cloud_call('template_remove', $args, 'json'); |
| 104 |
|
| 105 |
return [ |
| 106 |
'success' => (bool) ($response['success'] ?? false), |
| 107 |
'dry_run' => false, |
| 108 |
'message' => $response['message'] ?? '', |
| 109 |
'response' => $response, |
| 110 |
]; |
| 111 |
} |
| 112 |
|