PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow / 2.7.0
WDesignKit – AI Templates, Widget Builder & MCP Workflow v2.7.0
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 / settings / wdesignkit-features-manager-toggle.php

wdesignkit-features-manager-toggle.php in WDesignKit – AI Templates, Widget Builder & MCP Workflow 2.7.0, at includes/abilities/settings/wdesignkit-features-manager-toggle.php

172 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Abilities: Get and toggle WDesignKit plugin feature on/off states.
4 */
5
6 declare(strict_types=1);
7
8 if (!defined('ABSPATH')) {
9 exit();
10 }
11
12 wp_register_ability('wdesignkit/get-features-manager', [
13 'label' => __('Get WDesignKit Feature Manager States', 'wdesignkit'),
14 'description' => __(
15 'Returns the current enabled/disabled state for WDesignKit plugin features: widget builder master switch, template library master switch, code-snippet module, and debug/developer mode.',
16 'wdesignkit',
17 ),
18 'category' => 'wdesignkit',
19 'input_schema' => [
20 'type' => 'object',
21 ],
22 'output_schema' => [
23 'type' => 'object',
24 'properties' => [
25 'success' => ['type' => 'boolean'],
26 'features' => ['type' => 'object'],
27 ],
28 ],
29 'execute_callback' => 'wdesignkit_mcp_get_features_manager',
30 'permission_callback' => 'wdesignkit_mcp_permission_callback',
31 'meta' => [
32 'public' => true,
33 'show_in_rest' => true,
34 'mcp' => ['public' => true],
35 'annotations' => [
36 'instructions' => implode("\n", [
37 'Returns the current state of all WDesignKit feature toggles.',
38 'Feature keys: builder (master widget feature), template (master template library), code_snippet, debugger_mode.',
39 'Use wdesignkit/toggle-features-manager to enable or disable individual features.',
40 ]),
41 'readonly' => true,
42 'destructive' => false,
43 'idempotent' => true,
44 ],
45 ],
46 ]);
47
48 wp_register_ability('wdesignkit/toggle-features-manager', [
49 'label' => __('Toggle WDesignKit Plugin Features', 'wdesignkit'),
50 'description' => __(
51 'Enables or disables individual WDesignKit plugin features: the widget builder master switch, the template library master switch, the code-snippet module, and debug/developer mode. Only the keys you pass are changed.',
52 'wdesignkit',
53 ),
54 'category' => 'wdesignkit',
55 'input_schema' => [
56 'type' => 'object',
57 'properties' => [
58 'builder' => [
59 'type' => 'boolean',
60 'description' => 'Master toggle for the entire widget builder feature.',
61 ],
62 'template' => [
63 'type' => 'boolean',
64 'description' => 'Master toggle for the entire template library feature.',
65 ],
66 'code_snippet' => [
67 'type' => 'boolean',
68 'description' => 'Enable or disable the code-snippet module.',
69 ],
70 'debugger_mode' => [
71 'type' => 'boolean',
72 'description' => 'Enable or disable developer/debug mode.',
73 ],
74 ],
75 'additionalProperties' => false,
76 ],
77 'output_schema' => [
78 'type' => 'object',
79 'properties' => [
80 'success' => ['type' => 'boolean'],
81 'message' => ['type' => 'string'],
82 'features' => ['type' => 'object'],
83 ],
84 ],
85 'execute_callback' => 'wdesignkit_mcp_toggle_features_manager',
86 'permission_callback' => 'wdesignkit_mcp_permission_callback',
87 'meta' => [
88 'public' => true,
89 'show_in_rest' => true,
90 'mcp' => ['public' => true],
91 'annotations' => [
92 'instructions' => implode("\n", [
93 'Toggles individual WDesignKit plugin features on or off.',
94 'Only pass the features you want to change.',
95 'Disabling builder hides all widget-building UI; disabling template hides the template library.',
96 'debugger_mode enables verbose error output — intended for troubleshooting only.',
97 ]),
98 'readonly' => false,
99 'destructive' => false,
100 'idempotent' => true,
101 ],
102 ],
103 ]);
104
105 function wdesignkit_mcp_get_features_manager(array $input): array {
106 $settings = get_option('wkit_settings_panel', []);
107 if (!is_array($settings)) {
108 $settings = [];
109 }
110
111 $defaults = [
112 'builder' => true,
113 'template' => true,
114 'code_snippet' => true,
115 'debugger_mode' => false,
116 ];
117
118 $features = [];
119 foreach ($defaults as $key => $default) {
120 $features[$key] = isset($settings[$key]) ? (bool) $settings[$key] : $default;
121 }
122
123 return [
124 'success' => true,
125 'features' => $features,
126 ];
127 }
128
129 function wdesignkit_mcp_toggle_features_manager(array $input): array {
130 $settings = get_option('wkit_settings_panel', []);
131 if (!is_array($settings)) {
132 $settings = [];
133 }
134
135 $allowed = ['builder', 'template', 'code_snippet', 'debugger_mode'];
136 $changed = [];
137
138 foreach ($allowed as $key) {
139 if (isset($input[$key])) {
140 $settings[$key] = (bool) $input[$key];
141 $changed[] = $key;
142 }
143 }
144
145 $defaults = [
146 'builder' => true,
147 'template' => true,
148 'code_snippet' => true,
149 'debugger_mode' => false,
150 ];
151 $features = [];
152 foreach ($defaults as $key => $default) {
153 $features[$key] = isset($settings[$key]) ? (bool) $settings[$key] : $default;
154 }
155
156 if (empty($changed)) {
157 return [
158 'success' => true,
159 'message' => 'No feature settings provided to update.',
160 'features' => $features,
161 ];
162 }
163
164 update_option('wkit_settings_panel', $settings);
165
166 return [
167 'success' => true,
168 'message' => 'Feature settings updated: ' . implode(', ', $changed),
169 'features' => $features,
170 ];
171 }
172