PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow / 2.7.1
WDesignKit – AI Templates, Widget Builder & MCP Workflow v2.7.1
2.7.1 2.7.0 2.6.6 2.6.5 2.6.4 2.6.3 2.6.2 2.6.1 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 2.5.1 2.5.0 2.4.0 2.3.3 2.3.2 2.3.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 All 130 releases
wdesignkit / includes / abilities / code-snippets / wdesignkit-delete-snippet.php

wdesignkit-delete-snippet.php in WDesignKit – AI Templates, Widget Builder & MCP Workflow 2.7.1, at includes/abilities/code-snippets/wdesignkit-delete-snippet.php

103 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Ability: Delete a WDesignKit cloud snippet.
4 */
5
6 declare(strict_types=1);
7
8 if (!defined('ABSPATH')) {
9 exit();
10 }
11
12 wp_register_ability('wdesignkit/delete-snippet', [
13 'label' => __('Delete WDesignKit Cloud Snippet', 'wdesignkit'),
14 'description' => __(
15 'Deletes a snippet from the WDesignKit cloud marketplace by its cloud snippet ID. This removes the snippet from the cloud only — the local nxt-code-snippet WordPress post (if any) is NOT affected. Requires cloud login and confirm: true.',
16 'wdesignkit',
17 ),
18 'category' => 'wdesignkit',
19 'input_schema' => [
20 'type' => 'object',
21 'properties' => [
22 'snippet_id' => [
23 'type' => 'string',
24 'description' => 'Cloud snippet ID to delete (from wdesignkit/get-my-snippets or wdesignkit/get-existing-snippet).',
25 ],
26 'confirm' => [
27 'type' => 'boolean',
28 'description' => 'Must be true to execute the deletion. Omit or false for a dry-run preview.',
29 ],
30 ],
31 'required' => ['snippet_id'],
32 'additionalProperties' => false,
33 ],
34 'output_schema' => [
35 'type' => 'object',
36 'properties' => [
37 'success' => ['type' => 'boolean'],
38 'message' => ['type' => 'string'],
39 'response' => ['type' => ['object', 'array']],
40 'dry_run' => ['type' => 'boolean'],
41 ],
42 ],
43 'execute_callback' => 'wdesignkit_mcp_delete_snippet',
44 'permission_callback' => 'wdesignkit_mcp_permission_callback',
45 'meta' => [
46 'public' => false,
47 'show_in_rest' => true,
48 'mcp' => ['public' => false],
49 'annotations' => [
50 'instructions' => implode("\n", [
51 'Deletes a cloud snippet from the WDesignKit marketplace. Requires cloud login.',
52 'confirm: true is required to execute. Without it the call returns a dry-run preview.',
53 'Only removes the cloud record — local WP posts are not affected.',
54 'Get snippet_id from wdesignkit/get-my-snippets or wdesignkit/get-existing-snippet.',
55 ]),
56 'readonly' => false,
57 'destructive' => true,
58 'idempotent' => false,
59 ],
60 ],
61 ]);
62
63 function wdesignkit_mcp_delete_snippet(array $input): array {
64 // Timeout guard: cloud delete call uses the default 60s HTTP timeout.
65 set_time_limit(90);
66
67 if (!defined('WDKIT_SERVER_API_URL')) {
68 return ['success' => false, 'message' => 'WDesignKit plugin is not active.'];
69 }
70
71 $auth = wdesignkit_mcp_template_get_auth();
72 if (empty($auth['logged_in'])) {
73 return ['success' => false, 'message' => $auth['message'] ?? 'Not logged in to WDesignKit cloud.'];
74 }
75
76 $snippet_id = sanitize_text_field((string) ($input['snippet_id'] ?? ''));
77 $confirm = (bool) ($input['confirm'] ?? false);
78
79 if ($snippet_id === '') {
80 return ['success' => false, 'message' => 'snippet_id is required.'];
81 }
82
83 if (!$confirm) {
84 return [
85 'success' => false,
86 'message' => "Dry run: would delete cloud snippet ID '{$snippet_id}'. Pass confirm: true to execute.",
87 'dry_run' => true,
88 ];
89 }
90
91 $cloud = wdesignkit_mcp_template_cloud_call('snippet/delete', [
92 'token' => $auth['token'],
93 'id' => $snippet_id,
94 ], 'form');
95
96 return [
97 'success' => !empty($cloud['success']),
98 'message' => $cloud['message'] ?? $cloud['massage'] ?? ($cloud['success'] ? 'Snippet deleted.' : 'Failed to delete snippet.'),
99 'response' => $cloud,
100 'dry_run' => false,
101 ];
102 }
103