| 1 |
<?php |
| 2 |
/** |
| 3 |
* Abilities: Get, set, and reset WDesignKit white-label branding settings. |
| 4 |
*/ |
| 5 |
|
| 6 |
declare(strict_types=1); |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit(); |
| 10 |
} |
| 11 |
|
| 12 |
wp_register_ability('wdesignkit/get-white-label', [ |
| 13 |
'label' => __('Get WDesignKit White Label Settings', 'wdesignkit'), |
| 14 |
'description' => __( |
| 15 |
'Returns the current WDesignKit white-label branding configuration: custom plugin name, description, developer name, website URL, logo URL, and visibility toggles for help link, news, license tab, and rollback tab.', |
| 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 |
'configured' => ['type' => 'boolean'], |
| 27 |
'white_label' => ['type' => ['object', 'null']], |
| 28 |
], |
| 29 |
], |
| 30 |
'execute_callback' => 'wdesignkit_mcp_get_white_label', |
| 31 |
'permission_callback' => 'wdesignkit_mcp_permission_callback', |
| 32 |
'meta' => [ |
| 33 |
'public' => true, |
| 34 |
'show_in_rest' => true, |
| 35 |
'mcp' => ['public' => true], |
| 36 |
'annotations' => [ |
| 37 |
'instructions' => implode("\n", [ |
| 38 |
'Returns white label settings stored in the wkit_white_label option.', |
| 39 |
'configured is false and white_label is null when no white label is set.', |
| 40 |
'Use wdesignkit/set-white-label to configure; wdesignkit/reset-white-label to remove.', |
| 41 |
]), |
| 42 |
'readonly' => true, |
| 43 |
'destructive' => false, |
| 44 |
'idempotent' => true, |
| 45 |
], |
| 46 |
], |
| 47 |
]); |
| 48 |
|
| 49 |
wp_register_ability('wdesignkit/set-white-label', [ |
| 50 |
'label' => __('Set WDesignKit White Label Settings', 'wdesignkit'), |
| 51 |
'description' => __( |
| 52 |
'Configures WDesignKit white-label branding. plugin_name is required. All other fields are optional; provided fields are merged with any existing white label configuration.', |
| 53 |
'wdesignkit', |
| 54 |
), |
| 55 |
'category' => 'wdesignkit', |
| 56 |
'input_schema' => [ |
| 57 |
'type' => 'object', |
| 58 |
'properties' => [ |
| 59 |
'plugin_name' => [ |
| 60 |
'type' => 'string', |
| 61 |
'description' => 'Custom display name shown in the WordPress Plugins list. Required.', |
| 62 |
], |
| 63 |
'plugin_desc' => [ |
| 64 |
'type' => 'string', |
| 65 |
'description' => 'Custom plugin description.', |
| 66 |
], |
| 67 |
'developer_name' => [ |
| 68 |
'type' => 'string', |
| 69 |
'description' => 'Custom developer / author name.', |
| 70 |
], |
| 71 |
'website_url' => [ |
| 72 |
'type' => 'string', |
| 73 |
'description' => 'Custom developer website URL.', |
| 74 |
], |
| 75 |
'plugin_logo' => [ |
| 76 |
'type' => 'string', |
| 77 |
'description' => 'URL to a custom plugin logo image.', |
| 78 |
], |
| 79 |
'help_link' => [ |
| 80 |
'type' => 'boolean', |
| 81 |
'description' => 'Show or hide the help link in the plugin UI.', |
| 82 |
], |
| 83 |
'plugin_news' => [ |
| 84 |
'type' => 'boolean', |
| 85 |
'description' => 'Show or hide the plugin news section.', |
| 86 |
], |
| 87 |
'licence_tab' => [ |
| 88 |
'type' => 'boolean', |
| 89 |
'description' => 'Show or hide the license/subscription tab.', |
| 90 |
], |
| 91 |
'rollback_tab' => [ |
| 92 |
'type' => 'boolean', |
| 93 |
'description' => 'Show or hide the rollback tab.', |
| 94 |
], |
| 95 |
'force_disable' => [ |
| 96 |
'type' => 'boolean', |
| 97 |
'description' => 'Force-disable white label even if a configuration exists.', |
| 98 |
], |
| 99 |
], |
| 100 |
'required' => ['plugin_name'], |
| 101 |
'additionalProperties' => false, |
| 102 |
], |
| 103 |
'output_schema' => [ |
| 104 |
'type' => 'object', |
| 105 |
'properties' => [ |
| 106 |
'success' => ['type' => 'boolean'], |
| 107 |
'message' => ['type' => 'string'], |
| 108 |
'white_label' => ['type' => 'object'], |
| 109 |
], |
| 110 |
], |
| 111 |
'execute_callback' => 'wdesignkit_mcp_set_white_label', |
| 112 |
'permission_callback' => 'wdesignkit_mcp_permission_callback', |
| 113 |
'meta' => [ |
| 114 |
'public' => true, |
| 115 |
'show_in_rest' => true, |
| 116 |
'mcp' => ['public' => true], |
| 117 |
'annotations' => [ |
| 118 |
'instructions' => implode("\n", [ |
| 119 |
'Sets white label branding for the WDesignKit plugin.', |
| 120 |
'plugin_name is required and is shown in the WordPress Plugins list.', |
| 121 |
'Omitted optional fields retain their existing values.', |
| 122 |
'Use wdesignkit/reset-white-label to remove all white label branding.', |
| 123 |
]), |
| 124 |
'readonly' => false, |
| 125 |
'destructive' => false, |
| 126 |
'idempotent' => true, |
| 127 |
], |
| 128 |
], |
| 129 |
]); |
| 130 |
|
| 131 |
wp_register_ability('wdesignkit/reset-white-label', [ |
| 132 |
'label' => __('Reset WDesignKit White Label Settings', 'wdesignkit'), |
| 133 |
'description' => __( |
| 134 |
'Deletes the entire WDesignKit white-label configuration, restoring the default plugin branding. Requires confirm: true.', |
| 135 |
'wdesignkit', |
| 136 |
), |
| 137 |
'category' => 'wdesignkit', |
| 138 |
'input_schema' => [ |
| 139 |
'type' => 'object', |
| 140 |
'properties' => [ |
| 141 |
'confirm' => [ |
| 142 |
'type' => 'boolean', |
| 143 |
'description' => 'Must be true to delete white label settings.', |
| 144 |
], |
| 145 |
], |
| 146 |
'additionalProperties' => false, |
| 147 |
], |
| 148 |
'output_schema' => [ |
| 149 |
'type' => 'object', |
| 150 |
'properties' => [ |
| 151 |
'success' => ['type' => 'boolean'], |
| 152 |
'message' => ['type' => 'string'], |
| 153 |
], |
| 154 |
], |
| 155 |
'execute_callback' => 'wdesignkit_mcp_reset_white_label', |
| 156 |
'permission_callback' => 'wdesignkit_mcp_permission_callback', |
| 157 |
'meta' => [ |
| 158 |
'public' => true, |
| 159 |
'show_in_rest' => true, |
| 160 |
'mcp' => ['public' => true], |
| 161 |
'annotations' => [ |
| 162 |
'instructions' => implode("\n", [ |
| 163 |
'Deletes all white label settings and restores the default plugin branding.', |
| 164 |
'confirm: true is required to execute.', |
| 165 |
'To reconfigure, call wdesignkit/set-white-label again.', |
| 166 |
]), |
| 167 |
'readonly' => false, |
| 168 |
'destructive' => true, |
| 169 |
'idempotent' => false, |
| 170 |
], |
| 171 |
], |
| 172 |
]); |
| 173 |
|
| 174 |
function wdesignkit_mcp_get_white_label(array $input): array { |
| 175 |
$wl = get_option('wkit_white_label', null); |
| 176 |
|
| 177 |
return [ |
| 178 |
'success' => true, |
| 179 |
'configured' => !empty($wl), |
| 180 |
'white_label' => is_array($wl) ? $wl : null, |
| 181 |
]; |
| 182 |
} |
| 183 |
|
| 184 |
function wdesignkit_mcp_set_white_label(array $input): array { |
| 185 |
$plugin_name = sanitize_text_field((string) ($input['plugin_name'] ?? '')); |
| 186 |
if ($plugin_name === '') { |
| 187 |
return ['success' => false, 'message' => 'plugin_name is required.']; |
| 188 |
} |
| 189 |
|
| 190 |
$existing = get_option('wkit_white_label', []); |
| 191 |
if (!is_array($existing)) { |
| 192 |
$existing = []; |
| 193 |
} |
| 194 |
|
| 195 |
$new_data = $existing; |
| 196 |
$string_fields = ['plugin_name', 'plugin_desc', 'developer_name', 'website_url', 'plugin_logo']; |
| 197 |
$boolean_fields = ['help_link', 'plugin_news', 'licence_tab', 'rollback_tab', 'force_disable']; |
| 198 |
|
| 199 |
foreach ($string_fields as $field) { |
| 200 |
if (isset($input[$field])) { |
| 201 |
$new_data[$field] = sanitize_text_field((string) $input[$field]); |
| 202 |
} |
| 203 |
} |
| 204 |
foreach ($boolean_fields as $field) { |
| 205 |
if (isset($input[$field])) { |
| 206 |
$new_data[$field] = (bool) $input[$field]; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
if (!empty($existing)) { |
| 211 |
update_option('wkit_white_label', $new_data); |
| 212 |
} else { |
| 213 |
add_option('wkit_white_label', $new_data); |
| 214 |
} |
| 215 |
|
| 216 |
return [ |
| 217 |
'success' => true, |
| 218 |
'message' => 'White label settings saved.', |
| 219 |
'white_label' => $new_data, |
| 220 |
]; |
| 221 |
} |
| 222 |
|
| 223 |
function wdesignkit_mcp_reset_white_label(array $input): array { |
| 224 |
$confirm = (bool) ($input['confirm'] ?? false); |
| 225 |
|
| 226 |
if (!$confirm) { |
| 227 |
return [ |
| 228 |
'success' => false, |
| 229 |
'message' => 'confirm: true is required to delete white label settings.', |
| 230 |
]; |
| 231 |
} |
| 232 |
|
| 233 |
$exists = get_option('wkit_white_label', false); |
| 234 |
|
| 235 |
if (empty($exists)) { |
| 236 |
return [ |
| 237 |
'success' => true, |
| 238 |
'message' => 'No white label settings found — nothing to reset.', |
| 239 |
]; |
| 240 |
} |
| 241 |
|
| 242 |
delete_option('wkit_white_label'); |
| 243 |
|
| 244 |
return [ |
| 245 |
'success' => true, |
| 246 |
'message' => 'White label settings deleted. Plugin branding restored to defaults.', |
| 247 |
]; |
| 248 |
} |
| 249 |
|