wpnav_gutenberg_delete_block
Remove Gutenberg blocks from WordPress posts by specifying the post ID and block path to modify content directly.
Instructions
Delete a Gutenberg block at specified path. WARNING: This action modifies post content immediately.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| post_id | Yes | Post ID to modify | |
| path | Yes | Path to block to delete (e.g., [0] = first block, [1, 0] = first child of second block) |
Implementation Reference
- src/tools/gutenberg/index.ts:444-491 (handler)The main handler function for the wpnav_gutenberg_delete_block tool. It validates the input arguments (post_id and path), calls the WordPress REST API endpoint '/wpnav/v1/gutenberg/blocks/delete' with a POST request, and returns success or error response.handler: async (args, context) => { validateRequired(args, ['post_id', 'path']); const id = validateId(args.post_id, 'Post'); if (!validatePath(args.path)) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'invalid_path', message: 'Path must be non-empty array of non-negative integers', }, null, 2)), }], isError: true, }; } // Call REST API const result = await context.wpRequest('/wpnav/v1/gutenberg/blocks/delete', { method: 'POST', body: JSON.stringify({ post_id: id, path: args.path, }), }); if (!result.success) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: result.error }, null, 2)), }], isError: true, }; } return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ success: true, post_id: id, path: args.path, message: 'Block deleted successfully', }, null, 2)), }], }; },
- src/tools/gutenberg/index.ts:428-442 (schema)The inputSchema for the tool, specifying post_id as number and path as array of numbers, both required.inputSchema: { type: 'object', properties: { post_id: { type: 'number', description: 'Post ID to modify', }, path: { type: 'array', items: { type: 'number' }, description: 'Path to block to delete (e.g., [0] = first block, [1, 0] = first child of second block)', }, }, required: ['post_id', 'path'], },
- src/tools/gutenberg/index.ts:424-493 (registration)The toolRegistry.register call that registers the wpnav_gutenberg_delete_block tool, including its name, description, schema, handler, and category.toolRegistry.register({ definition: { name: 'wpnav_gutenberg_delete_block', description: 'Delete a Gutenberg block at specified path. WARNING: This action modifies post content immediately.', inputSchema: { type: 'object', properties: { post_id: { type: 'number', description: 'Post ID to modify', }, path: { type: 'array', items: { type: 'number' }, description: 'Path to block to delete (e.g., [0] = first block, [1, 0] = first child of second block)', }, }, required: ['post_id', 'path'], }, }, handler: async (args, context) => { validateRequired(args, ['post_id', 'path']); const id = validateId(args.post_id, 'Post'); if (!validatePath(args.path)) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'invalid_path', message: 'Path must be non-empty array of non-negative integers', }, null, 2)), }], isError: true, }; } // Call REST API const result = await context.wpRequest('/wpnav/v1/gutenberg/blocks/delete', { method: 'POST', body: JSON.stringify({ post_id: id, path: args.path, }), }); if (!result.success) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: result.error }, null, 2)), }], isError: true, }; } return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ success: true, post_id: id, path: args.path, message: 'Block deleted successfully', }, null, 2)), }], }; }, category: ToolCategory.CONTENT, });
- src/tools/gutenberg/helpers.ts:44-54 (helper)validatePath helper function used in the handler to ensure the path is a valid non-empty array of non-negative integers.export function validatePath(path: number[]): boolean { if (!Array.isArray(path)) { return false; } if (path.length === 0) { return false; } return path.every(n => Number.isInteger(n) && n >= 0); }