Delete a snippet
wp_delete_php_snippetMove a PHP snippet of Code Snippets or WPCode to the plugin's trash, or delete it for good with force: true. The id is the one wp_list_php_snippets lists. An active snippet stops running, so the test requests follow, and a fatal error (other code needing its functions) brings it back. Test requests then check that the site still runs, as wp_write_plugin_file does: the home page, this MCP endpoint (its own 401 is the expected answer), wp-admin/admin-post.php (runs admin_init, so admin snippets run there) and the dashboard in wp-admin, logged in as the account of this connection. A fatal error at any of them, or reaching none of them, puts the previous state back at once and the answer names target, error, file and line; this MCP endpoint ending early, or one target not reached while others are, is asked again with the previous state, and the change stays out where that answers. Not checked: wp-admin screens other than the dashboard (the editors, settings pages), cron, AJAX, and code that runs only on some pages or for other users; errors there are left to the snippet plugin: Code Snippets catches errors while a snippet loads, CODE_SNIPPETS_SAFE_MODE in wp-config.php stops every snippet and ?snippets-safe-mode=1 browses without them; WPCode switches off a snippet that ends a wp-admin request with an error, WPCODE_SAFE_MODE in wp-config.php stops every snippet and ?wpcode-safe-mode=1 in wp-admin or on the login page browses without them. While a safe mode stops every snippet, the test requests are skipped and the answer says so. Every change first records an undo point (wp_undo writes the plugin's record back byte for byte, with the same test requests, and keeps the current record where the site does worse with the old one) and is refused if that fails; a snippet too large for one needs allow_without_undo, and with undo switched off on the site the change goes ahead with a warning. The audit log notes the snippet name and the sha256 of the code before and after. Not on multisite; blocked by DISALLOW_FILE_EDIT and DISALLOW_FILE_MODS. Forwarded by AlphaBridge Connect to the one site this connection reaches.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Snippet id, as wp_list_php_snippets lists it. | |
| force | No | true deletes for good instead of moving the snippet to the trash. Default false. | |
| provider | No | Snippet plugin: code-snippets (Code Snippets) or wpcode (WPCode). Needed only when both are active. | |
| allow_without_undo | No | true makes the change although the snippet is too large for an undo point (over the undo size limit): the change then has no way back. Only for that case. | |
| allow_without_probe | No | true keeps the change although the test requests afterwards fail, where the previous state fails the same way: a fatal error that was there before, or a site that cannot reach itself (an HTTP login or a firewall in front of it). Every target is then asked, and each failure is asked again with the previous state; a failure the previous state does not have still puts it back. |