wp_delete_media
Delete media files from WordPress sites by specifying the media ID, with options to permanently remove or move to trash for site cleanup.
Instructions
Deletes a media item.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | No | The ID of the WordPress site to target (from mcp-wordpress.config.json). Required if multiple sites are configured. | |
| id | Yes | The ID of the media item to delete. | |
| force | No | If true, permanently delete. If false, move to trash. Defaults to false. |
Implementation Reference
- src/tools/media.ts:175-192 (registration)Tool registration and schema definition for wp_delete_media, including name, description, input parameters (id: number required, force: boolean optional), and handler binding.{ name: "wp_delete_media", description: "Deletes a media item.", parameters: [ { name: "id", type: "number", required: true, description: "The ID of the media item to delete.", }, { name: "force", type: "boolean", description: "If true, permanently delete. If false, move to trash. Defaults to false.", }, ], handler: this.handleDeleteMedia.bind(this), },
- src/tools/media.ts:256-265 (handler)The core handler function that implements wp_delete_media tool logic: extracts id and force params, calls WordPressClient.deleteMedia, handles success response and errors.public async handleDeleteMedia(client: WordPressClient, params: Record<string, unknown>): Promise<unknown> { const { id, force } = params as { id: number; force?: boolean }; try { await client.deleteMedia(id, force); const action = force ? "permanently deleted" : "moved to trash"; return `✅ Media item ${id} has been ${action}`; } catch (_error) { throw new Error(`Failed to delete media: ${getErrorMessage(_error)}`); } }