wpnav_gutenberg_move_block
Move Gutenberg blocks within WordPress posts to reorganize content structure or reposition nested elements for better layout management.
Instructions
Move a Gutenberg block from one path to another. Useful for reordering blocks or moving nested blocks.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| post_id | Yes | Post ID to modify | |
| from_path | Yes | Source path (block to move) | |
| to_path | Yes | Destination path (where to move block) |
Implementation Reference
- src/tools/gutenberg/index.ts:355-417 (handler)Handler function that validates input parameters (post_id, from_path, to_path) and performs the block move by calling the WordPress REST API endpoint '/wpnav/v1/gutenberg/blocks/move'.handler: async (args, context) => { validateRequired(args, ['post_id', 'from_path', 'to_path']); const id = validateId(args.post_id, 'Post'); if (!validatePath(args.from_path)) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'invalid_from_path', message: 'from_path must be non-empty array of non-negative integers', }, null, 2)), }], isError: true, }; } if (!validatePath(args.to_path)) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'invalid_to_path', message: 'to_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/move', { method: 'POST', body: JSON.stringify({ post_id: id, from_path: args.from_path, to_path: args.to_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, from_path: args.from_path, to_path: args.to_path, message: 'Block moved successfully', }, null, 2)), }], }; },
- src/tools/gutenberg/index.ts:334-353 (schema)Input schema defining the required parameters for the tool: post_id (number), from_path (array of numbers), to_path (array of numbers).inputSchema: { type: 'object', properties: { post_id: { type: 'number', description: 'Post ID to modify', }, from_path: { type: 'array', items: { type: 'number' }, description: 'Source path (block to move)', }, to_path: { type: 'array', items: { type: 'number' }, description: 'Destination path (where to move block)', }, }, required: ['post_id', 'from_path', 'to_path'], },
- src/tools/gutenberg/index.ts:330-419 (registration)Full registration of the wpnav_gutenberg_move_block tool using toolRegistry.register, including definition (name, description, schema), handler, and category.toolRegistry.register({ definition: { name: 'wpnav_gutenberg_move_block', description: 'Move a Gutenberg block from one path to another. Useful for reordering blocks or moving nested blocks.', inputSchema: { type: 'object', properties: { post_id: { type: 'number', description: 'Post ID to modify', }, from_path: { type: 'array', items: { type: 'number' }, description: 'Source path (block to move)', }, to_path: { type: 'array', items: { type: 'number' }, description: 'Destination path (where to move block)', }, }, required: ['post_id', 'from_path', 'to_path'], }, }, handler: async (args, context) => { validateRequired(args, ['post_id', 'from_path', 'to_path']); const id = validateId(args.post_id, 'Post'); if (!validatePath(args.from_path)) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'invalid_from_path', message: 'from_path must be non-empty array of non-negative integers', }, null, 2)), }], isError: true, }; } if (!validatePath(args.to_path)) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'invalid_to_path', message: 'to_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/move', { method: 'POST', body: JSON.stringify({ post_id: id, from_path: args.from_path, to_path: args.to_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, from_path: args.from_path, to_path: args.to_path, message: 'Block moved successfully', }, null, 2)), }], }; }, category: ToolCategory.CONTENT, });
- src/tools/gutenberg/helpers.ts:36-54 (helper)validatePath helper function used to validate from_path and to_path arrays in the handler./** * Validate path array * * Ensures path is a valid array of non-negative integers. * * @param path Path array to validate * @returns True if valid, false otherwise */ 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); }