Skip to main content
Glama

delete-user

Remove a WordPress user account and reassign their posts to another user using the WordPress MCP Server tool. Simplify user management with secure programmatic actions.

Instructions

Delete a WordPress user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
passwordYesWordPress application password
reassignIdYesID of the user to reassign posts to
siteUrlYesWordPress site URL
userIdYesUser ID or 'me' for current user
usernameYesWordPress username

Implementation Reference

  • The handler function for the 'delete-user' tool. It performs a DELETE request to the WordPress /wp-json/wp/v2/users/{userId} endpoint with force=true and reassign={reassignId} parameters to delete the user and reassign their content.
    async ({ siteUrl, username, password, userId, reassignId }) => { try { await makeWPRequest<any>({ siteUrl, endpoint: `users/${userId}`, method: "DELETE", auth: { username, password }, params: { force: true, reassign: reassignId } }); return { content: [ { type: "text", text: `Successfully deleted user ${userId}. Posts have been reassigned to user ${reassignId}.`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error deleting user: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
  • Zod input schema for the 'delete-user' tool defining parameters: siteUrl, username, password, userId (string/number/'me'), reassignId.
    { siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), userId: z.union([z.string(), z.number(), z.literal("me")]).describe("User ID or 'me' for current user"), reassignId: z.number().describe("ID of the user to reassign posts to"), },
  • src/index.ts:522-564 (registration)
    Registration of the 'delete-user' tool via server.tool() with name, description, input schema, and inline handler function.
    server.tool( "delete-user", "Delete a WordPress user", { siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), userId: z.union([z.string(), z.number(), z.literal("me")]).describe("User ID or 'me' for current user"), reassignId: z.number().describe("ID of the user to reassign posts to"), }, async ({ siteUrl, username, password, userId, reassignId }) => { try { await makeWPRequest<any>({ siteUrl, endpoint: `users/${userId}`, method: "DELETE", auth: { username, password }, params: { force: true, reassign: reassignId } }); return { content: [ { type: "text", text: `Successfully deleted user ${userId}. Posts have been reassigned to user ${reassignId}.`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error deleting user: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
  • Shared utility function makeWPRequest used by the delete-user handler (and other tools) to make authenticated HTTP requests to the WordPress REST API.
    // Helper function for making WordPress API requests async function makeWPRequest<T>({ siteUrl, endpoint, method = 'GET', auth, data = null, params = null }: { siteUrl: string; endpoint: string; method?: 'GET' | 'POST' | 'PUT' | 'DELETE'; auth: { username: string; password: string }; data?: any; params?: any; }): Promise<T> { const authString = Buffer.from(`${auth.username}:${auth.password}`).toString('base64'); try { const response = await axios({ method, url: `${siteUrl}/wp-json/wp/v2/${endpoint}`, headers: { 'Authorization': `Basic ${authString}`, 'Content-Type': 'application/json', }, data: data, params: params }); return response.data as T; } catch (error) { if (axios.isAxiosError(error) && error.response) { throw new Error(`WordPress API error: ${error.response.data?.message || error.message}`); } throw error; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/prathammanocha/wordpress-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server