wpnav_delete_user
Delete a WordPress user by ID and reassign their content to another user. Permanent deletion with audit logging for user management.
Instructions
Delete a WordPress user by ID. HIGH RISK: Permanent data loss. User content will be reassigned to specified user. Changes are logged in audit trail.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | WordPress user ID to delete | |
| reassign | Yes | User ID to reassign deleted user's content to (required) | |
| force | No | Force permanent deletion. Default: true |
Implementation Reference
- src/tools/users/index.ts:264-308 (handler)Executes the deletion of a WordPress user via WP REST API DELETE /wp/v2/users/{id} with reassign and force parameters. Includes validation, error handling for writes disabled, and structured response.handler: async (args, context) => { try { validateRequired(args, ['id', 'reassign']); const id = validateId(args.id, 'User'); const reassignId = validateId(args.reassign, 'Reassign User'); const params = new URLSearchParams({ force: String(args.force !== false), reassign: String(reassignId), }); const result = await context.wpRequest(`/wp/v2/users/${id}?${params.toString()}`, { method: 'DELETE', }); return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ id: result.id, message: 'User deleted successfully', }, null, 2)), }], }; } catch (error: any) { const errorMessage = error.message || 'Unknown error'; const isWritesDisabled = errorMessage.includes('WRITES_DISABLED'); return { content: [{ type: 'text', text: JSON.stringify({ error: isWritesDisabled ? 'writes_disabled' : 'operation_failed', code: isWritesDisabled ? 'WRITES_DISABLED' : 'DELETE_FAILED', message: errorMessage, context: { resource_type: 'user', resource_id: args.id, suggestion: isWritesDisabled ? 'Set WPNAV_ENABLE_WRITES=1 in MCP server config (.mcp.json env section)' : 'Check user ID exists with wpnav_get_user', }, }, null, 2), }], isError: true, }; } },
- src/tools/users/index.ts:254-262 (schema)Input schema validation for tool parameters: id (number, required), reassign (number, required), force (boolean, default true).inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'WordPress user ID to delete' }, reassign: { type: 'number', description: 'User ID to reassign deleted user\'s content to (required)' }, force: { type: 'boolean', description: 'Force permanent deletion. Default: true', default: true }, }, required: ['id', 'reassign'], },
- src/tools/users/index.ts:250-310 (registration)Registers the wpnav_delete_user tool with toolRegistry, including definition (name, description, schema), handler, and category.toolRegistry.register({ definition: { name: 'wpnav_delete_user', description: 'Delete a WordPress user by ID. HIGH RISK: Permanent data loss. User content will be reassigned to specified user. Changes are logged in audit trail.', inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'WordPress user ID to delete' }, reassign: { type: 'number', description: 'User ID to reassign deleted user\'s content to (required)' }, force: { type: 'boolean', description: 'Force permanent deletion. Default: true', default: true }, }, required: ['id', 'reassign'], }, }, handler: async (args, context) => { try { validateRequired(args, ['id', 'reassign']); const id = validateId(args.id, 'User'); const reassignId = validateId(args.reassign, 'Reassign User'); const params = new URLSearchParams({ force: String(args.force !== false), reassign: String(reassignId), }); const result = await context.wpRequest(`/wp/v2/users/${id}?${params.toString()}`, { method: 'DELETE', }); return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ id: result.id, message: 'User deleted successfully', }, null, 2)), }], }; } catch (error: any) { const errorMessage = error.message || 'Unknown error'; const isWritesDisabled = errorMessage.includes('WRITES_DISABLED'); return { content: [{ type: 'text', text: JSON.stringify({ error: isWritesDisabled ? 'writes_disabled' : 'operation_failed', code: isWritesDisabled ? 'WRITES_DISABLED' : 'DELETE_FAILED', message: errorMessage, context: { resource_type: 'user', resource_id: args.id, suggestion: isWritesDisabled ? 'Set WPNAV_ENABLE_WRITES=1 in MCP server config (.mcp.json env section)' : 'Check user ID exists with wpnav_get_user', }, }, null, 2), }], isError: true, }; } }, category: ToolCategory.USERS, });