Skip to main content
Glama

update_page_from_file

Update a WordPress page with Elementor data from specified files, returning a boolean to confirm success. Requires page ID and Elementor file path for operation.

Instructions

Updates an existing page in WordPress with Elementor data from a file, it will return a boolean value to indicate if the update was successful.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentFilePathNoThe absolute path to the file to update the WordPress content from, optional.
elementorFilePathYesThe absolute path to the file to update the Elementor data from.
pageIdYesThe ID of the page to update.
statusNoThe status for the page (e.g., 'publish', 'draft').
titleNoThe title for the page.

Implementation Reference

  • Handler function for the 'update_page_from_file' tool. Reads Elementor data from the specified file path, optionally reads content from another file path, constructs the update payload, calls the updatePage helper, and returns a success response.
    async (input) => { const pageData = JSON.parse( fs.readFileSync(input.elementorFilePath, "utf8") ); let contentData = null; if (input.contentFilePath) { contentData = fs.readFileSync(input.contentFilePath, "utf8"); } await updatePage(input.pageId, { title: input.title, status: input.status, content: contentData, elementor_data: JSON.stringify(pageData, null, 0), }); return { content: [{ type: "text", text: "true" }], }; }
  • Input schema for the 'update_page_from_file' tool defining parameters like pageId, title, status, contentFilePath, and elementorFilePath using Zod validation.
    { pageId: z .number() .int() .positive() .describe("The ID of the page to update."), title: z.string().optional().describe("The title for the page."), status: z .enum(["publish", "future", "draft", "pending", "private"]) .optional() .describe("The status for the page (e.g., 'publish', 'draft')."), contentFilePath: z .string() .optional() .describe( "The absolute path to the file to update the WordPress content from, optional." ), elementorFilePath: z .string() .describe("The absolute path to the file to update the Elementor data from."), },
  • src/index.js:182-224 (registration)
    Registration of the 'update_page_from_file' tool using server.tool(), including name, description, input schema, and handler function.
    server.tool( "update_page_from_file", "Updates an existing page in WordPress with Elementor data from a file, it will return a boolean value to indicate if the update was successful.", { pageId: z .number() .int() .positive() .describe("The ID of the page to update."), title: z.string().optional().describe("The title for the page."), status: z .enum(["publish", "future", "draft", "pending", "private"]) .optional() .describe("The status for the page (e.g., 'publish', 'draft')."), contentFilePath: z .string() .optional() .describe( "The absolute path to the file to update the WordPress content from, optional." ), elementorFilePath: z .string() .describe("The absolute path to the file to update the Elementor data from."), }, async (input) => { const pageData = JSON.parse( fs.readFileSync(input.elementorFilePath, "utf8") ); let contentData = null; if (input.contentFilePath) { contentData = fs.readFileSync(input.contentFilePath, "utf8"); } await updatePage(input.pageId, { title: input.title, status: input.status, content: contentData, elementor_data: JSON.stringify(pageData, null, 0), }); return { content: [{ type: "text", text: "true" }], }; } );
  • Helper function 'updatePage' called by the tool handler to perform the actual WordPress REST API update for the page, handling payload construction and validation.
    async function updatePage(pageId, pageData) { const client = getApiClient(); const payload = {}; if (pageData.title) payload.title = pageData.title; if (pageData.status) payload.status = pageData.status; if (pageData.content) payload.content = pageData.content; // Use !== undefined to allow setting empty content if (pageData.elementor_data) { if (typeof pageData.elementor_data !== 'string') { throw new Error('elementor_data must be provided as a JSON string.'); } try { JSON.parse(pageData.elementor_data); // Basic validation } catch (e) { throw new Error('elementor_data is not valid JSON string.'); } payload.meta = { _elementor_data: pageData.elementor_data }; } if (Object.keys(payload).length === 0) { throw new Error("No update data provided."); } // WP uses POST for updates via ID route const response = await client.post(`/wp-json/wp/v2/pages/${pageId}`, payload); return response.data; }

Other Tools

Related Tools

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/aguaitech/Elementor-MCP'

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